From d82784ce56c4d147b5b76ddc57cd0c26cbf49f65 Mon Sep 17 00:00:00 2001 From: Specoolazius Date: Thu, 31 Mar 2022 15:31:44 +0200 Subject: [PATCH] presence stopping on not being able to connect to server --- bot/botclient.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bot/botclient.py b/bot/botclient.py index bd95a37..b82ad54 100644 --- a/bot/botclient.py +++ b/bot/botclient.py @@ -229,9 +229,24 @@ class Presence(object): ) await asyncio.sleep(20) - except Exception as e: - # ToDo: server offline exception - print('server offline because:', str(e)) + except asyncio.TimeoutError: + if self.bot.is_server_starting and self.bot.last_start + self.bot.config.server_start_timout < time.time(): + self.bot.is_server_starting = False + + # ToDo: better presence + await self.bot.change_presence( + activity=discord.Activity( + type=discord.ActivityType.watching, + name=f'{self.bot.config.server_address} starting' if self.bot.is_server_starting else + f'offline: [self.server.address]', + ), + status=discord.Status.idle + ) + + # abs -> simple fix if for any reason the sleep_time is negative + sleep_time = abs(_time - time.time() + self.retry_in_seconds) + self.bot.logger.debug(f'Server offline, retrying in {round(sleep_time, 4)} seconds') + await asyncio.sleep(sleep_time) @__server_online_presence.before_loop async def __before_status(self) -> None: