From fc274b47aef8b6a59ec56a685a657664d22ee58f Mon Sep 17 00:00:00 2001 From: Mow910 Date: Tue, 24 Mar 2026 00:21:02 +0100 Subject: [PATCH] Implement cooldown feature for ProtonDB command in TwitchBot and update configuration options in webapp - Added a cooldown mechanism to the ProtonDB command to prevent spamming. - Introduced a new configuration option for setting the cooldown duration in seconds. - Updated the ProtonDB template to include the new cooldown setting for Twitch users. --- twitchbot/protondb.py | 13 ++++++++++++ webapp/templates/protondb.html | 38 +++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/twitchbot/protondb.py b/twitchbot/protondb.py index 92c2919..11bb068 100644 --- a/twitchbot/protondb.py +++ b/twitchbot/protondb.py @@ -1,5 +1,6 @@ import asyncio import logging +import time from twitchAPI.chat import ChatMessage @@ -8,6 +9,8 @@ from protondb import searhProtonDb from twitchbot import _user_has_twitch_permission from webapp import webapp +_last_used: float = 0.0 + TIER_ICONS = { 'platinum': '✅ Platinum', 'gold': '🥇 Gold', @@ -49,14 +52,24 @@ def _format_game_response(game: dict) -> str: async def protondb_command(msg: ChatMessage): + global _last_used with webapp.app_context(): if not ConfigurationHelper().getValue('proton_db_twitch_enable'): return permission = ConfigurationHelper().getValue('proton_db_twitch_permission') or 'viewer' + cooldown = int(ConfigurationHelper().getValue('proton_db_twitch_cooldown') or 0) if not _user_has_twitch_permission(msg, permission): return + if cooldown > 0: + elapsed = time.time() - _last_used + if elapsed < cooldown: + remaining = int(cooldown - elapsed) + await msg.reply(f"@{msg.user.name} La commande !pdb est en cooldown, réessaie dans {remaining}s.") + return + _last_used = time.time() + text = msg.text for prefix in ('!protondb', '!pdb'): if text.lower().startswith(prefix): diff --git a/webapp/templates/protondb.html b/webapp/templates/protondb.html index eb91b69..6bf20e4 100644 --- a/webapp/templates/protondb.html +++ b/webapp/templates/protondb.html @@ -110,18 +110,32 @@ -
- - +
+
+ + +
+ +
+ + +

0 = pas de cooldown

+