diff --git a/chat_listener.py b/chat_listener.py index 78f524e..57896f2 100644 --- a/chat_listener.py +++ b/chat_listener.py @@ -26,22 +26,30 @@ class TwitchBot(twitchio.Client): async def event_ready(self): """Called once when the bot goes online.""" - print(f"Listener ready for #{self.channel_name}") + # Diagnostic Logging: Confirming the bot is ready and joined the channel. + print(f"DIAGNOSTIC: Listener connected and ready for user_id: {self.db_user_id}, channel: #{self.channel_name}") async def event_message(self, message): # Mandate: Type hint removed to prevent import errors. """Runs every time a message is sent in chat.""" + # Diagnostic Logging: Checkpoint 1 - A raw message is received from Twitch. + print(f"DIAGNOSTIC: Message received for user {self.db_user_id} in channel {self.channel_name}: '{message.content}'") + # Ignore messages sent by the bot itself to prevent loops. if message.echo: return # Prepare the message data to be sent to the frontend chat_data = { - "author": message.author.name, + "author": message.author.name if message.author else "Twitch", "text": message.content, "platform": "twitch" } + # Diagnostic Logging: Checkpoint 2 - The message data has been prepared for broadcasting. + print(f"DIAGNOSTIC: Prepared chat_data for user {self.db_user_id}: {chat_data}") # Broadcast the message to the specific user's overlay # We need the user's ID to know which WebSocket connection to send to. user_id = self.db_user_id - await self.websocket_manager.broadcast_to_user(user_id, chat_data) \ No newline at end of file + await self.websocket_manager.broadcast_to_user(user_id, chat_data) + # Diagnostic Logging: Checkpoint 3 - The broadcast function was called. + print(f"DIAGNOSTIC: Broadcast called for user {self.db_user_id}.") \ No newline at end of file