From cfa6f07e7d79a03a9e365d8f755b2d082c180a69 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 23 May 2019 10:22:25 -0400 Subject: [PATCH] attempt && usage --- sopel_modules/SpiceBot/Prerun.py | 33 ++++++++++++++----- sopel_modules/SpiceBot_AI/AI.py | 2 +- sopel_modules/SpiceBot_BotPrivs/BotPrivs.py | 4 +-- .../Channels_Command.py | 2 +- .../NickQueryCommand.py | 2 +- .../SpiceBot_CommandsQuery/QueryCommand.py | 2 +- .../SpiceBot_GifSearch/Gif_API_Commands.py | 2 +- .../SpiceBot_GifSearch/Gif_Command.py | 2 +- .../SpiceBot_GifSearch/Gif_Search_Commands | 2 +- sopel_modules/SpiceBot_Logs/Logs_Command.py | 2 +- sopel_modules/SpiceBot_Messaging/Messaging.py | 6 ++-- sopel_modules/SpiceBot_Update/Update.py | 2 +- 12 files changed, 38 insertions(+), 23 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 794cbdc..3c2c23f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -12,25 +12,40 @@ class BotPrerun(): def __init__(self): self.dict = {} - def args(self, trigger_command_type='module_command'): + def prerun(self, trigger_command_type='module_command'): def actual_decorator(function): @functools.wraps(function) - def argsbuilder(bot, trigger, *args, **kwargs): - trigger.sb = self.sopel_trigger_args(bot, trigger, trigger_command_type) - return function(bot, trigger, *args, **kwargs) - return argsbuilder + def internal_prerun(bot, trigger, *args, **kwargs): + prerun_split = self.sopel_trigger_args(bot, trigger, trigger_command_type) + for prerun in prerun_split: + trigger.sb = prerun + function(bot, trigger, *args, **kwargs) + return + return internal_prerun return actual_decorator def sopel_trigger_args(self, bot, trigger, trigger_command_type='module_command'): + trigger_args = spicemanip.main(trigger.args[1], 'create') if trigger_command_type in ['nickname', 'nickname_command', 'nickname_commands']: trigger_command = spicemanip.main(trigger_args, 2).lower() - trigger_args = spicemanip.main(trigger_args, '3+', 'list') + trigger_args = spicemanip.main(trigger_args, '2+', 'list') else: trigger_command = spicemanip.main(trigger_args, 1).lower()[1:] - trigger_args = spicemanip.main(trigger_args, '2+', 'list') - argsdict = {"com": trigger_command, "args": trigger_args, "type": trigger_command_type} - return argsdict + trigger_args = spicemanip.main(trigger_args, '1+', 'list') + + # Handle && splittings + trigger_args_list_split = spicemanip.main(trigger_args, "split_&&") + if not len(trigger_args_list_split): + trigger_args_list_split.append([]) + + prerun_split = [] + for trigger_args_list in trigger_args_list_split: + trigger_args_part = spicemanip.main(trigger_args, 'create') + argsdict = {"com": trigger_command, "args": trigger_args_part, "type": trigger_command_type} + prerun_split.append(argsdict) + + return prerun_split prerun = BotPrerun() diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 1f4f6e9..2712b84 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -10,7 +10,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED, SpiceBot.events.BOT_COMMANDSQUERY]) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): diff --git a/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py b/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py index cf462b1..cd9ed10 100644 --- a/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py +++ b/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py @@ -9,13 +9,13 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('owners', 'owner') def bot_command_owners(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('admins') def bot_command_admins(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Channels_Command/Channels_Command.py b/sopel_modules/SpiceBot_Channels_Command/Channels_Command.py index 039113a..7aab13f 100644 --- a/sopel_modules/SpiceBot_Channels_Command/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels_Command/Channels_Command.py @@ -10,7 +10,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger): diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index f6c485e..786dff8 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -11,7 +11,7 @@ import spicemanip @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 10bf80f..5754413 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -11,7 +11,7 @@ import spicemanip @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) -@SpiceBot.prerun.args('query_command') +@SpiceBot.prerun.prerun('query_command') @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger): diff --git a/sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py b/sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py index 941d4fe..c19438f 100644 --- a/sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py +++ b/sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py @@ -12,7 +12,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_GIFSEARCH]) -@SpiceBot.prerun.args('prefix_command') +@SpiceBot.prerun.prerun('prefix_command') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): diff --git a/sopel_modules/SpiceBot_GifSearch/Gif_Command.py b/sopel_modules/SpiceBot_GifSearch/Gif_Command.py index bf306c4..3ee6481 100644 --- a/sopel_modules/SpiceBot_GifSearch/Gif_Command.py +++ b/sopel_modules/SpiceBot_GifSearch/Gif_Command.py @@ -12,7 +12,7 @@ import spicemanip @SpiceBot.events.check_ready([SpiceBot.events.BOT_GIFSEARCH]) -@SpiceBot.prerun.args('prefix_command') +@SpiceBot.prerun.prerun('prefix_command') @module.commands('gif') def gif_trigger(bot, trigger): diff --git a/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands b/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands index 941d4fe..c19438f 100644 --- a/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands +++ b/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands @@ -12,7 +12,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_GIFSEARCH]) -@SpiceBot.prerun.args('prefix_command') +@SpiceBot.prerun.prerun('prefix_command') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index bdb17e6..581860f 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -9,7 +9,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS]) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('logs', 'debug') def bot_command_logs(bot, trigger): diff --git a/sopel_modules/SpiceBot_Messaging/Messaging.py b/sopel_modules/SpiceBot_Messaging/Messaging.py index e0ce5e1..1d5200d 100644 --- a/sopel_modules/SpiceBot_Messaging/Messaging.py +++ b/sopel_modules/SpiceBot_Messaging/Messaging.py @@ -9,19 +9,19 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('action') def bot_command_action(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('notice') def bot_command_notice(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('privmsg', 'say', 'msg') def bot_command_privmsg(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index d56ba0d..72cbdfe 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -27,7 +27,7 @@ def setup(bot): bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False) -@SpiceBot.prerun.args('nickname_command') +@SpiceBot.prerun.prerun('nickname_command') @sopel.module.nickname_commands('update') def nickname_comand_update(bot, trigger):