update update

This commit is contained in:
gpatruno
2026-04-28 21:06:26 +02:00
parent 7b2135bfed
commit b4254c9e06
28 changed files with 2032 additions and 547 deletions
+54 -11
View File
@@ -16,6 +16,8 @@ from fonction.first_class import (
from twitch_bot import chat_state
from twitch_bot.interaction_chat import InteractionChatProcessor
from twitch_bot import twitch_helix
from twitch_bot.subtitle_rules import SubtitleRulesProcessor
def _resolve_user_index(pseudo: str) -> int:
@@ -84,7 +86,7 @@ class BotController:
'active_flux': len([f for f in self.flux_list if f['active']])
}
def add_flux(self, channel_name, record_audio=True):
def add_flux(self, channel_name, record_audio=True, send_messages=True, enable_ia=True):
flux_id = len(self.flux_list) + 1
# Créer l'objet flux pour l'API (sans les instances de bots)
@@ -93,6 +95,8 @@ class BotController:
'name': channel_name,
'twitchname': channel_name,
'record_audio': record_audio,
'send_messages': bool(send_messages),
'enable_ia': bool(enable_ia),
'active': True,
'created_at': datetime.now().isoformat(),
'status': 'starting'
@@ -137,13 +141,42 @@ class BotController:
return {}
msg_bot_for_interaction = messageTwitch("config/user.json", channel_name)
def create_clip_as(pseudo: str, broadcaster_login: str, has_delay: bool = False):
client_id = twitch_helix.twitch_client_id("config/config.json")
bearer = twitch_helix.bearer_token_for_pseudo(pseudo, "config/user.json")
broadcaster_id = twitch_helix.get_user_id_by_login(
client_id=client_id,
bearer=bearer,
login=broadcaster_login,
)
return twitch_helix.create_clip(
client_id=client_id,
bearer=bearer,
broadcaster_id=broadcaster_id,
has_delay=bool(has_delay),
)
interaction = InteractionChatProcessor(
channel_name=channel_name,
get_registered_accounts=get_registered_accounts,
get_account_policies=get_account_policies,
send_message_as=lambda pseudo, text: msg_bot_for_interaction.send_message_user(
_resolve_user_index(pseudo), text
send_message_as=lambda pseudo, text: (
msg_bot_for_interaction.send_message_user(_resolve_user_index(pseudo), text)
if bool(flux_data.get("send_messages", True))
else None
),
create_clip_as=create_clip_as,
)
subtitle_rules = SubtitleRulesProcessor(
channel_name=channel_name,
send_message_as=lambda pseudo, text: (
msg_bot_for_interaction.send_message_user(_resolve_user_index(pseudo), text)
if bool(flux_data.get("send_messages", True))
else None
),
create_clip_as=create_clip_as,
resolve_default_account=lambda: (get_registered_accounts() or [""])[0],
)
self.bots[flux_id] = {
@@ -153,6 +186,7 @@ class BotController:
'ia_bot': None,
'message_bot': None,
'interaction': interaction,
'subtitle_rules': subtitle_rules,
}
chat_bot.start_background()
@@ -165,19 +199,28 @@ class BotController:
threading.Thread(target=record_bot.main, daemon=True).start()
# Démarrer le bot de sous-titres
subtitle_bot = Subtitle_translation("config/config.json")
subtitle_storage_key = f"subtitle_data__{channel_name.lower()}"
subtitle_bot = Subtitle_translation(
"config/config.json",
storage_key=subtitle_storage_key,
on_new_subtitle=lambda ts, text: subtitle_rules.on_new_subtitle(ts_key=ts, subtitle_text=text),
segment_seconds=30,
max_backlog_files=3,
)
self.bots[flux_id]['subtitle_bot'] = subtitle_bot
subtitle_bot.start_main_loop()
# Démarrer le générateur IA
ia_bot = IA_generator("config/config.json")
self.bots[flux_id]['ia_bot'] = ia_bot
ia_bot.start_main_loop()
if bool(flux_data.get("enable_ia", True)):
ia_bot = IA_generator("config/config.json")
self.bots[flux_id]['ia_bot'] = ia_bot
ia_bot.start_main_loop()
# Démarrer le contrôleur de messages
message_bot = messageTwitch("config/user.json", channel_name)
self.bots[flux_id]['message_bot'] = message_bot
message_bot.start_loop_respond()
# Démarrer le contrôleur de messages (uniquement si autorisé sur ce flux)
if bool(flux_data.get("send_messages", True)) and bool(flux_data.get("enable_ia", True)):
message_bot = messageTwitch("config/user.json", channel_name)
self.bots[flux_id]['message_bot'] = message_bot
message_bot.start_loop_respond()
# Mettre à jour le statut
flux_data['status'] = 'active'