Refactor ProtonDB command execution in TwitchBot for improved context handling

- Introduced a helper function `_search` to encapsulate the ProtonDB search logic within the app context.
- Updated the command execution to use the new helper function, enhancing code clarity and maintainability.
This commit is contained in:
2026-03-24 00:02:49 +01:00
parent c9f27bf09e
commit a93d5cda70
+5 -2
View File
@@ -68,10 +68,13 @@ async def protondb_command(msg: ChatMessage):
await msg.reply(f"@{msg.user.name} Utilisation : !pdb <nom du jeu> Exemple : !pdb Elden Ring")
return
def _search():
with webapp.app_context():
return searhProtonDb(name)
try:
loop = asyncio.get_event_loop()
with webapp.app_context():
games = await loop.run_in_executor(None, searhProtonDb, name)
games = await loop.run_in_executor(None, _search)
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.")