Ajout de la gestion des informations de stream dans le bot Twitch. Implémentation de la fonction de remplacement des variables de commande pour inclure des informations dynamiques telles que le titre du stream, le nom du jeu, le nombre de viewers et l'uptime. Mise à jour de l'interface utilisateur pour afficher ces informations en temps réel dans la modération Twitch.

This commit is contained in:
2026-03-06 13:48:43 +01:00
parent 876eb1a080
commit 10dd78f630
5 changed files with 273 additions and 49 deletions
+36 -2
View File
@@ -104,11 +104,45 @@ async def _handleCustomCommand(msg: ChatMessage):
if commande:
permission = commande.twitch_permission or 'viewer'
if not _user_has_twitch_permission(msg, permission):
return # Pas de réponse = l'utilisateur n'a pas la permission
response = commande.response.replace('{user}', msg.user.name)
return
response = _replace_command_variables(commande.response, msg)
await msg.reply(response)
def _replace_command_variables(text: str, msg: ChatMessage) -> str:
"""Remplace les variables de template dans la réponse d'une commande."""
from datetime import datetime
result = text
result = result.replace('{user}', msg.user.name)
result = result.replace('{username}', msg.user.name)
result = result.replace('{channel}', msg.room.name)
bot_status = webapp.config.get("BOT_STATUS", {})
result = result.replace('{title}', bot_status.get("twitch_stream_title", ""))
result = result.replace('{game}', bot_status.get("twitch_game_name", ""))
result = result.replace('{viewers}', str(bot_status.get("twitch_viewer_count", 0)))
uptime_str = "hors ligne"
started_at_str = bot_status.get("twitch_started_at")
if started_at_str and bot_status.get("twitch_is_live", False):
try:
started_at = datetime.fromisoformat(started_at_str)
delta = datetime.now(started_at.tzinfo) - started_at
total_seconds = int(delta.total_seconds())
hours, remainder = divmod(max(0, total_seconds), 3600)
minutes, _ = divmod(remainder, 60)
if hours > 0:
uptime_str = f"{hours}h {minutes:02d}min"
else:
uptime_str = f"{minutes}min"
except (ValueError, TypeError):
pass
result = result.replace('{uptime}', uptime_str)
return result
async def _helloCommand(msg: ChatMessage):
await msg.reply(f'Bonjour {msg.user.name}')
+6
View File
@@ -67,9 +67,15 @@ async def checkOnlineStreamer(twitch: Twitch) :
if main_stream:
webapp.config["BOT_STATUS"]["twitch_is_live"] = True
webapp.config["BOT_STATUS"]["twitch_viewer_count"] = getattr(main_stream, 'viewer_count', 0)
webapp.config["BOT_STATUS"]["twitch_stream_title"] = getattr(main_stream, 'title', '') or ''
webapp.config["BOT_STATUS"]["twitch_game_name"] = getattr(main_stream, 'game_name', '') or ''
webapp.config["BOT_STATUS"]["twitch_started_at"] = main_stream.started_at.isoformat() if getattr(main_stream, 'started_at', None) else None
else:
webapp.config["BOT_STATUS"]["twitch_is_live"] = False
webapp.config["BOT_STATUS"]["twitch_viewer_count"] = 0
webapp.config["BOT_STATUS"]["twitch_stream_title"] = ""
webapp.config["BOT_STATUS"]["twitch_game_name"] = ""
webapp.config["BOT_STATUS"]["twitch_started_at"] = None
# Premier check : synchronisation sans notification
if _live_alert_first_check: