aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-07-02 22:19:52 +0100
committerGravatar Gareth Coles <[email protected]>2018-07-02 22:19:52 +0100
commit766faffa607ea973ec83590e0a28eb49be29bdb0 (patch)
tree6da49cd80b063eab2435ad40d9122e8fe9d3acd7
parentMerge branch 'fix-parser-not-invoking-the-command' into 'master' (diff)
[Snekbox] More robust codeblock escape handling
-rw-r--r--bot/cogs/snekbox.py19
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: