diff options
author | 2022-07-16 22:26:45 +0100 | |
---|---|---|
committer | 2022-07-16 23:45:30 +0100 | |
commit | 7e1f74f345f8322b0704ab5ba1ee3cf81e021c5d (patch) | |
tree | 8fdfb7204a30ab44e1d599f8395cd13354a7767b | |
parent | Infer the snekbox invoker from context (diff) |
Move snekbox lock error handling to a try/except
The cog_command_error isn't hit when the run_job function is called from the button interaction, this means if the lock error is raiseed, it doees not get handled.
-rw-r--r-- | bot/exts/utils/snekbox.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index e1413a013..f4246a145 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -10,7 +10,7 @@ from typing import Literal, Optional, Tuple from botcore.utils import interactions, scheduling from botcore.utils.regex import FORMATTED_CODE_REGEX, RAW_CODE_REGEX from discord import AllowedMentions, HTTPException, Interaction, Message, NotFound, Reaction, User, enums, ui -from discord.ext.commands import Cog, Command, Context, Converter, command, errors, guild_only +from discord.ext.commands import Cog, Command, Context, Converter, command, guild_only from bot.bot import Bot from bot.constants import Categories, Channels, MODERATION_ROLES, Roles, URLs @@ -454,7 +454,14 @@ class Snekbox(Cog): log.info(f"Received code from {ctx.author} for evaluation:\n{code}") while True: - response = await self.send_job(ctx, python_version, code, args=args, job_name=job_name) + try: + response = await self.send_job(ctx, python_version, code, args=args, job_name=job_name) + except LockedResourceError: + await ctx.send( + f"{ctx.author.mention} You've already got a job running - " + "please wait for it to finish!" + ) + return # Store the bot's response message id per invocation, to ensure the `wait_for`s in `continue_job` # don't trigger if the response has already been replaced by a new response. |