From e9fc21e423cf3baacc5e102dc3bae41238824d04 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Jan 2026 21:09:39 +0000 Subject: [PATCH] Fix bot not responding to mentions - event loop wasn't running The bot was detecting mentions correctly but not responding because the async event loop was never started. Changes: - Created separate _run_event_loop() method to run loop.run_forever() - Start event loop in its own daemon thread before IRC bot - IRC bot thread no longer sets event loop (handled by loop thread) - Now asyncio.run_coroutine_threadsafe() can properly execute async tasks This fixes the issue where mentions were detected but handle_mention() was never executed because there was no running event loop to process the coroutine. --- chatbot.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chatbot.py b/chatbot.py index 5df2194..84cc33a 100644 --- a/chatbot.py +++ b/chatbot.py @@ -216,6 +216,10 @@ class EugenBot(irc.bot.SingleServerIRCBot): # Create event loop for async operations self.loop = asyncio.new_event_loop() + # Start event loop in separate thread + loop_thread = threading.Thread(target=self._run_event_loop, daemon=True) + loop_thread.start() + # Start bot in separate thread bot_thread = threading.Thread(target=self._run_bot, daemon=True) bot_thread.start() @@ -225,9 +229,15 @@ class EugenBot(irc.bot.SingleServerIRCBot): self.logger.info("Starting dashboard...") self.dashboard.run() + def _run_event_loop(self): + """Run the async event loop (called in thread)""" + asyncio.set_event_loop(self.loop) + self.logger.debug("Starting event loop...") + self.loop.run_forever() + self.logger.debug("Event loop stopped") + def _run_bot(self): """Run the IRC bot (called in thread)""" - asyncio.set_event_loop(self.loop) try: self.logger.info("Starting IRC bot...") super().start()