Compare commits

..

5 Commits

Author SHA1 Message Date
c4bcfe3b2b Clean 2025-03-18 20:29:42 +01:00
05bd4bde27 Update ai 2025-03-18 20:29:22 +01:00
46241f0b2e Fix 2025-03-18 20:22:21 +01:00
c36622babf Add chatbot_in_chats 2025-03-18 20:22:00 +01:00
c7c273cdac Update 2025-03-18 20:14:12 +01:00
5 changed files with 35 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ class TwitchConfig(BaseModel):
class NotificationsConfig(BaseModel):
start_stream: str
change_category: str | None = None
redemption_reward: str | None = None
class GamesListConfig(BaseModel):
channel_id: int
@@ -29,3 +30,5 @@ class StreamerConfig(BaseModel):
twitch: TwitchConfig
notifications: NotificationsConfig
integrations: IntegrationsConfig
chatbot_in_chats: list[int] | None = None

View File

@@ -304,18 +304,7 @@ class MessagesProc:
)
@classmethod
async def _on_custom_reward(cls, twitch: Twitch, event: MessageEvent):
pass
# if event.channel_points_custom_reward_id:
# await twitch.send_chat_message(
# event.broadcaster_user_id,
# config.TWITCH_ADMIN_USER_ID,
# "Спасибо за поддержку!",
# reply_parent_message_id=event.message_id
# )
@classmethod
async def on_message(cls, event: MessageEvent):
async def on_message(cls, received_as: str, event: MessageEvent):
if event.chatter_user_name in cls.FULL_IGNORED_USER_LOGINS:
return
@@ -323,10 +312,9 @@ class MessagesProc:
await cls._update_history(event)
twitch = await authorize(event.broadcaster_user_login)
twitch = await authorize(received_as)
await cls._goida(twitch, event)
await cls._lasqexx(twitch, event)
await cls._ask_ai(twitch, event)
await cls._kurbezz(twitch, event)
await cls._on_custom_reward(twitch, event)

View File

@@ -4,6 +4,7 @@ from pydantic import BaseModel
from twitchAPI.object.eventsub import ChannelPointsCustomRewardRedemptionAddEvent
from repositories.streamers import StreamerConfigRepository
from .twitch.authorize import authorize
@@ -33,8 +34,19 @@ async def on_redemption_reward_add(reward: RewardRedemption):
twitch = await authorize(reward.broadcaster_user_login)
streamer = await StreamerConfigRepository.get_by_twitch_id(int(reward.broadcaster_user_id))
if streamer.notifications.redemption_reward is None:
return
message = streamer.notifications.redemption_reward.format(
user=reward.user_name,
reward_title=reward.reward_title,
reward_promt=f" ({reward.reward_prompt})" if reward.reward_prompt else ""
)
await twitch.send_chat_message(
reward.broadcaster_user_id,
reward.broadcaster_user_id,
f"🎉 {reward.user_name} just redeemed {reward.reward_title}! 🎉"
message
)

View File

@@ -81,8 +81,11 @@ async def check_streams_states():
"stream_notifications.on_message",
retry_on_error=True
)
async def on_message(event: MessageEvent):
await MessagesProc.on_message(event)
async def on_message(
received_as: str,
event: MessageEvent
):
await MessagesProc.on_message(received_as, event)
@broker.task(

View File

@@ -7,7 +7,6 @@ from twitchAPI.twitch import Twitch
from twitchAPI.object.eventsub import StreamOnlineEvent, ChannelUpdateEvent, ChannelChatMessageEvent, ChannelPointsCustomRewardRedemptionAddEvent
from twitchAPI.oauth import validate_token
from core.config import config
from repositories.streamers import StreamerConfigRepository, StreamerConfig
from modules.stream_notifications.tasks import on_stream_state_change, on_stream_state_change_with_check, on_message, on_redemption_reward_add_task
from modules.stream_notifications.state import UpdateEvent, EventType
@@ -55,6 +54,7 @@ class TwitchService:
async def on_message(self, event: ChannelChatMessageEvent):
await on_message.kiq(
self.streamer.twitch.name,
MessageEvent.from_twitch_event(event)
)
@@ -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")