From 73da4fbe2a502849c1ea3c18d5637ac3671c4674 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 23 Feb 2022 14:13:04 -0500 Subject: [PATCH] test --- sopel_SpiceBot_Core_Prerun/__init__.py | 16 +++++++--- sopel_SpiceBot_Core_Prerun/pipe_split.py | 37 ++---------------------- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/sopel_SpiceBot_Core_Prerun/__init__.py b/sopel_SpiceBot_Core_Prerun/__init__.py index 6f05343..4c511e9 100644 --- a/sopel_SpiceBot_Core_Prerun/__init__.py +++ b/sopel_SpiceBot_Core_Prerun/__init__.py @@ -6,7 +6,7 @@ from .comrun import ComRun # from .clean_trigger import clean_trigger # from .validate_command import validate_command # from .dispatch_multi import dispatch_multi -# from .pipe_split import pipe_split +from .pipe_split import rebuild_pipes # from .command_args import command_args # from .rule_match import rule_match @@ -39,13 +39,21 @@ def prerun(rulematch=False): sb.commands.dispatch(commands[0]) return + # Get list of trigger command(s) by | split + commands = sb.commands.get_commands_split(trigger, "|") + + # Validate | split + trigger_command = sb.commands.get_command_from_trigger(trigger) + if trigger_command != commands[0]["trigger_command"]: + trigger_dict = rebuild_pipes(commands) + print(trigger_dict) + sb.commands.dispatch(trigger_dict) + return + # This is where we rebuild trigger # we validate a few things here # trigger = clean_trigger(bot, trigger, commands[0]) - # Get list of trigger command(s) by | split - commands = sb.commands.get_commands_split(trigger, "|") - # Now we have a single valid command # we are going to validate the command # as a && or | attached to a command diff --git a/sopel_SpiceBot_Core_Prerun/pipe_split.py b/sopel_SpiceBot_Core_Prerun/pipe_split.py index 80aa7ac..4fb4fc2 100644 --- a/sopel_SpiceBot_Core_Prerun/pipe_split.py +++ b/sopel_SpiceBot_Core_Prerun/pipe_split.py @@ -1,39 +1,6 @@ -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): - - # Get list of trigger command(s) - pipes = sb.commands.get_commands_split(trigger, "|") - - comrun.trigger_dict = pipes[0] - del pipes[0] - - if len(pipes): - comrun.piped = True - - function(bot, trigger, comrun, *args, **kwargs) - - if len(pipes): - repipe_trigger_dict = reassemble_pipes(pipes, comrun.say) - sb.commands.dispatch(repipe_trigger_dict) - - return internal_pipe_split - return actual_decorator - - -def reassemble_pipes(pipes, comrunsay): +def rebuild_pipes(pipes): first_pipe = pipes[0] del pipes[0] @@ -46,7 +13,7 @@ def reassemble_pipes(pipes, comrunsay): "trigger_sender": first_pipe["trigger_sender"] } - repipe_trigger_dict["trigger_str"] += " %s" % comrunsay + repipe_trigger_dict["trigger_str"] += " | " for trigger_dict in pipes: if trigger_dict["trigger_type"] == "command": repipe_trigger_dict["trigger_str"] += " | %s%s %s" % (trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])