This commit is contained in:
deathbybandaid 2022-02-23 14:13:04 -05:00
parent e1faf1341c
commit 73da4fbe2a
2 changed files with 14 additions and 39 deletions

View File

@ -6,7 +6,7 @@ from .comrun import ComRun
# from .clean_trigger import clean_trigger # from .clean_trigger import clean_trigger
# from .validate_command import validate_command # from .validate_command import validate_command
# from .dispatch_multi import dispatch_multi # 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 .command_args import command_args
# from .rule_match import rule_match # from .rule_match import rule_match
@ -39,13 +39,21 @@ def prerun(rulematch=False):
sb.commands.dispatch(commands[0]) sb.commands.dispatch(commands[0])
return 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 # This is where we rebuild trigger
# we validate a few things here # we validate a few things here
# trigger = clean_trigger(bot, trigger, commands[0]) # 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 # Now we have a single valid command
# we are going to validate the command # we are going to validate the command
# as a && or | attached to a command # as a && or | attached to a command

View File

@ -1,39 +1,6 @@
import functools
from sopel_SpiceBot_Core_1 import sb
def pipe_split(): def rebuild_pipes(pipes):
"""
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):
first_pipe = pipes[0] first_pipe = pipes[0]
del pipes[0] del pipes[0]
@ -46,7 +13,7 @@ def reassemble_pipes(pipes, comrunsay):
"trigger_sender": first_pipe["trigger_sender"] "trigger_sender": first_pipe["trigger_sender"]
} }
repipe_trigger_dict["trigger_str"] += " %s" % comrunsay repipe_trigger_dict["trigger_str"] += " | "
for trigger_dict in pipes: for trigger_dict in pipes:
if trigger_dict["trigger_type"] == "command": 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"]) repipe_trigger_dict["trigger_str"] += " | %s%s %s" % (trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])