Enhance TwitchBot connection handling by implementing a reconnection strategy that restarts the session after 90 seconds of disconnection. Update logging messages for clarity. Modify Twitch moderation template layout for improved responsiveness and user experience, adjusting grid classes and simplifying live status display.
This commit is contained in:
+16
-1
@@ -177,11 +177,26 @@ class TwitchBot():
|
||||
self.twitch = await Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret'))
|
||||
await self.twitch.set_user_authentication(helper.getValue('twitch_access_token'), USER_SCOPE, helper.getValue('twitch_refresh_token'))
|
||||
self.chat = await Chat(self.twitch)
|
||||
# Laisser des tentatives de reconnexion internes plus longues avant reboot complet du client
|
||||
self.chat.reconnect_delay_steps = [0, 1, 2, 4, 8, 16, 32, 64, 128, 128, 128]
|
||||
self.chat.register_event(ChatEvent.READY, _onReady)
|
||||
self.chat.register_event(ChatEvent.MESSAGE, _onMessage)
|
||||
self.chat.register_command('hello', _helloCommand)
|
||||
self._register_moderation_commands()
|
||||
self.chat.start()
|
||||
disconnected_since = None
|
||||
while True:
|
||||
connected = self.chat.is_connected()
|
||||
if connected:
|
||||
disconnected_since = None
|
||||
else:
|
||||
if disconnected_since is None:
|
||||
disconnected_since = time.time()
|
||||
# Si la lib n'arrive pas à se reconnecter en interne pendant un moment, on relance la session complète.
|
||||
elif time.time() - disconnected_since >= 90:
|
||||
logging.warning("Chat Twitch déconnecté depuis plus de 90s, redémarrage de la session")
|
||||
break
|
||||
await asyncio.sleep(2)
|
||||
except Exception as e:
|
||||
logging.error(f'Échec de l\'authentification Twitch : {e}')
|
||||
finally:
|
||||
@@ -318,7 +333,7 @@ class TwitchBot():
|
||||
time.sleep(60)
|
||||
continue
|
||||
asyncio.run(self._connect())
|
||||
logging.warning("Session Twitch terminée, reconnexion dans %ss", retry_delay)
|
||||
logging.warning("Session Twitch perdue, reconnexion complète dans %ss", retry_delay)
|
||||
except Exception as e:
|
||||
logging.error("Déconnexion/erreur Twitch: %s", e)
|
||||
with webapp.app_context():
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 xl:grid-cols-4 gap-4">
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-4 gap-4">
|
||||
<!-- Colonne 1 : Live Twitch -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden flex flex-col xl:h-[600px]">
|
||||
<div class="aspect-video bg-gray-900">
|
||||
@@ -163,24 +163,10 @@
|
||||
Ouvrir
|
||||
</a>
|
||||
</div>
|
||||
<div class="p-3 space-y-2 text-sm overflow-y-auto">
|
||||
<div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">Titre</div>
|
||||
<div class="font-medium text-gray-900 dark:text-white leading-snug" id="streamTitle">{{ stream_title or 'N/A' }}</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">Catégorie</div>
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300" id="streamGame">{{ game_name or 'N/A' }}</span>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">Viewers</div>
|
||||
<div class="text-xl font-bold text-purple-600 dark:text-purple-400" id="streamViewers">{{ viewer_count }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">Uptime</div>
|
||||
<div class="text-sm font-mono font-medium text-gray-900 dark:text-white" id="streamUptime">--:--:--</div>
|
||||
<div class="flex-1 p-3 flex items-center justify-center">
|
||||
<div class="text-center">
|
||||
<div class="text-sm font-medium text-gray-900 dark:text-white">{{ 'Live en cours' if is_live else 'En attente du prochain live' }}</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Lecture Twitch intégrée</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user