From c97fc634fd0d7ff79b5d64f7cfab915e52d1985a Mon Sep 17 00:00:00 2001 From: FrenchMasterSword <33038089+FrenchMasterSword@users.noreply.github.com> Date: Sat, 5 Jan 2019 20:47:13 +0100 Subject: Added Name of exception's class in traceback. --- bot/cogs/snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index cb0454249..0b9aa1b45 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -30,7 +30,7 @@ exec(open(venv_file).read(), dict(__file__=venv_file)) try: {CODE} except Exception as e: - print(e) + print("{}: {}".format(e.__class__.__name__, e)) """ ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") -- cgit v1.2.3 From 19c8213fdd1e58aae2c5566c33bbc6f7a345abd1 Mon Sep 17 00:00:00 2001 From: FrenchMasterSword Date: Sat, 5 Jan 2019 22:43:15 +0100 Subject: Raised exception now returns full traceback. Also directly returns "[No output]" if code is only composed of comments, to avoid breaking try/except. --- bot/cogs/snekbox.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 0b9aa1b45..1be524c1e 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -30,7 +30,8 @@ exec(open(venv_file).read(), dict(__file__=venv_file)) try: {CODE} except Exception as e: - print("{}: {}".format(e.__class__.__name__, e)) + import traceback + print(traceback.format_exc(), end='') """ ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") @@ -86,6 +87,11 @@ 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() -- cgit v1.2.3 From e0897757a728a408d0d7291b6f01041305fbdbd5 Mon Sep 17 00:00:00 2001 From: FrenchMasterSword Date: Sat, 5 Jan 2019 23:21:42 +0100 Subject: Exception doesn't need to be accessed --- bot/cogs/snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 1be524c1e..7ec503686 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -29,7 +29,7 @@ exec(open(venv_file).read(), dict(__file__=venv_file)) try: {CODE} -except Exception as e: +except: import traceback print(traceback.format_exc(), end='') """ -- cgit v1.2.3 From 1746fd37cb3ce84f12240cc8fc193a80a3f9b797 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Thu, 17 Jan 2019 18:37:36 +0100 Subject: The codeblock is already stripped later Co-Authored-By: FrenchMasterSword <33038089+FrenchMasterSword@users.noreply.github.com> --- bot/cogs/snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 7ec503686..9db452ca5 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -31,7 +31,7 @@ try: {CODE} except: import traceback - print(traceback.format_exc(), end='') + print(traceback.format_exc()) """ ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") -- cgit v1.2.3 From 67188ee4eefcf0019009df8afef57de150cfa70a Mon Sep 17 00:00:00 2001 From: Scragly <29337040+scragly@users.noreply.github.com> Date: Sat, 19 Jan 2019 23:35:08 +1000 Subject: Move comment checking to after code extraction, use try:finally block for removing job entry. --- bot/cogs/snekbox.py | 24 +++++++++++------------- 1 file 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): -- cgit v1.2.3 From 4fb6f6f71bd0a54b5f86df4a81c25358b3aee125 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Sat, 19 Jan 2019 17:51:45 +0100 Subject: Hiding 'hidden infractions' from regular users user information embed --- bot/cogs/information.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3