From 9e57e766865c4b925a9bfbc9563ba1602b569f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dml?= <88406955+Twilights-0@users.noreply.github.com> Date: Tue, 18 Aug 2026 18:34:05 +0200 Subject: [PATCH 1/5] Implement DiscordGateway503Filter for logging Added a logging filter to handle Discord Gateway 503 errors. --- src/fablabot/main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/fablabot/main.py b/src/fablabot/main.py index 8ebd352..b9df172 100644 --- a/src/fablabot/main.py +++ b/src/fablabot/main.py @@ -31,6 +31,29 @@ with open(DISCORD_TOKEN_FILE) as f: DISCORD_TOKEN = f.read().strip() +class DiscordGateway503Filter(logging.Filter): + """clean warning for gateway 503 error""" + + def filter(self, record: logging.LogRecord) -> bool: + if record.name != "discord.client" or not record.exc_info: + return True + + exception = record.exc_info[1] + + if ( + exception.__class__.__name__ == "WSServerHandshakeError" + and getattr(exception, "status", None) == 503 + ): + retry_message = record.getMessage() + + logger.warning( + "Discord Gateway indisponible (503). %s", + retry_message, + ) + + return False + + return True class Fablabot(commands.Bot): """Discord bot implementation for the DeVinci Fablab server.""" @@ -99,6 +122,9 @@ async def on_command_error(self, ctx: commands.Context[Any], exception: Exceptio def main() -> None: """Run the bot using the token from the environment.""" + discord_logger = logging.getLogger("discord.client") + discord_logger.addFilter(DiscordGateway503Filter()) + logger.info("Starting FablaBot.") bot = Fablabot() logger.info("Running bot.") From 91bdf4d3a015d1d5925a9342f6152d0080fc7693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dml?= <88406955+Twilights-0@users.noreply.github.com> Date: Tue, 18 Aug 2026 18:41:03 +0200 Subject: [PATCH 2/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/fablabot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fablabot/main.py b/src/fablabot/main.py index b9df172..d4faf21 100644 --- a/src/fablabot/main.py +++ b/src/fablabot/main.py @@ -124,7 +124,7 @@ def main() -> None: """Run the bot using the token from the environment.""" discord_logger = logging.getLogger("discord.client") discord_logger.addFilter(DiscordGateway503Filter()) - + logger.info("Starting FablaBot.") bot = Fablabot() logger.info("Running bot.") From a7117484b72febd73abb41e714c01762cabb7ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dml?= <88406955+Twilights-0@users.noreply.github.com> Date: Tue, 18 Aug 2026 18:41:33 +0200 Subject: [PATCH 3/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/fablabot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fablabot/main.py b/src/fablabot/main.py index d4faf21..079bffc 100644 --- a/src/fablabot/main.py +++ b/src/fablabot/main.py @@ -32,7 +32,7 @@ DISCORD_TOKEN = f.read().strip() class DiscordGateway503Filter(logging.Filter): - """clean warning for gateway 503 error""" + """Filter Discord gateway 503 warnings into a cleaner message.""" def filter(self, record: logging.LogRecord) -> bool: if record.name != "discord.client" or not record.exc_info: From 06e8f1f159b9bce9fc82439e2012549c352e9d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dml?= <88406955+Twilights-0@users.noreply.github.com> Date: Tue, 18 Aug 2026 18:43:31 +0200 Subject: [PATCH 4/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/fablabot/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fablabot/main.py b/src/fablabot/main.py index 079bffc..85ad482 100644 --- a/src/fablabot/main.py +++ b/src/fablabot/main.py @@ -40,8 +40,10 @@ def filter(self, record: logging.LogRecord) -> bool: exception = record.exc_info[1] + from aiohttp import WSServerHandshakeError + if ( - exception.__class__.__name__ == "WSServerHandshakeError" + isinstance(exception, WSServerHandshakeError) and getattr(exception, "status", None) == 503 ): retry_message = record.getMessage() From 1a5901add069ebc1a77c1417cefd9f6ce6252b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dml?= <88406955+Twilights-0@users.noreply.github.com> Date: Tue, 18 Aug 2026 18:43:40 +0200 Subject: [PATCH 5/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/fablabot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fablabot/main.py b/src/fablabot/main.py index 85ad482..e091b16 100644 --- a/src/fablabot/main.py +++ b/src/fablabot/main.py @@ -35,7 +35,7 @@ class DiscordGateway503Filter(logging.Filter): """Filter Discord gateway 503 warnings into a cleaner message.""" def filter(self, record: logging.LogRecord) -> bool: - if record.name != "discord.client" or not record.exc_info: + if not record.exc_info: return True exception = record.exc_info[1]