diff --git a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py index a22e441..15a9c17 100644 --- a/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py +++ b/sopel_SpiceBot_Core_1/SBCore/commands/__init__.py @@ -69,34 +69,34 @@ class Commands(): }) return commands_list - def dispatch(self, bot, trigger, trigger_dict): + def dispatch(self, bot, trigger_dict): if trigger_dict["trigger_type"] == "command": - return self.dispatch_command(bot, trigger, trigger_dict) + return self.dispatch_command(bot, trigger_dict) elif trigger_dict["trigger_type"] == "nickname_command": - return self.dispatch_nickname_command(bot, trigger, trigger_dict) + return self.dispatch_nickname_command(bot, trigger_dict) elif trigger_dict["trigger_type"] == "action_command": - return self.dispatch_action_command(bot, trigger, trigger_dict) + return self.dispatch_action_command(bot, trigger_dict) - def dispatch_command(self, bot, trigger, trigger_dict): + def dispatch_command(self, bot, trigger_dict): pretrigger = PreTrigger( bot.nick, - ":%s %s %s :%s%s" % (trigger.hostmask, "PRIVMSG", trigger.sender, + ":%s %s %s :%s%s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"], trigger_dict["trigger_prefix"], trigger_dict["trigger_str"]) ) bot.dispatch(pretrigger) - def dispatch_nickname_command(self, bot, trigger, trigger_dict): + def dispatch_nickname_command(self, bot, trigger_dict): pretrigger = PreTrigger( bot.nick, - ":%s %s %s :%s %s" % (trigger.hostmask, "PRIVMSG", trigger.sender, + ":%s %s %s :%s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"], trigger_dict["trigger_prefix"], trigger_dict["trigger_str"]) ) bot.dispatch(pretrigger) - def dispatch_action_command(self, bot, trigger, trigger_dict): + def dispatch_action_command(self, bot, trigger_dict): pretrigger = PreTrigger( bot.nick, - ":%s %s %s :%s%s %s%s" % (trigger.hostmask, "PRIVMSG", trigger.sender, + ":%s %s %s :%s%s %s%s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"], "\x01", "ACTION", trigger_dict["trigger_str"], "\x01") ) bot.dispatch(pretrigger) @@ -135,7 +135,9 @@ class Commands(): "trigger_type": first_trigger_type, "trigger_prefix": first_trigger_prefix, "trigger_str": first_trigger, - "trigger_command": first_command + "trigger_command": first_command, + "trigger_hostmask": trigger.hostmask, + "trigger_sender": trigger.sender }) for trigger_str in triggers: @@ -195,7 +197,9 @@ class Commands(): "trigger_type": trigger_type, "trigger_prefix": trigger_prefix, "trigger_str": trigger_str, - "trigger_command": trigger_command + "trigger_command": trigger_command, + "trigger_hostmask": trigger.hostmask, + "trigger_sender": trigger.sender }) return commands diff --git a/sopel_SpiceBot_Core_Prerun/dispatch_multi.py b/sopel_SpiceBot_Core_Prerun/dispatch_multi.py index b532ed7..3a54157 100644 --- a/sopel_SpiceBot_Core_Prerun/dispatch_multi.py +++ b/sopel_SpiceBot_Core_Prerun/dispatch_multi.py @@ -21,7 +21,7 @@ def dispatch_multi(): # If more than 1 trigger command, dispatch if len(commands) > 1: for trigger_dict in commands: - sb.commands.dispatch(bot, trigger, trigger_dict) + sb.commands.dispatch(bot, trigger_dict) return function(bot, trigger, comrun, *args, **kwargs) diff --git a/sopel_SpiceBot_Core_Prerun/pipe_split.py b/sopel_SpiceBot_Core_Prerun/pipe_split.py index 1fe34f9..b1fd6dc 100644 --- a/sopel_SpiceBot_Core_Prerun/pipe_split.py +++ b/sopel_SpiceBot_Core_Prerun/pipe_split.py @@ -18,11 +18,59 @@ def pipe_split(): # Get list of trigger command(s) pipes = sb.commands.get_commands_split(trigger, "|") - bot.say(str(pipes)) - function(bot, trigger, comrun, *args, **kwargs) + if len(pipes) == 1: + function(bot, trigger, comrun, *args, **kwargs) + else: + # for trigger_dict in commands: + # sb.commands.dispatch(bot, trigger, trigger_dict) + # return - print(comrun.test) + # first_pipe = pipes[0] + del pipes[0] + + function(bot, trigger, comrun, *args, **kwargs) + + repipe_trigger_dict = reassemble_pipes(pipes, comrun.say) + sb.commands.dispatch(bot, repipe_trigger_dict) + + bot.say(comrun.say) return internal_pipe_split return actual_decorator + + +def reassemble_pipes(self, pipes, comrunsay): + + """ + { + "trigger_type": first_trigger_type, + "trigger_prefix": first_trigger_prefix, + "trigger_str": first_trigger, + "trigger_command": first_command, + "trigger_hostmask": trigger.hostmask, + "trigger_sender": trigger.sender + } + """ + first_pipe = pipes[0] + del pipes[0] + + repipe_trigger_dict = { + "trigger_type": first_pipe["trigger_type"], + "trigger_prefix": first_pipe["trigger_prefix"], + "trigger_str": first_pipe["trigger_str"], + "trigger_command": first_pipe["trigger_command"], + "trigger_hostmask": first_pipe["trigger_hostmask"], + "trigger_sender": first_pipe["trigger_sender"] + } + + repipe_trigger_dict["trigger_str"] += " %s" % comrunsay + for trigger_dict in pipes: + if trigger_dict["trigger_type"] == "command": + repipe_trigger_dict["trigger_str"] += " | %s%s" % (trigger_dict["trigger_prefix"], trigger_dict["trigger_str"]) + elif trigger_dict["trigger_type"] == "nickname_command": + repipe_trigger_dict["trigger_str"] += " | %s %s" % (trigger_dict["trigger_prefix"], trigger_dict["trigger_str"]) + elif trigger_dict["trigger_type"] == "action_command": + repipe_trigger_dict["trigger_str"] += " | %s %s" % ("/me", trigger_dict["trigger_str"]) + + return repipe_trigger_dict diff --git a/sopel_SpiceBot_Runtime_Commands/__init__.py b/sopel_SpiceBot_Runtime_Commands/__init__.py index be04657..95b5b07 100644 --- a/sopel_SpiceBot_Runtime_Commands/__init__.py +++ b/sopel_SpiceBot_Runtime_Commands/__init__.py @@ -2,16 +2,25 @@ from sopel import plugin -from sopel_SpiceBot_Core_1 import sb - from sopel_SpiceBot_Core_Prerun import prerun +@prerun() +@plugin.command('pipea') +def pipea(bot, trigger, comrun): + comrun.say = "this is a test" + + +@prerun() +@plugin.command('pipeb') +def pipeb(bot, trigger, comrun): + comrun.say = str(trigger.group()).upper() + + @prerun() @plugin.command('test', "testnew") def commands_test(bot, trigger, comrun): bot.say("%s" % trigger.raw) - comrun.test = "this is a real test" @prerun() @@ -38,5 +47,3 @@ def commands_test_c(bot, trigger, comrun): bot.say("test c") bot.say("test c: %s" % trigger.raw) - - sb.commands.dispatch_command(bot, trigger, ".testa")