mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[Trivia] Better handling for session errors (#3606)
* Better handling for session errors * Use `stop` instead of `end_game`, translation support
This commit is contained in:
parent
e8b975a095
commit
67ab59106f
@ -98,8 +98,26 @@ class TriviaSession:
|
|||||||
session = cls(ctx, question_list, settings)
|
session = cls(ctx, question_list, settings)
|
||||||
loop = ctx.bot.loop
|
loop = ctx.bot.loop
|
||||||
session._task = loop.create_task(session.run())
|
session._task = loop.create_task(session.run())
|
||||||
|
session._task.add_done_callback(session._error_handler)
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
def _error_handler(self, fut):
|
||||||
|
"""Catches errors in the session task."""
|
||||||
|
try:
|
||||||
|
fut.result()
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
except Exception as exc:
|
||||||
|
LOG.error("A trivia session has encountered an error.\n", exc_info=exc)
|
||||||
|
asyncio.create_task(
|
||||||
|
self.ctx.send(
|
||||||
|
_(
|
||||||
|
"An unexpected error occurred in the trivia session.\nCheck your console or logs for details."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.stop()
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""Run the trivia session.
|
"""Run the trivia session.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user