From c5e9d8f23c02e9f1707745457bacd16d1491a5eb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 22 Feb 2022 10:32:40 -0500 Subject: [PATCH] test --- sopel_SpiceBot_Core_Prerun/__init__.py | 45 +++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/sopel_SpiceBot_Core_Prerun/__init__.py b/sopel_SpiceBot_Core_Prerun/__init__.py index cae9d3d..fb7e61e 100644 --- a/sopel_SpiceBot_Core_Prerun/__init__.py +++ b/sopel_SpiceBot_Core_Prerun/__init__.py @@ -8,7 +8,7 @@ class ComRun(): pass -def dispatch(): +def dispatch_multi(): """ This splits the given command by `&&` and re-dispatches it internally to the bot. """ @@ -16,7 +16,7 @@ def dispatch(): def actual_decorator(function): @functools.wraps(function) - def internal_dispatch(bot, trigger, *args, **kwargs): + def internal_dispatch_multi(bot, trigger, *args, **kwargs): bot.say("dispatch") @@ -31,7 +31,30 @@ def dispatch(): function(bot, trigger, *args, **kwargs) - return internal_dispatch + return internal_dispatch_multi + return actual_decorator + + +def dispatch_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_dispatch_pipe(bot, trigger, *args, **kwargs): + + bot.say("dispatch") + + # Get list of trigger command(s) + pipes = get_pipes(bot, trigger) + bot.say(str(pipes)) + + function(bot, trigger, *args, **kwargs) + + return internal_dispatch_pipe return actual_decorator @@ -56,8 +79,9 @@ def prerun(): def actual_decorator(function): - @dispatch() - @command_args() + @dispatch_pipes() + @dispatch_multi() + # @command_args() @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): @@ -72,6 +96,17 @@ def prerun(): return actual_decorator +def get_pipes(bot, trigger): + + # Get && split for multiple commands + if "|" in trigger.args[1]: + pipes = [x.strip() for x in trigger.args[1].split("|")] + else: + pipes = [trigger.args[1]] + + return pipes + + def get_commands(bot, trigger): commands = []