SpiceBot/sopel_SpiceBot_Core_Prerun/dispatch_multi.py
deathbybandaid a2569cab86 test
2022-02-22 12:31:14 -05:00

29 lines
810 B
Python

import functools
from sopel_SpiceBot_Core_1 import sb
def dispatch_multi():
"""
This splits the given command by `&&` and re-dispatches it internally to the bot.
"""
def actual_decorator(function):
@functools.wraps(function)
def internal_dispatch_multi(bot, trigger, comrun, *args, **kwargs):
# Get list of trigger command(s)
commands = sb.commands.get_commands_split(trigger, "&&")
if len(commands) == 1:
function(bot, trigger, comrun, *args, **kwargs)
comrun.trigger_dict = commands[0]
else:
for trigger_dict in commands:
sb.commands.dispatch(bot, trigger_dict)
return
return internal_dispatch_multi
return actual_decorator