Add ProtonDB command support for Twitch and update configuration options

- Introduced `cmd_pdb` command in TwitchBot for ProtonDB integration.
- Registered new command for Twitch and updated chat command list.
- Added configuration options for enabling ProtonDB on Twitch in the webapp.
- Updated ProtonDB template to include new settings and permissions for Twitch users.
This commit is contained in:
2026-03-24 00:00:05 +01:00
parent 0453af255f
commit c9f27bf09e
4 changed files with 118 additions and 1 deletions
+5
View File
@@ -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:
+88
View File
@@ -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 <nom du jeu> 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)
+1
View File
@@ -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',
+24 -1
View File
@@ -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">
<label for="proton_db_enable_enable" class="text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer">
Activer la commande ProtonDB
Activer la commande ProtonDB sur Discord (<code class="px-1 py-0.5 bg-gray-200 dark:bg-gray-600 rounded text-xs">!pdb</code>)
</label>
</div>
<div class="flex items-center gap-3 p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg">
<input type="checkbox" name="proton_db_twitch_enable" id="proton_db_twitch_enable"
{% if configuration.getValue('proton_db_twitch_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">
<label for="proton_db_twitch_enable" class="text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer">
Activer la commande ProtonDB sur Twitch (<code class="px-1 py-0.5 bg-gray-200 dark:bg-gray-600 rounded text-xs">!pdb</code>)
</label>
</div>
<div>
<label for="proton_db_twitch_permission" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Permission minimale pour <code class="px-1 py-0.5 bg-gray-200 dark:bg-gray-600 rounded text-xs">!pdb</code> sur Twitch
</label>
<select name="proton_db_twitch_permission" id="proton_db_twitch_permission"
class="w-full sm:w-48 px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all">
{% set current_perm = configuration.getValue('proton_db_twitch_permission') or 'viewer' %}
<option value="viewer" {% if current_perm == 'viewer' %}selected{% endif %}>👁️ Viewer (tout le monde)</option>
<option value="sub" {% if current_perm == 'sub' %}selected{% endif %}>⭐ Abonné (Sub)</option>
<option value="vip" {% if current_perm == 'vip' %}selected{% endif %}>💎 VIP</option>
<option value="moderator" {% if current_perm == 'moderator' %}selected{% endif %}>🛡️ Modérateur</option>
</select>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>