From a1bed3d02eff5b73768fd51fb2f3bee5601211fb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 12 Feb 2022 18:41:28 -0500 Subject: [PATCH] test --- .../SBCore/commands/__init__.py | 33 ++++++++++- sopel_SpiceBot_Core_Prerun/__init__.py | 55 ++++++++++++++----- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py index 14cd256..a9fd1a7 100644 --- a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py +++ b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py @@ -8,6 +8,27 @@ class Commands(): def __init__(self): self.bot = None + @property + def valid_sopel_commands(self): + found = [] + for command_dict in self.sopel_commands: + found.append(command_dict["name"]).extend(command_dict["aliases"]) + return found + + @property + def valid_sopel_nickname_commands(self): + found = [] + for command_dict in self.sopel_nickname_commands: + found.append(command_dict["name"]).extend(command_dict["aliases"]) + return found + + @property + def valid_sopel_action_commands(self): + found = [] + for command_dict in self.sopel_action_commands: + found.append(command_dict["name"]).extend(command_dict["aliases"]) + return found + @property def sopel_commands(self): commands_list = [] @@ -16,6 +37,7 @@ class Commands(): commands_list.append({ "name": command.name, "aliases": command.aliases, + "type": "command" }) return commands_list @@ -27,6 +49,7 @@ class Commands(): commands_list.append({ "name": command.name, "aliases": command.aliases, + "type": "nickname_command" }) return commands_list @@ -38,16 +61,20 @@ class Commands(): commands_list.append({ "name": command.name, "aliases": command.aliases, + "type": "action_command" }) return commands_list def dispatch(self, bot, trigger, trigger_dict): if trigger_dict["trigger_type"] == "command": - return self.dispatch_command(bot, trigger, trigger_dict) + if trigger_dict["trigger_type"] in self.valid_sopel_commands: + return self.dispatch_command(bot, trigger, trigger_dict) elif trigger_dict["trigger_type"] == "nickname_command": - return self.dispatch_nickname_command(bot, trigger, trigger_dict) + if trigger_dict["trigger_type"] in self.valid_sopel_nickname_commands: + return self.dispatch_nickname_command(bot, trigger, trigger_dict) elif trigger_dict["trigger_type"] == "action_command": - return self.dispatch_action_command(bot, trigger, trigger_dict) + if trigger_dict["trigger_type"] in self.valid_sopel_action_commands: + return self.dispatch_action_command(bot, trigger, trigger_dict) def dispatch_command(self, bot, trigger, trigger_dict): pretrigger = PreTrigger( diff --git a/sopel_SpiceBot_Core_Prerun/__init__.py b/sopel_SpiceBot_Core_Prerun/__init__.py index 45ba4b8..6768383 100644 --- a/sopel_SpiceBot_Core_Prerun/__init__.py +++ b/sopel_SpiceBot_Core_Prerun/__init__.py @@ -27,43 +27,70 @@ def get_commands(bot, trigger): if trigger.tags["intent"] == "ACTION": first_trigger_type = "action_command" first_trigger_prefix = "ACTION" - first_trigger = first_trigger else: bot.say("what kind of rule command is this") first_trigger_type = "rule" first_trigger_prefix = None - first_trigger = first_trigger + + first_command = first_trigger.split(" ")[0] commands.append({ "trigger_type": first_trigger_type, "trigger_prefix": first_trigger_prefix, - "trigger_str": first_trigger + "trigger_str": first_trigger, + "trigger_command": first_command }) - for trigger_item in triggers: + for trigger_str in triggers: - if trigger_item.startswith(tuple(sb.config.prefix_list)): + if trigger_str.startswith(tuple(sb.config.prefix_list)): trigger_type = "command" - trigger_prefix = trigger_item[0] - trigger_str = trigger_item[1:] - elif trigger_item.startswith(bot.nick): + trigger_prefix = trigger_str[0] + trigger_str = trigger_str[1:] + trigger_command = trigger_str.split(" ")[0] + elif trigger_str.startswith(bot.nick): trigger_type = "nickname_command" - trigger_prefix = str(trigger_item.split(" ")[0]) - trigger_str = " ".join(trigger_item.split(" ")[1:]) - elif trigger_item.startswith(tuple(["ACTION", "/me"])): + trigger_prefix = str(trigger_str.split(" ")[0]) + trigger_str = " ".join(trigger_str.split(" ")[1:]) + trigger_command = trigger_str.split(" ")[0] + elif trigger_str.startswith(tuple(["ACTION", "/me"])): trigger_type = "action_command" trigger_prefix = "ACTION" - trigger_str = " ".join(trigger_item.split(" ")[1:]) + trigger_str = " ".join(trigger_str.split(" ")[1:]) + trigger_command = trigger_str.split(" ")[0] else: + command_types = ["command", "nickname_command", "action_command"] # TODO Assume same command type until proven otherwise trigger_type = first_trigger_type trigger_prefix = first_trigger_prefix - trigger_str = trigger_item + trigger_str = trigger_str + trigger_command = trigger_str.split(" ")[0] + + # Still under the assumption that the command is most likely the same type as first command + command_types.remove(trigger_type) + command_types.insert(0, trigger_type) + + found = [] + for command_type in command_types: + + if command_type == "command": + commands_list = sb.commands.valid_sopel_commands + elif command_type == "nickname_command": + commands_list = sb.commands.valid_sopel_nickname_commands + elif command_type == "action_command": + commands_list = sb.commands.valid_sopel_action_commands + + if trigger_command in commands_list: + found.append(command_type) + + if len(found): + trigger_type = found[0] commands.append({ "trigger_type": trigger_type, "trigger_prefix": trigger_prefix, - "trigger_str": trigger_str + "trigger_str": trigger_str, + "trigger_command": trigger_command }) return commands