import functools from sopel_SpiceBot_Core_1 import sb def pipe_split(): """ This splits the given command by ` | ` and re-dispatches it internally to the bot. This allows the output of a command to be sent """ def actual_decorator(function): @functools.wraps(function) def internal_pipe_split(bot, trigger, comrun, *args, **kwargs): bot.say("pipe_split") # Get list of trigger command(s) pipes = sb.commands.get_commands_split(trigger, "|") if len(pipes) == 1: function(bot, trigger, comrun, *args, **kwargs) else: # for trigger_dict in commands: # sb.commands.dispatch(bot, trigger, trigger_dict) # return # 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(pipes, comrunsay): 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