From 5c8d9f69213de5b796a4bdd27aabded9882ffb17 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Tue, 9 Apr 2024 19:46:10 +0200 Subject: [PATCH] fix(discord): don't try to send messages when there is no asyncio loop (#230) When close() is called, "self.loop" is made a sentinel value. Still using this causes long backtraces for every message. close() can be called when the websocket is dropped with an unexpected error. --- dibridge/discord.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dibridge/discord.py b/dibridge/discord.py index db5bcde..1a0b94d 100644 --- a/dibridge/discord.py +++ b/dibridge/discord.py @@ -184,12 +184,24 @@ async def _stop(self): # Thread safe wrapper around functions def send_message(self, irc_username, message): + if self.loop == discord.utils.MISSING: + log.warning(f"Can't relay message from {irc_username} to Discord: connection is down.") + return + asyncio.run_coroutine_threadsafe(self._send_message(irc_username, message), self.loop) def send_message_self(self, message): + if self.loop == discord.utils.MISSING: + log.warning("Can't relay status message to Discord: connection is down.") + return + asyncio.run_coroutine_threadsafe(self._send_message_self(message), self.loop) def update_presence(self, status): + if self.loop == discord.utils.MISSING: + log.warning(f"Can't update presence to {status}: connection is down.") + return + asyncio.run_coroutine_threadsafe(self._update_presence(status), self.loop)