diff options
| author | 2019-01-19 17:54:30 -0700 | |
|---|---|---|
| committer | 2019-01-19 17:54:30 -0700 | |
| commit | c2ab0c874054d9c0c5b99cd883ad7e8cf853e3c3 (patch) | |
| tree | eb40ea63a0d4664a5ae68165cf6640b8f16cd78f | |
| parent | Merge branch 'master' into newline-antispam (diff) | |
| parent | Merge pull request #286 from python-discord/user-command-hidden-infractions (diff) | |
Merge branch 'master' into newline-antispam
| -rw-r--r-- | bot/cogs/information.py | 5 | ||||
| -rw-r--r-- | bot/cogs/snekbox.py | 24 |
2 files changed, 18 insertions, 11 deletions
diff --git a/bot/cogs/information.py b/bot/cogs/information.py index 129166d2f..0d31cb0d3 100644 --- a/bot/cogs/information.py +++ b/bot/cogs/information.py @@ -135,10 +135,13 @@ class Information: if not with_role_check(ctx, *MODERATION_ROLES): raise BadArgument("You do not have permission to use this command on users other than yourself.") - # Non-moderators may only do this in #bot-commands + # Non-moderators may only do this in #bot-commands and can't see + # hidden infractions. if not with_role_check(ctx, *MODERATION_ROLES): if not ctx.channel.id == Channels.bot: raise MissingPermissions("You can't do that here!") + # Hide hidden infractions for users without a moderation role + hidden = False # Validates hidden input hidden = str(hidden) 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): |