From 3401b68d6c7b98a14b0822173fb6f0c1f0822d1b Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Sun, 17 Jan 2021 22:40:51 +0100 Subject: [PATCH] Better alias handling --- bot/framework.py | 14 +++++++------- launcher.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bot/framework.py b/bot/framework.py index 3a9ba92..0d437d7 100644 --- a/bot/framework.py +++ b/bot/framework.py @@ -86,21 +86,21 @@ class BotFramework(): def call_command(cmd, par): result = self.commands[cmd](*par) # *params means the list is unpacked and handed over as separate arguments. - self.telegram.send_message(result) - self.telegram.increase_counter("execute_activity") + return result + if self.is_command(cmd): # first word - call_command(cmd, params) + result = call_command(cmd, params) elif cmd in self.persistence["bot"]["aliases"]: dealias = self.persistence["bot"]["aliases"][cmd].split(" ") # as a list new_cmd = dealias[0] params = dealias[1:] + params - self.telegram.send_message("Substituted " + cmd + " to " + self.persistence["bot"]["aliases"][cmd] + " and got:") - call_command(new_cmd, params) + result = "Substituted " + cmd + " to " + self.persistence["bot"]["aliases"][cmd] + " and got:\n\n" + result += call_command(new_cmd, params) else: - self.telegram.send_message("Command " + tmp[0] + " not found.") - + result = "Command " + tmp[0] + " not found." + self.telegram.send_message(result) def is_command(self, input): """checks if we have a command. Returns true if yes and False if not diff --git a/launcher.py b/launcher.py index 5f266e1..ab89924 100644 --- a/launcher.py +++ b/launcher.py @@ -19,7 +19,7 @@ class Launcher(): self.persistence["global"]["reboots"] += 1 self.clock_module = clock.main.ClockFace(prst=self.persistence) - self.bot_module = bot.main.ChatBot(name="ChatterBot", version="2.2", prst=self.persistence, hw_commands=self.clock_module.commands) + self.bot_module = bot.main.ChatBot(name="ChatterBot", version="2.3", prst=self.persistence, hw_commands=self.clock_module.commands) self.dashboard_module = dashboard.main.DashBoard(host_ip="0.0.0.0", prst=self.persistence) self.threads = []