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:
@@ -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")
|
await msg.reply(f"@{msg.user.name} Utilisation : !pdb <nom du jeu> Exemple : !pdb Elden Ring")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _search():
|
||||||
|
with webapp.app_context():
|
||||||
|
return searhProtonDb(name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
with webapp.app_context():
|
games = await loop.run_in_executor(None, _search)
|
||||||
games = await loop.run_in_executor(None, searhProtonDb, name)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Erreur ProtonDB Twitch pour "{name}": {e}')
|
logging.error(f'Erreur ProtonDB Twitch pour "{name}": {e}')
|
||||||
await msg.reply(f"@{msg.user.name} Erreur lors de la recherche ProtonDB.")
|
await msg.reply(f"@{msg.user.name} Erreur lors de la recherche ProtonDB.")
|
||||||
|
|||||||
Reference in New Issue
Block a user