diff --git a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py index 50cbacc..15c9f56 100644 --- a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py +++ b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py @@ -153,9 +153,12 @@ class Commands(): else: return False - def is_rulematch(self, function, command_type): + def is_catchall(self, function, command_type): """Determine if function could be called with a rule match""" - rulematch = False + command_aliases = self.get_command_aliases + return '(.*)' in command_aliases + + def get_command_aliases(self, function, command_type): if command_type == "command": if hasattr(function, 'commands'): command_aliases = function.commands @@ -165,9 +168,7 @@ class Commands(): elif command_type == "action_command": if hasattr(function, 'action_commands'): command_aliases = function.action_commands - if '(.*)' in command_aliases: - rulematch = True - return rulematch + return command_aliases def get_commands_nosplit(self, trigger): commands = [] diff --git a/sopel_SpiceBot_Core_Prerun/__init__.py b/sopel_SpiceBot_Core_Prerun/__init__.py index 4fb4b7c..63e696f 100644 --- a/sopel_SpiceBot_Core_Prerun/__init__.py +++ b/sopel_SpiceBot_Core_Prerun/__init__.py @@ -17,15 +17,15 @@ def prerun(): # we are going to redispatch commands # This will give sopel the appearance of recieving individual commands if comrun.is_multi_command: - if not comrun.is_rulematch: + if not comrun.is_catchall: sb.commands.dispatch(comrun.command) - elif comrun.is_rulematch and comrun.has_command_been_sanitized: + elif comrun.is_catchall and comrun.has_command_been_sanitized: sb.commands.dispatch(comrun.command) for trigger_dict in comrun.commands[1:]: - if not comrun.is_rulematch: + if not comrun.is_catchall: sb.commands.dispatch(trigger_dict) - elif comrun.is_rulematch and comrun.has_command_been_sanitized: + elif comrun.is_catchall and comrun.has_command_been_sanitized: sb.commands.dispatch(trigger_dict) return @@ -39,13 +39,17 @@ def prerun(): sb.commands.dispatch(trigger_dict) return - if comrun.is_rulematch and comrun.is_real_command: + # Block the catch-all from running a command twice + if comrun.is_catchall and comrun.is_real_command: return - elif comrun.is_rulematch and not comrun.is_real_command: + + # The command is not valid + if comrun.is_catchall and not comrun.is_real_command: bot.say("Invalid command: %s" % comrun.command["trigger_command"]) return - print(trigger.match) + # At this point, we update the re.match for trigger + trigger = rebuild_trigger(comrun, trigger) # Run function function(bot, trigger, comrun, *args, **kwargs) @@ -57,6 +61,11 @@ def prerun(): return actual_decorator +def rebuild_trigger(comrun, trigger): + print(trigger.match) + return trigger + + def rebuild_pipes(commands): repipe_trigger_dict = commands[0] @@ -100,8 +109,8 @@ class ComRun(): return sb.commands.what_command_type(self.trigger) @property - def is_rulematch(self): - return sb.commands.is_rulematch(self.function, self.command_type) + def is_catchall(self): + return sb.commands.is_catchall(self.function, self.command_type) @property def is_multi_command(self): @@ -142,10 +151,11 @@ class ComRun(): @property def has_command_been_sanitized(self): - trigger_command = sb.commands.get_command_from_trigger(self.trigger) - if trigger_command != self.command["trigger_command"]: return True - return False + + @property + def re_match(self): + return