From e2f02eeed8b2c5b78c4c326ffdfa6b8cc01568b5 Mon Sep 17 00:00:00 2001 From: Specoolazius Date: Thu, 31 Mar 2022 15:34:05 +0200 Subject: [PATCH] better server presence task --- bot/botclient.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bot/botclient.py b/bot/botclient.py index 9685f6a..06fafe6 100644 --- a/bot/botclient.py +++ b/bot/botclient.py @@ -211,6 +211,8 @@ class Presence(object): def __init__(self, bot: BotClient): self.bot = bot self.mc_server = self.bot.mc_server + self.retry_in_seconds = self.bot.config.retry_in_seconds + self.__server_online_presence.start() """ @@ -221,23 +223,29 @@ class Presence(object): @tasks.loop() async def __server_online_presence(self): + _time = time.time() + try: self.bot.logger.debug('Getting server information') status = await self.mc_server.async_status() + self.bot.is_server_starting = False + await self.bot.change_presence( activity=discord.Game( - name=f'with {status.players.online} players' - ) + name=f'with {status.players.online} player{"s" if status.players.online != 1 else ""}', + ), + status=discord.Status.online ) - await asyncio.sleep(40) + await asyncio.sleep(40) await self.bot.change_presence( activity=discord.Activity( type=discord.ActivityType.watching, - name=self.bot.config.server_address + name=self.bot.config.server_address, ) ) + await asyncio.sleep(20) except asyncio.TimeoutError: