Better alias handling

This commit is contained in:
Remy Moll 2021-01-17 22:40:51 +01:00
parent 3b2170cf3d
commit 3401b68d6c
2 changed files with 8 additions and 8 deletions

View File

@ -86,21 +86,21 @@ class BotFramework():
def call_command(cmd, par): def call_command(cmd, par):
result = self.commands[cmd](*par) result = self.commands[cmd](*par)
# *params means the list is unpacked and handed over as separate arguments. # *params means the list is unpacked and handed over as separate arguments.
self.telegram.send_message(result)
self.telegram.increase_counter("execute_activity") self.telegram.increase_counter("execute_activity")
return result
if self.is_command(cmd): # first word if self.is_command(cmd): # first word
call_command(cmd, params) result = call_command(cmd, params)
elif cmd in self.persistence["bot"]["aliases"]: elif cmd in self.persistence["bot"]["aliases"]:
dealias = self.persistence["bot"]["aliases"][cmd].split(" ") # as a list dealias = self.persistence["bot"]["aliases"][cmd].split(" ") # as a list
new_cmd = dealias[0] new_cmd = dealias[0]
params = dealias[1:] + params params = dealias[1:] + params
self.telegram.send_message("Substituted <code>" + cmd + "</code> to <code>" + self.persistence["bot"]["aliases"][cmd] + "</code> and got:") result = "Substituted <code>" + cmd + "</code> to <code>" + self.persistence["bot"]["aliases"][cmd] + "</code> and got:\n\n"
call_command(new_cmd, params) result += call_command(new_cmd, params)
else: else:
self.telegram.send_message("Command <code>" + tmp[0] + "</code> not found.") result = "Command <code>" + tmp[0] + "</code> not found."
self.telegram.send_message(result)
def is_command(self, input): def is_command(self, input):
"""checks if we have a command. Returns true if yes and False if not """checks if we have a command. Returns true if yes and False if not

View File

@ -19,7 +19,7 @@ class Launcher():
self.persistence["global"]["reboots"] += 1 self.persistence["global"]["reboots"] += 1
self.clock_module = clock.main.ClockFace(prst=self.persistence) 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.dashboard_module = dashboard.main.DashBoard(host_ip="0.0.0.0", prst=self.persistence)
self.threads = [] self.threads = []