diff --git a/twitchbot/__init__.py b/twitchbot/__init__.py index aa2aaa9..c92820c 100644 --- a/twitchbot/__init__.py +++ b/twitchbot/__init__.py @@ -235,6 +235,9 @@ class TwitchBot(): async def cmd_multitwitch(msg): await moderation.multitwitch_command(msg, self.twitch) async def cmd_permit(msg): await link_filter.permit_command(msg, self.twitch) + from twitchbot import protondb as protondb_twitch + async def cmd_pdb(msg): await protondb_twitch.protondb_command(msg) + self.chat.register_command('kick', cmd_timeout) self.chat.register_command('to', cmd_timeout) self.chat.register_command('timeout', cmd_timeout) @@ -256,6 +259,8 @@ class TwitchBot(): self.chat.register_command('no_game', cmd_no_game) self.chat.register_command('multitwitch', cmd_multitwitch) self.chat.register_command('permit', cmd_permit) + self.chat.register_command('pdb', cmd_pdb) + self.chat.register_command('protondb', cmd_pdb) async def _checkOnlineStreamers(self): while True: diff --git a/twitchbot/protondb.py b/twitchbot/protondb.py new file mode 100644 index 0000000..8c6d49b --- /dev/null +++ b/twitchbot/protondb.py @@ -0,0 +1,88 @@ +import asyncio +import logging + +from twitchAPI.chat import ChatMessage + +from database.helpers import ConfigurationHelper +from protondb import searhProtonDb +from twitchbot import _user_has_twitch_permission +from webapp import webapp + +TIER_ICONS = { + 'platinum': '✅ Platinum', + 'gold': '🥇 Gold', + 'silver': '🥈 Silver', + 'bronze': '🥉 Bronze', + 'borked': '❌ Borked', + 'native': '🐧 Native', +} + +AC_ICONS = { + 'supported': '✅', + 'running': '⚠️', + 'broken': '❌', + 'denied': '🚫', + 'planned': '📅', +} + + +def _format_game_response(game: dict) -> str: + name = game.get('name', '?') + tier = (game.get('tier') or '').lower() + tier_label = TIER_ICONS.get(tier, tier.capitalize() if tier else '?') + g_id = game.get('id', '') + + parts = [f"[{name}] {tier_label}"] + + ac_status = (game.get('anticheat_status') or '').lower() + if ac_status: + ac_icon = AC_ICONS.get(ac_status, '❔') + acs = game.get('anticheats') or [] + ac_list = ', '.join(str(ac) for ac in acs if ac) + ac_part = f"Anti-cheat: {ac_icon} {ac_status.capitalize()}" + if ac_list: + ac_part += f" ({ac_list})" + parts.append(ac_part) + + parts.append(f"protondb.com/app/{g_id}") + return ' | '.join(parts) + + +async def protondb_command(msg: ChatMessage): + with webapp.app_context(): + if not ConfigurationHelper().getValue('proton_db_twitch_enable'): + return + permission = ConfigurationHelper().getValue('proton_db_twitch_permission') or 'viewer' + + if not _user_has_twitch_permission(msg, permission): + return + + text = msg.text + for prefix in ('!protondb', '!pdb'): + if text.lower().startswith(prefix): + text = text[len(prefix):] + break + name = text.strip() + + if not name: + await msg.reply(f"@{msg.user.name} Utilisation : !pdb Exemple : !pdb Elden Ring") + return + + try: + loop = asyncio.get_event_loop() + with webapp.app_context(): + games = await loop.run_in_executor(None, searhProtonDb, name) + except Exception as e: + logging.error(f'Erreur ProtonDB Twitch pour "{name}": {e}') + await msg.reply(f"@{msg.user.name} Erreur lors de la recherche ProtonDB.") + return + + if not games: + await msg.reply(f"@{msg.user.name} Aucun jeu trouvé pour \"{name}\" sur Steam.") + return + + for game in games[:3]: + response = _format_game_response(game) + if len(response) > 500: + response = response[:497] + '...' + await msg.reply(response) diff --git a/webapp/configurations.py b/webapp/configurations.py index 05585d8..bd6f13d 100644 --- a/webapp/configurations.py +++ b/webapp/configurations.py @@ -16,6 +16,7 @@ def updateConfiguration(): checkboxes = { 'humble_bundle_enable': 'humble_bundle_channel', 'proton_db_enable_enable': 'proton_db_api_id', + 'proton_db_twitch_enable': 'proton_db_api_id', 'moderation_enable': 'moderation_staff_role_ids', 'moderation_ban_enable': 'moderation_staff_role_ids', 'moderation_kick_enable': 'moderation_staff_role_ids', diff --git a/webapp/templates/protondb.html b/webapp/templates/protondb.html index 4f32a34..eb91b69 100644 --- a/webapp/templates/protondb.html +++ b/webapp/templates/protondb.html @@ -97,9 +97,32 @@ {% if configuration.getValue('proton_db_enable_enable') %}checked{% endif %} class="w-5 h-5 rounded border-gray-300 dark:border-gray-600 text-purple-600 focus:ring-purple-500 dark:bg-gray-700"> + +
+ + +
+ +
+ + +