From e2c3869365e67b78a754341f4cd13fb7d2ea40b3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 9 Feb 2022 18:16:57 -0500 Subject: [PATCH] test --- SpiceBot/SpiceBotCore/botsetup/__init__.py | 9 +++ SpiceBot/SpiceBotCore/botsetup/events.py | 62 +++++++++++++++++ .../SpiceBotCore/botsetup/welcome_setup.py | 20 ++++++ SpiceBot/__init__.py | 66 ------------------- 4 files changed, 91 insertions(+), 66 deletions(-) create mode 100644 SpiceBot/SpiceBotCore/botsetup/__init__.py create mode 100644 SpiceBot/SpiceBotCore/botsetup/events.py create mode 100644 SpiceBot/SpiceBotCore/botsetup/welcome_setup.py diff --git a/SpiceBot/SpiceBotCore/botsetup/__init__.py b/SpiceBot/SpiceBotCore/botsetup/__init__.py new file mode 100644 index 0000000..676934f --- /dev/null +++ b/SpiceBot/SpiceBotCore/botsetup/__init__.py @@ -0,0 +1,9 @@ +# coding=utf8 +"""SpiceBotSERV +A Niche Wrapper around Sopel +""" +from __future__ import unicode_literals, absolute_import, division, print_function + +from .welcome_setup import * +from .events import * +# from .startupmonologue import * diff --git a/SpiceBot/SpiceBotCore/botsetup/events.py b/SpiceBot/SpiceBotCore/botsetup/events.py new file mode 100644 index 0000000..3b6be3c --- /dev/null +++ b/SpiceBot/SpiceBotCore/botsetup/events.py @@ -0,0 +1,62 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Events system. +""" +from threading import Thread +from sopel import plugin + +from SpiceBot import sb + + +@plugin.event(sb.events.BOT_WELCOME, sb.events.BOT_READY, sb.events.BOT_CONNECTED, sb.events.BOT_LOADED) +@plugin.rule('.*') +def bot_events_complete(bot, trigger): + """This is here simply to log to stderr that this was recieved.""" + sb.logger.info('SpiceBot_Events: %s' % trigger.args[1]) + + +@plugin.event(sb.events.RPL_WELCOME) +@plugin.rule('.*') +def bot_events_connected(bot, trigger): + + # Handling for connection count + sb.events.dict["RPL_WELCOME_Count"] += 1 + if sb.events.dict["RPL_WELCOME_Count"] > 1: + sb.events.trigger(bot, sb.events.BOT_RECONNECTED, "Bot ReConnected to IRC") + else: + sb.events.trigger(bot, sb.events.BOT_WELCOME, "Welcome to the SpiceBot Events System") + + """For items tossed in a queue, this will trigger them accordingly""" + Thread(target=events_thread, args=(bot,)).start() + + +def events_thread(bot): + while True: + if len(sb.events.dict["trigger_queue"]): + pretriggerdict = sb.events.dict["trigger_queue"][0] + sb.events.dispatch(bot, pretriggerdict) + try: + del sb.events.dict["trigger_queue"][0] + except IndexError: + pass + + +@plugin.event(sb.events.BOT_WELCOME) +@plugin.rule('.*') +def bot_events_start(bot, trigger): + """This stage is redundant, but shows the system is working.""" + sb.events.trigger(bot, sb.events.BOT_READY, "Ready To Process module setup procedures") + + """Here, we wait until we are in at least one channel""" + while not len(list(bot.channels.keys())) > 0: + pass + sb.events.trigger(bot, sb.events.BOT_CONNECTED, "Bot Connected to IRC") + + +@sb.events.startup_check_ready() +@plugin.event(sb.events.BOT_READY) +@plugin.rule('.*') +def bot_events_startup_complete(bot, trigger): + """All events registered as required for startup have completed""" + sb.events.trigger(bot, sb.events.BOT_LOADED, "All registered modules setup procedures have completed") diff --git a/SpiceBot/SpiceBotCore/botsetup/welcome_setup.py b/SpiceBot/SpiceBotCore/botsetup/welcome_setup.py new file mode 100644 index 0000000..6cb68c6 --- /dev/null +++ b/SpiceBot/SpiceBotCore/botsetup/welcome_setup.py @@ -0,0 +1,20 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Events system. +""" +from sopel import plugin + +from SpiceBot import sb + + +@plugin.event("001") +@plugin.rule('.*') +def welcome_setup_start(bot, trigger): + sb.comms.ircbackend_initialize(bot) + + +@plugin.event(sb.events.BOT_CONNECTED) +@plugin.rule('.*') +def bot_events_start_set_hostmask(bot, trigger): + sb.comms.hostmask_set(bot) diff --git a/SpiceBot/__init__.py b/SpiceBot/__init__.py index 6f35965..d959974 100644 --- a/SpiceBot/__init__.py +++ b/SpiceBot/__init__.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import os import pathlib -from threading import Thread from sopel import plugin @@ -28,68 +27,3 @@ def sb_nickname_command(bot, trigger): bot.say("%s" % sb.versions.dict) sb.osd("test", trigger.sender) - - -@plugin.event("001") -@plugin.rule('.*') -def welcome_setup_start(bot, trigger): - sb.comms.ircbackend_initialize(bot) - - -@plugin.event(sb.events.BOT_CONNECTED) -@plugin.rule('.*') -def bot_events_start_set_hostmask(bot, trigger): - sb.comms.hostmask_set(bot) - - -@plugin.event(sb.events.BOT_WELCOME, sb.events.BOT_READY, sb.events.BOT_CONNECTED, sb.events.BOT_LOADED) -@plugin.rule('.*') -def bot_events_complete(bot, trigger): - """This is here simply to log to stderr that this was recieved.""" - sb.logger.info('SpiceBot_Events: %s' % trigger.args[1]) - - -@plugin.event(sb.events.RPL_WELCOME) -@plugin.rule('.*') -def bot_events_connected(bot, trigger): - - # Handling for connection count - sb.events.dict["RPL_WELCOME_Count"] += 1 - if sb.events.dict["RPL_WELCOME_Count"] > 1: - sb.events.trigger(bot, sb.events.BOT_RECONNECTED, "Bot ReConnected to IRC") - else: - sb.events.trigger(bot, sb.events.BOT_WELCOME, "Welcome to the SpiceBot Events System") - - """For items tossed in a queue, this will trigger them accordingly""" - Thread(target=events_thread, args=(bot,)).start() - - -def events_thread(bot): - while True: - if len(sb.events.dict["trigger_queue"]): - pretriggerdict = sb.events.dict["trigger_queue"][0] - sb.events.dispatch(bot, pretriggerdict) - try: - del sb.events.dict["trigger_queue"][0] - except IndexError: - pass - - -@plugin.event(sb.events.BOT_WELCOME) -@plugin.rule('.*') -def bot_events_start(bot, trigger): - """This stage is redundant, but shows the system is working.""" - sb.events.trigger(bot, sb.events.BOT_READY, "Ready To Process module setup procedures") - - """Here, we wait until we are in at least one channel""" - while not len(list(bot.channels.keys())) > 0: - pass - sb.events.trigger(bot, sb.events.BOT_CONNECTED, "Bot Connected to IRC") - - -@sb.events.startup_check_ready() -@plugin.event(sb.events.BOT_READY) -@plugin.rule('.*') -def bot_events_startup_complete(bot, trigger): - """All events registered as required for startup have completed""" - sb.events.trigger(bot, sb.events.BOT_LOADED, "All registered modules setup procedures have completed")