aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/snekbox.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index 9db452ca5..cfbd032cb 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -87,11 +87,6 @@ class Snekbox:
if not code: # None or empty string
return await ctx.invoke(self.bot.get_command("help"), "eval")
- if all([line.startswith('#') for line in code.strip('\n')]): # Only comments
- return await ctx.send(
- f"{ctx.author.mention} Your eval job has completed.\n\n```py\n[No output]\n```"
- )
-
log.info(f"Received code from {ctx.author.name}#{ctx.author.discriminator} for evaluation:\n{code}")
self.jobs[ctx.author.id] = datetime.datetime.now()
@@ -109,10 +104,16 @@ class Snekbox:
code = textwrap.dedent(RAW_CODE_REGEX.fullmatch(code).group("code"))
log.trace(f"Eval message contains not or badly formatted code, stripping whitespace only:\n{code}")
- code = textwrap.indent(code, " ")
- code = CODE_TEMPLATE.replace("{CODE}", code)
-
try:
+ stripped_lines = [ln.strip() for ln in code.split('\n')]
+ if all([line.startswith('#') for line in stripped_lines]):
+ return await ctx.send(
+ f"{ctx.author.mention} Your eval job has completed.\n\n```[No output]```"
+ )
+
+ code = textwrap.indent(code, " ")
+ code = CODE_TEMPLATE.replace("{CODE}", code)
+
await self.rmq.send_json(
"input",
snekid=str(ctx.author.id), message=code
@@ -180,13 +181,10 @@ class Snekbox:
else:
await ctx.send(
- f"{ctx.author.mention} Your eval job has completed.\n\n```py\n[No output]\n```"
+ f"{ctx.author.mention} Your eval job has completed.\n\n```[No output]```"
)
-
- del self.jobs[ctx.author.id]
- except Exception:
+ finally:
del self.jobs[ctx.author.id]
- raise
@eval_command.error
async def eval_command_error(self, ctx: Context, error: CommandError):