diff options
| author | 2019-01-20 01:22:02 +1000 | |
|---|---|---|
| committer | 2019-01-20 01:22:02 +1000 | |
| commit | 930deb38dd8750b1c802797fd7f8a4099e6ffdc7 (patch) | |
| tree | fd0dcda9f58fd41e9222f9008d155785bbec8cdd | |
| parent | Merge pull request #284 from python-discord/redirect-help-botcommands (diff) | |
| parent | Merge branch 'master' into master (diff) | |
Merge pull request #253 from FrenchMasterSword/master
Eval returns complete traceback. Also doesn't break on comments.
| -rw-r--r-- | bot/cogs/snekbox.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index cb0454249..cfbd032cb 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -29,8 +29,9 @@ exec(open(venv_file).read(), dict(__file__=venv_file)) try: {CODE} -except Exception as e: - print(e) +except: + import traceback + print(traceback.format_exc()) """ ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") @@ -103,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 @@ -174,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): |