From f3cbd5100b205d9d9e7f3b3b27b7c37b69834aac Mon Sep 17 00:00:00 2001 From: romangraef Date: Sun, 11 Mar 2018 18:35:47 +0100 Subject: fixed eval und stuff --- lib/__init__.py | 5 ++++- modules/builtins/eval.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/__init__.py b/lib/__init__.py index 2c67b83..edb1b42 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -45,12 +45,15 @@ class CommandContext(object): self.client = client self.channel = channel self.message = message - self.rest_content = re.sub('.*? ', '', message.message) + self.rest_content = re.sub('^.*? ', '', message.message) self.author = message.from_id def respond(self, text): self.client.send_message(self.channel, text=text) + def edit(self, text): + self.client.edit_message_text(chat_id=self.channel, message_id=self.message.id, text=text) + def register_command(func): if not is_command(func): diff --git a/modules/builtins/eval.py b/modules/builtins/eval.py index dfbdd57..77b82ea 100644 --- a/modules/builtins/eval.py +++ b/modules/builtins/eval.py @@ -6,6 +6,7 @@ from lib import * @name('eval') @description('evals a given piece of python code') def eval_command(ctx: CommandContext): + ctx.edit("```\n%s\n```" % ctx.rest_content) try: block = ast.parse(ctx.rest_content, mode='exec') last = ast.Expression(block.body.pop().value) @@ -23,7 +24,7 @@ def eval_command(ctx: CommandContext): 'client': ctx.client, 'print': lambda *content, stdout=False: - print(*content) + print(*content) if stdout else ctx.respond('\t'.join(map(str, content))) } -- cgit