diff options
| author | 2019-01-19 23:35:08 +1000 | |
|---|---|---|
| committer | 2019-01-19 23:35:08 +1000 | |
| commit | 67188ee4eefcf0019009df8afef57de150cfa70a (patch) | |
| tree | 7029abc85d029d2ec7c1aea284bda711ed0c57d3 | |
| parent | The codeblock is already stripped later (diff) | |
Move comment checking to after code extraction, use try:finally block for removing job entry.
| -rw-r--r-- | bot/cogs/snekbox.py | 24 |
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): |