From c36622babf70ecd0827fa901266f4d77e33aae9c Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 18 Mar 2025 20:22:00 +0100 Subject: [PATCH] Add chatbot_in_chats --- src/domain/streamers.py | 2 ++ .../stream_notifications/twitch/webhook.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/domain/streamers.py b/src/domain/streamers.py index 91200aa..990a826 100644 --- a/src/domain/streamers.py +++ b/src/domain/streamers.py @@ -30,3 +30,5 @@ class StreamerConfig(BaseModel): twitch: TwitchConfig notifications: NotificationsConfig integrations: IntegrationsConfig + + chatbot_in_chats: list[int] | None = None diff --git a/src/modules/stream_notifications/twitch/webhook.py b/src/modules/stream_notifications/twitch/webhook.py index 6e23e17..406bad2 100644 --- a/src/modules/stream_notifications/twitch/webhook.py +++ b/src/modules/stream_notifications/twitch/webhook.py @@ -100,17 +100,20 @@ class TwitchService: await eventsub.listen_channel_update_v2(str(streamer.twitch.id), self.on_channel_update) case "listen_stream_online": await eventsub.listen_stream_online(str(streamer.twitch.id), self.on_stream_online) - case "listen_channel_chat_message": - await eventsub.listen_channel_chat_message( - str(streamer.twitch.id), - str(config.TWITCH_ADMIN_USER_ID), - self.on_message - ) case "listen_channel_points_custom_reward_redemption_add": await eventsub.listen_channel_points_custom_reward_redemption_add( str(streamer.twitch.id), self.on_channel_points_custom_reward_redemption_add ) + case "listen_channel_chat_message": + chatbot_in_chats = streamer.chatbot_in_chats or [] + + for chat_id in chatbot_in_chats: + await eventsub.listen_channel_chat_message( + str(chat_id), + str(streamer.twitch.id), + self.on_message + ) case _: raise ValueError("Unknown method") @@ -127,8 +130,8 @@ class TwitchService: await gather( self.subscribe_with_retry("listen_channel_update_v2", eventsub, streamer), self.subscribe_with_retry("listen_stream_online", eventsub, streamer), - # self.subscribe_with_retry("listen_channel_chat_message", eventsub, streamer), - self.subscribe_with_retry("listen_channel_points_custom_reward_redemption_add", eventsub, streamer) + self.subscribe_with_retry("listen_channel_points_custom_reward_redemption_add", eventsub, streamer), + self.subscribe_with_retry("listen_channel_chat_message", eventsub, streamer), ) logger.info(f"Subscribe to events for {streamer.twitch.name} done")