From 9cb4186bb897bd21693029a2ab0329b0da432472 Mon Sep 17 00:00:00 2001 From: Mow910 Date: Wed, 25 Mar 2026 22:00:29 +0100 Subject: [PATCH] Add stream uptime formatting to Twitch moderation and enhance template layout - Introduced a new helper function `_format_stream_uptime` to calculate and format the stream uptime based on the start time. - Updated the Twitch moderation route to include the formatted stream uptime in the rendered template. - Enhanced the Twitch moderation template layout for better responsiveness and visual clarity, including adjustments to the live status display and overall structure. --- webapp/templates/twitch-moderation.html | 122 +++++++++++++----------- webapp/twitch_moderation.py | 30 +++++- 2 files changed, 93 insertions(+), 59 deletions(-) diff --git a/webapp/templates/twitch-moderation.html b/webapp/templates/twitch-moderation.html index 1e72a29..277e2dc 100644 --- a/webapp/templates/twitch-moderation.html +++ b/webapp/templates/twitch-moderation.html @@ -75,62 +75,60 @@ transition: opacity 0.2s; } #editModal.hidden, #addCommandModal.hidden { display: none; } + @keyframes tmOfflineGlow { + 0%, 100% { opacity: 0.55; } + 50% { opacity: 1; } + } + .tm-offline-icon { animation: tmOfflineGlow 3s ease-in-out infinite; }
-
-

Modération Twitch

-

Commandes et logs de modération pour {{ twitch_channel }}

-
- - -
-
-
-
-
- -
-
-

Live

-

{{ 'En ligne' if is_live else 'Hors ligne' }}

-
-
- {% if is_live %} -
-
{{ viewer_count }}
-
viewers
-
- {% endif %} -
+
+
+

Modération Twitch

+

Commandes et logs de modération pour {{ twitch_channel }}

-
-
-
- -
-

Filtre de liens

-

{{ 'Actif' if link_filter_enabled else 'Inactif' }}

-
+
+ +
+
+ {% if is_live %} + + {% else %} + + {% endif %}
- Configurer +
+

{{ 'En direct' if is_live else 'Hors ligne' }}

+ {% if is_live %} +

{{ stream_title or 'Sans titre' }}

+ {% else %} +

Repos — à bientôt sur Twitch

+ {% endif %} +
+ Chaîne
-
-
-
-
-
- -
-
-

Mots interdits

-

{{ banned_words|length }} mot{{ 's' if banned_words|length > 1 else '' }}

-
+
+ +
+

Filtre liens

+

{{ 'Actif' if link_filter_enabled else 'Inactif' }}

+
+ Réglages +
+
+
+ +
+
+

Mots interdits

+

{{ banned_words|length }} actif{{ 's' if banned_words|length != 1 else '' }}

+
+ Liste
@@ -146,27 +144,37 @@
-
+
{% if is_live %} - + + + EN DIRECT + {% else %} - + + + Pas en direct + {% endif %} - {{ 'EN DIRECT' if is_live else 'HORS LIGNE' }} - • {{ viewer_count }} viewers + • {{ viewer_count }} viewers
Ouvrir
-
-
-
{{ 'Live en cours' if is_live else 'En attente du prochain live' }}
-
Lecture Twitch intégrée
+
+
+ {% if is_live %} +

{{ stream_title or 'Sans titre' }}

+

{{ game_name or 'Catégorie non renseignée' }}{% if stream_uptime %} · {{ stream_uptime }}{% endif %}

+ {% else %} +

En attente du prochain live

+

Lecteur intégré — son activé automatiquement quand la chaîne est en ligne

+ {% endif %}
@@ -426,7 +434,7 @@
-
+

Mots interdits ({{ banned_words|length }})

diff --git a/webapp/twitch_moderation.py b/webapp/twitch_moderation.py index a738882..02f446f 100644 --- a/webapp/twitch_moderation.py +++ b/webapp/twitch_moderation.py @@ -5,7 +5,31 @@ from database import db from database.models import Commande, TwitchModerationLog, TwitchLinkFilter, TwitchBannedWord, ModShoutboxMessage from flask_login import current_user from database.helpers import ConfigurationHelper -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone + + +def _format_stream_uptime(started_at_iso): + """Durée depuis le début du live (texte court pour le panneau).""" + if not started_at_iso: + return None + try: + s = str(started_at_iso).replace("Z", "+00:00") + started = datetime.fromisoformat(s) + if started.tzinfo is None: + started = started.replace(tzinfo=timezone.utc) + now = datetime.now(timezone.utc) + sec = int((now - started).total_seconds()) + if sec < 0: + return None + h, sec = divmod(sec, 3600) + m, sec = divmod(sec, 60) + if h > 0: + return f"{h}h {m}min" + if m > 0: + return f"{m} min" + return "< 1 min" + except (ValueError, TypeError): + return None import asyncio MODERATION_COMMANDS = [ @@ -139,7 +163,8 @@ def twitch_moderation(): stream_title = bot_status.get("twitch_stream_title", "") game_name = bot_status.get("twitch_game_name", "") started_at = bot_status.get("twitch_started_at") - + stream_uptime = _format_stream_uptime(started_at) if is_live else None + return render_template( "twitch-moderation.html", commands=MODERATION_COMMANDS, @@ -155,6 +180,7 @@ def twitch_moderation(): stream_title=stream_title, game_name=game_name, started_at=started_at, + stream_uptime=stream_uptime, ) @webapp.route("/twitch-moderation/logs/clear")