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.
This commit is contained in:
Claude 2026-01-02 21:09:39 +00:00
parent a52be47121
commit e9fc21e423
No known key found for this signature in database

View file

@ -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()