aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-07-27 12:03:54 +0100
committerGravatar Gareth Coles <[email protected]>2018-07-27 12:03:54 +0100
commit0095cfa18ec7ede434ce130c47e6c0cdd873fea5 (patch)
tree7406bdbd8ec00deac0be5b3deb34daf088237425
parentMerge branch 'remove-python-syntax-parser' into 'master' (diff)
Fix eval and add codeblock support
-rw-r--r--bot/cogs/snekbox.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index 7115e3ae5..167e0aed6 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -79,7 +79,15 @@ class Snekbox:
log.info(f"Received code from {ctx.author.name}#{ctx.author.discriminator} for evaluation:\n{code}")
self.jobs[ctx.author.id] = datetime.datetime.now()
- code = [f" {line}" for line in code.split("\n")]
+ if code.startswith("```") and code.endswith("```"):
+ code = code[3:-3]
+
+ if code.startswith("python"):
+ code = code[6:]
+ elif code.startswith("py"):
+ code = code[2:]
+
+ code = [f" {line.strip()}" for line in code.split("\n")]
code = CODE_TEMPLATE.replace("{CODE}", "\n".join(code))
try: