From e5bea4ea9c8108239069e32aca5e09f1bc302acd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 31 May 2019 12:41:23 -0400 Subject: [PATCH] channel and events --- sopel_modules/SpiceBot/Commands.py | 5 +- sopel_modules/SpiceBot_AI/AI.py | 2 +- .../SpiceBot_Core_Commands/Commands.py | 4 +- .../SpiceBot_Core_Processing/Events.py | 68 +++++++++++++++++++ .../Modules.py} | 24 +++---- .../SpiceBot_Core_Processing/__init__.py | 2 + sopel_modules/SpiceBot_Events/Connected.py | 16 ----- .../SpiceBot_Events/Connection_Count.py | 15 ---- sopel_modules/SpiceBot_Events/Loaded.py | 15 ---- sopel_modules/SpiceBot_Events/Logging.py | 14 ---- sopel_modules/SpiceBot_Events/Queue.py | 18 ----- sopel_modules/SpiceBot_Events/Ready.py | 14 ---- sopel_modules/SpiceBot_Events/Welcome.py | 17 ----- sopel_modules/SpiceBot_Events/__init__.py | 13 ---- .../SpiceBot_Module_Parsing/__init__.py | 10 --- .../StartupMonologue_Display_Commands.py | 2 +- 16 files changed, 86 insertions(+), 153 deletions(-) create mode 100644 sopel_modules/SpiceBot_Core_Processing/Events.py rename sopel_modules/{SpiceBot_Module_Parsing/ModuleParsing.py => SpiceBot_Core_Processing/Modules.py} (50%) delete mode 100644 sopel_modules/SpiceBot_Events/Connected.py delete mode 100644 sopel_modules/SpiceBot_Events/Connection_Count.py delete mode 100644 sopel_modules/SpiceBot_Events/Loaded.py delete mode 100644 sopel_modules/SpiceBot_Events/Logging.py delete mode 100644 sopel_modules/SpiceBot_Events/Queue.py delete mode 100644 sopel_modules/SpiceBot_Events/Ready.py delete mode 100644 sopel_modules/SpiceBot_Events/Welcome.py delete mode 100644 sopel_modules/SpiceBot_Events/__init__.py delete mode 100644 sopel_modules/SpiceBot_Module_Parsing/__init__.py diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 3bc8fdd..75d5e33 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -29,6 +29,9 @@ class BotCommands(): }, 'disabled': {} } + self.module_files_parse() + for comtype in ['module', 'nickname', 'rule']: + logs.log('SpiceBot_Commands', "Found " + str(len(self.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True) def find_command_type(self, command): for commandstype in self.dict['commands'].keys(): @@ -129,7 +132,7 @@ class BotCommands(): pypi_modules_dir = os.path.join(plugin_dir, pathname) filepathlisting.append(pypi_modules_dir) except Exception as e: - logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e)) + logs.log('SpiceBOT_COMMANDS', "sopel_modules not loaded :" + str(e)) # Extra directories for directory in botconfig.extra: diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 314dc26..4ee3cd2 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -9,7 +9,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED, SpiceBot.events.BOT_COMMANDSQUERY]) +@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED, SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun.prerun('nickname') @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index bf632a8..461c62a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -12,7 +12,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) +@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun.prerun('nickname') @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): @@ -78,7 +78,7 @@ def query_detection_nick(bot, trigger): bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) +@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun.prerun('query') @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Processing/Events.py b/sopel_modules/SpiceBot_Core_Processing/Events.py new file mode 100644 index 0000000..422e493 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Processing/Events.py @@ -0,0 +1,68 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Channels system. +""" +import sopel + +import sopel_modules.SpiceBot as SpiceBot + + +@sopel.module.event(SpiceBot.events.BOT_WELCOME) +@sopel.module.rule('.*') +def bot_events_connected(bot, trigger): + """For items tossed in a queue, this will trigger them accordingly""" + while True: + if len(SpiceBot.events.dict["trigger_queue"]): + pretriggerdict = SpiceBot.events.dict["trigger_queue"][0] + SpiceBot.events.dispatch(bot, pretriggerdict) + del SpiceBot.events.dict["trigger_queue"][0] + + +@sopel.module.event(SpiceBot.events.BOT_WELCOME, SpiceBot.events.BOT_READY, SpiceBot.events.BOT_CONNECTED, SpiceBot.events.BOT_LOADED) +@sopel.module.rule('.*') +def bot_events_complete(bot, trigger): + """This is here simply to log to stderr that this was recieved.""" + SpiceBot.logs.log('SpiceBot_Events', trigger.args[1], True) + + +@sopel.module.event(SpiceBot.events.RPL_WELCOME) +@sopel.module.rule('.*') +def bot_startup_welcome(bot, trigger): + """The Bot events system does not start until RPL_WELCOME 001 is recieved + from the server""" + if SpiceBot.events.check(SpiceBot.events.BOT_WELCOME): + return + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_WELCOME, "Welcome to the SpiceBot Events System") + + +@sopel.module.event(SpiceBot.events.BOT_WELCOME) +@sopel.module.rule('.*') +def bot_events_start(bot, trigger): + """This stage is redundant, but shows the system is working.""" + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_READY, "Ready To Process module setup procedures") + + +@sopel.module.event(SpiceBot.events.BOT_WELCOME) +@sopel.module.rule('.*') +def bot_events_Connected(bot, trigger): + """Here, we wait until we are in at least one channel""" + while not len(bot.channels.keys()) > 0: + pass + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_CONNECTED, "Bot Connected to IRC") + + +@SpiceBot.events.startup_check_ready() +@sopel.module.event(SpiceBot.events.BOT_READY) +@sopel.module.rule('.*') +def bot_events_startup_complete(bot, trigger): + """All events registered as required for startup have completed""" + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_LOADED, "All registered modules setup procedures have completed") + + +@sopel.module.event(SpiceBot.events.RPL_WELCOME) +@sopel.module.rule('.*') +def bot_startup_reconnect(bot, trigger): + SpiceBot.events.dict["RPL_WELCOME_Count"] += 1 + if SpiceBot.events.dict["RPL_WELCOME_Count"] > 1: + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_RECONNECTED, "Bot ReConnected to IRC") diff --git a/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py b/sopel_modules/SpiceBot_Core_Processing/Modules.py similarity index 50% rename from sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py rename to sopel_modules/SpiceBot_Core_Processing/Modules.py index 38d6ac2..7d998ed 100644 --- a/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py +++ b/sopel_modules/SpiceBot_Core_Processing/Modules.py @@ -1,29 +1,21 @@ -# coding=utf-8 - +# coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function - +""" +This is the SpiceBot Channels system. +""" import sopel -import sopel.module import sopel_modules.SpiceBot as SpiceBot -def setup(bot): - SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure") - SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY]) - - SpiceBot.commands.module_files_parse() - - for comtype in ['module', 'nickname', 'rule']: - SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True) - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDSQUERY, "SpiceBot_Commands") - - @sopel.module.event(SpiceBot.events.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): + SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDS]) + for comtype in SpiceBot.commands.dict['commands'].keys(): if comtype not in ['module', 'nickname', 'rule']: SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True) + + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDS, "SpiceBot_Commands") diff --git a/sopel_modules/SpiceBot_Core_Processing/__init__.py b/sopel_modules/SpiceBot_Core_Processing/__init__.py index 3901a3c..c0bc043 100644 --- a/sopel_modules/SpiceBot_Core_Processing/__init__.py +++ b/sopel_modules/SpiceBot_Core_Processing/__init__.py @@ -7,6 +7,8 @@ This module contains references only for other modules to utilize. """ from .Channels import * +from .Events import * +from .Modules import * __author__ = 'Sam Zick' diff --git a/sopel_modules/SpiceBot_Events/Connected.py b/sopel_modules/SpiceBot_Events/Connected.py deleted file mode 100644 index ecf81ac..0000000 --- a/sopel_modules/SpiceBot_Events/Connected.py +++ /dev/null @@ -1,16 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_WELCOME) -@sopel.module.rule('.*') -def bot_events_Connected(bot, trigger): - """Here, we wait until we are in at least one channel""" - while not len(bot.channels.keys()) > 0: - pass - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_CONNECTED, "Bot Connected to IRC") diff --git a/sopel_modules/SpiceBot_Events/Connection_Count.py b/sopel_modules/SpiceBot_Events/Connection_Count.py deleted file mode 100644 index 461ed8d..0000000 --- a/sopel_modules/SpiceBot_Events/Connection_Count.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.RPL_WELCOME) -@sopel.module.rule('.*') -def bot_startup_welcome(bot, trigger): - SpiceBot.events.dict["RPL_WELCOME_Count"] += 1 - if SpiceBot.events.dict["RPL_WELCOME_Count"] > 1: - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_RECONNECTED, "Bot ReConnected to IRC") diff --git a/sopel_modules/SpiceBot_Events/Loaded.py b/sopel_modules/SpiceBot_Events/Loaded.py deleted file mode 100644 index 820c3b2..0000000 --- a/sopel_modules/SpiceBot_Events/Loaded.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@SpiceBot.events.startup_check_ready() -@sopel.module.event(SpiceBot.events.BOT_READY) -@sopel.module.rule('.*') -def bot_events_startup_complete(bot, trigger): - """All events registered as required for startup have completed""" - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_LOADED, "All registered modules setup procedures have completed") diff --git a/sopel_modules/SpiceBot_Events/Logging.py b/sopel_modules/SpiceBot_Events/Logging.py deleted file mode 100644 index 77c1fb8..0000000 --- a/sopel_modules/SpiceBot_Events/Logging.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_WELCOME, SpiceBot.events.BOT_READY, SpiceBot.events.BOT_CONNECTED, SpiceBot.events.BOT_LOADED) -@sopel.module.rule('.*') -def bot_events_complete(bot, trigger): - """This is here simply to log to stderr that this was recieved.""" - SpiceBot.logs.log('SpiceBot_Events', trigger.args[1], True) diff --git a/sopel_modules/SpiceBot_Events/Queue.py b/sopel_modules/SpiceBot_Events/Queue.py deleted file mode 100644 index 68905c0..0000000 --- a/sopel_modules/SpiceBot_Events/Queue.py +++ /dev/null @@ -1,18 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_WELCOME) -@sopel.module.rule('.*') -def bot_events_connected(bot, trigger): - """For items tossed in a queue, this will trigger them accordingly""" - while True: - if len(SpiceBot.events.dict["trigger_queue"]): - pretriggerdict = SpiceBot.events.dict["trigger_queue"][0] - SpiceBot.events.dispatch(bot, pretriggerdict) - del SpiceBot.events.dict["trigger_queue"][0] diff --git a/sopel_modules/SpiceBot_Events/Ready.py b/sopel_modules/SpiceBot_Events/Ready.py deleted file mode 100644 index 9284475..0000000 --- a/sopel_modules/SpiceBot_Events/Ready.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_WELCOME) -@sopel.module.rule('.*') -def bot_events_start(bot, trigger): - """This stage is redundant, but shows the system is working.""" - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_READY, "Ready To Process module setup procedures") diff --git a/sopel_modules/SpiceBot_Events/Welcome.py b/sopel_modules/SpiceBot_Events/Welcome.py deleted file mode 100644 index 27e3c3d..0000000 --- a/sopel_modules/SpiceBot_Events/Welcome.py +++ /dev/null @@ -1,17 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.RPL_WELCOME) -@sopel.module.rule('.*') -def bot_startup_welcome(bot, trigger): - """The Bot events system does not start until RPL_WELCOME 001 is recieved - from the server""" - if SpiceBot.events.check(SpiceBot.events.BOT_WELCOME): - return - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_WELCOME, "Welcome to the SpiceBot Events System") diff --git a/sopel_modules/SpiceBot_Events/__init__.py b/sopel_modules/SpiceBot_Events/__init__.py deleted file mode 100644 index e2846d8..0000000 --- a/sopel_modules/SpiceBot_Events/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf8 -from __future__ import unicode_literals, absolute_import, division, print_function - -from .Welcome import * -from .Ready import * -from .Connected import * -from .Loaded import * -from .Queue import * -from .Logging import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_Module_Parsing/__init__.py b/sopel_modules/SpiceBot_Module_Parsing/__init__.py deleted file mode 100644 index 09f2208..0000000 --- a/sopel_modules/SpiceBot_Module_Parsing/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -# coding=utf8 -"""Parse module file information -""" -from __future__ import unicode_literals, absolute_import, division, print_function - -from .ModuleParsing import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py index e5a490f..4f16db4 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py @@ -7,7 +7,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@sopel.module.event(SpiceBot.events.BOT_COMMANDSQUERY) +@sopel.module.event(SpiceBot.events.BOT_COMMANDS) @sopel.module.rule('.*') def bot_startup_monologue_commands(bot, trigger):