This commit is contained in:
2025-11-18 01:43:43 +01:00
parent 53c1966494
commit 1c93a09c74

View File

@@ -26,22 +26,30 @@ class TwitchBot(twitchio.Client):
async def event_ready(self): async def event_ready(self):
"""Called once when the bot goes online.""" """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. async def event_message(self, message): # Mandate: Type hint removed to prevent import errors.
"""Runs every time a message is sent in chat.""" """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. # Ignore messages sent by the bot itself to prevent loops.
if message.echo: if message.echo:
return return
# Prepare the message data to be sent to the frontend # Prepare the message data to be sent to the frontend
chat_data = { chat_data = {
"author": message.author.name, "author": message.author.name if message.author else "Twitch",
"text": message.content, "text": message.content,
"platform": "twitch" "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 # Broadcast the message to the specific user's overlay
# We need the user's ID to know which WebSocket connection to send to. # We need the user's ID to know which WebSocket connection to send to.
user_id = self.db_user_id user_id = self.db_user_id
await self.websocket_manager.broadcast_to_user(user_id, chat_data) 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}.")