From d5f53727a70998412687775c2025e3f5400dbedc Mon Sep 17 00:00:00 2001 From: dgouju Date: Tue, 7 Aug 2018 09:44:14 +0200 Subject: [PATCH] Makes commands case-insensitive and sort help for better readability --- ciscosparkbot/Spark.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ciscosparkbot/Spark.py b/ciscosparkbot/Spark.py index 3b942b4..5480294 100644 --- a/ciscosparkbot/Spark.py +++ b/ciscosparkbot/Spark.py @@ -247,7 +247,7 @@ def process_incoming_message(self): # Find the command that was sent, if any command = "" for c in self.commands.items(): - if message.text.find(c[0]) != -1: + if message.text.lower().find(c[0]) != -1: command = c[0] sys.stderr.write("Found command: " + command + "\n") # If a command was found, stop looking for others @@ -285,7 +285,7 @@ def add_command(self, command, help_message, callback): :param callback: The function to run when this command is given :return: """ - self.commands[command] = {"help": help_message, "callback": callback} + self.commands[command.lower()] = {"help": help_message, "callback": callback} def remove_command(self, command): """ @@ -315,7 +315,7 @@ def send_help(self, post_data): """ message = "Hello! " message += "I understand the following commands: \n" - for c in self.commands.items(): + for c in sorted(self.commands.items()): if c[1]["help"][0] != "*": message += "* **%s**: %s \n" % (c[0], c[1]["help"]) return message