Skip to content

Commit

Permalink
fix(discord): don't try to send messages when there is no asyncio loop (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
TrueBrain committed Apr 9, 2024
1 parent fc5c9f5 commit 5c8d9f6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dibridge/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 5c8d9f6

Please sign in to comment.