Updated chat_listener and listener_manager

This commit is contained in:
2025-11-17 15:08:29 +01:00
parent 4013d3d23d
commit 5dc73bd06a
2 changed files with 15 additions and 3 deletions

View File

@@ -1,11 +1,16 @@
from twitchio.ext import commands
class TwitchBot(commands.Bot):
def __init__(self, access_token: str, channel_name: str):
def __init__(self, access_token: str, client_id: str, client_secret: str, bot_id: str, channel_name: str):
super().__init__(
token=access_token,
prefix='!', # A prefix is required but won't be used for reading chat
initial_channels=[channel_name]
initial_channels=[channel_name],
# These are now required by twitchio
client_id=client_id,
client_secret=client_secret,
# The 'bot_id' is the Twitch ID of the user account the bot is running as
id=bot_id
)
self.channel_name = channel_name

View File

@@ -3,6 +3,7 @@ from typing import Dict
from chat_listener import TwitchBot
import security # To decrypt tokens
from config import settings # To get client_id and client_secret
class ListenerManager:
def __init__(self):
@@ -23,7 +24,13 @@ class ListenerManager:
tokens = security.decrypt_tokens(user.encrypted_tokens)
access_token = tokens['access_token']
bot = TwitchBot(access_token=access_token, channel_name=user.username)
bot = TwitchBot(
access_token=access_token,
channel_name=user.username,
client_id=settings.TWITCH_CLIENT_ID,
client_secret=settings.TWITCH_CLIENT_SECRET,
bot_id=user.platform_user_id
)
task = asyncio.create_task(bot.start())
self.active_listeners[user.id] = task