Trigger Queue

This commit is contained in:
deathbybandaid 2019-05-06 09:43:10 -04:00
parent 2d8c1e5ff0
commit 1b019eab42
5 changed files with 28 additions and 23 deletions

View File

@ -23,17 +23,6 @@ def setup(bot):
if 'SpiceBot_CommandsQuery' not in bot.memory:
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
def shutdown(bot):
if "SpiceBot_CommandsQuery" in bot.memory:
del bot.memory["SpiceBot_CommandsQuery"]
@sopel.module.event('1003')
@sopel.module.rule('.*')
def trigger_command_list_initial(bot, trigger):
bot_events_recieved(bot, trigger.event)
for comtype in ['module', 'nickname', 'rule']:
if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] = 0
@ -155,6 +144,11 @@ def trigger_command_list_initial(bot, trigger):
bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery")
def shutdown(bot):
if "SpiceBot_CommandsQuery" in bot.memory:
del bot.memory["SpiceBot_CommandsQuery"]
@sopel.module.event('1004')
@sopel.module.rule('.*')
def bot_events_complete(bot, trigger):

View File

@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module
from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_check
from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_check, bot_events_setup_check
from sopel_modules.SpiceBot_SBTools import bot_logging
import time
@ -50,6 +50,13 @@ def bot_events_connected(bot, trigger):
bot_logging(bot, 'SpiceBot_Events', trigger.args[1])
bot_events_recieved(bot, trigger.event)
bot_events_setup_check(bot)
while 'SpiceBot_Events' in bot.memory:
if len(bot.memory['SpiceBot_Events']["queue"]):
bot.dispatch(bot.memory['SpiceBot_Events']["queue"][0])
del bot.memory['SpiceBot_Events']["queue"][0]
@sopel.module.event('1004')
@sopel.module.rule('.*')

View File

@ -29,12 +29,12 @@ def bot_events_trigger(bot, number, message):
bot.nick,
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
)
bot.dispatch(pretrigger)
bot.memory['SpiceBot_Events']["queue"].append(pretrigger)
def bot_events_setup_check(bot):
if "SpiceBot_Events" not in bot.memory:
bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": []}
bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": []}
def bot_events_check(bot, listreq):

View File

@ -59,12 +59,6 @@ def setup(bot):
if 'SpiceBot_GifSearch' not in bot.memory:
bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}}
@sopel.module.event('1003')
@sopel.module.rule('.*')
def bot_startup_gifsearch_complete(bot, trigger):
bot_events_recieved(bot, trigger.event)
dir_to_scan = []
moduledir = os.path.dirname(os.path.abspath(__file__))
@ -239,6 +233,7 @@ def getGif(bot, searchdict):
try:
gifpage = requests.get(gifdict["returnurl"], headers=None)
except Exception as e:
gifpage = str(e)
gifpage = None
if gifpage and not str(gifpage.status_code).startswith(tuple(["4", "5"])):

View File

@ -27,9 +27,19 @@ def setup(bot):
startup_bot_event(bot, "SpiceBot_CommandsQuery")
bot_logs_setup_check(bot)
def bot_logs_setup_check(bot):
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
@sopel.module.event('1003')
@sopel.module.rule('.*')
def bot_startup_logs_complete(bot, trigger):
bot_events_recieved(bot, trigger.event)
set_bot_event(bot, "SpiceBot_Logs")
bot_events_trigger(bot, 2004, "SpiceBot_Logs")
@ -39,7 +49,7 @@ def shutdown(bot):
del bot.memory["SpiceBot_Logs"]
@sopel.module.event('1004')
@sopel.module.event('1003')
@sopel.module.rule('.*')
def join_log_channel(bot, trigger):
bot_events_recieved(bot, trigger.event)
@ -51,8 +61,7 @@ def join_log_channel(bot, trigger):
if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin:
bot.write(('SAJOIN', bot.nick, channel))
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
bot_logs_setup_check(bot)
while 'SpiceBot_Logs' in bot.memory:
if len(bot.memory['SpiceBot_Logs']["queue"]):