aboutsummaryrefslogtreecommitdiff
path: root/drutils/eval.py
diff options
context:
space:
mode:
authorromangraef <romangraef@gmail.com>2019-09-08 19:35:35 +0200
committerromangraef <romangraef@gmail.com>2019-09-08 19:35:35 +0200
commit15a7505738abcaa0d3d82b5cc21f59b653fca3e0 (patch)
tree30c11352fc7e6d9ff5231f9378d70e9cbca627ee /drutils/eval.py
parentf222ac827089aa72c82a3d49dd0df57d190262a3 (diff)
downloaddrutils-15a7505738abcaa0d3d82b5cc21f59b653fca3e0.tar.gz
drutils-15a7505738abcaa0d3d82b5cc21f59b653fca3e0.tar.bz2
drutils-15a7505738abcaa0d3d82b5cc21f59b653fca3e0.zip
augmented converters
Diffstat (limited to 'drutils/eval.py')
-rw-r--r--drutils/eval.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/drutils/eval.py b/drutils/eval.py
index fd105b5..645d069 100644
--- a/drutils/eval.py
+++ b/drutils/eval.py
@@ -13,7 +13,8 @@ REPLACEMENTS = {
}
-async def handle_eval(message: discord.Message, client: discord.Client, to_eval: str, **kwargs):
+async def handle_eval(message: discord.Message, client: discord.Client, to_eval: str,
+ strip_codeblock: bool = False, **kwargs):
channel = message.channel
author = message.author
@@ -36,7 +37,13 @@ async def handle_eval(message: discord.Message, client: discord.Client, to_eval:
'guild': channel.guild if hasattr(channel, 'guild') else None,
}
variables.update(kwargs)
+
lines = to_eval.strip().split('\n')
+ if strip_codeblock:
+ if lines[0].startswith("```"):
+ lines = lines[1:]
+ lines[-1] = ''.join(lines[-1].rsplit('```', 1))
+
block = '\n'.join(' ' + line for line in lines)
code = ("async def code({variables}):\n"
"{block}").format(variables=', '.join(variables.keys()), block=block)