diff options
-rw-r--r-- | bot/cogs/snekbox.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 9e90461cb..2a68950bb 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -1,5 +1,6 @@ import datetime import logging +import re from discord.ext.commands import Bot, Context, command @@ -20,6 +21,8 @@ except Exception as e: print(e) """ +ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") + class Snekbox: """ @@ -70,7 +73,10 @@ class Snekbox: else: output = message.body.decode().strip(" \n") - if "```" in output: + if "<@" in output: + output = output.replace("<@", "<@\u200B") # Zero-width space + + if ESCAPE_REGEX.findall(output): output = "Code block escape attempt detected; will not output result" else: if output.count("\n") > 0: @@ -88,9 +94,14 @@ class Snekbox: elif len(output) >= 1000: output = f"{output[:1000]}\n... (truncated - too long)" - await ctx.send( - f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```" - ) + if output.strip(): + await ctx.send( + f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```" + ) + else: + await ctx.send( + f"{ctx.author.mention} Your eval job has completed.\n\n```py\n[No output]\n```" + ) del self.jobs[ctx.author.id] except Exception: |