Remove Loadorder system and update logic for commandsquery

This commit is contained in:
deathbybandaid 2019-05-06 14:20:30 -04:00
parent 32e216e7a3
commit 999bfca80c
9 changed files with 20 additions and 172 deletions

View File

@ -6,7 +6,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
import sopel.module
from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import startup_bot_event, set_bot_event
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
from sopel_modules.SpiceBot_SBTools import (
@ -38,8 +37,6 @@ def setup(bot):
bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure")
bot_events_startup_register(bot, ['2001'])
startup_bot_event(bot, "SpiceBot_Channels")
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
if "SpiceBot_Channels" not in bot.memory:
@ -76,7 +73,6 @@ def trigger_channel_list_initial(bot, trigger):
channel_list_current(bot)
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.")
set_bot_event(bot, "SpiceBot_Channels")
bot_events_trigger(bot, 2001, "SpiceBot_Channels")
join_all_channels(bot)

View File

@ -7,7 +7,6 @@ import sopel.module
import os
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, startup_bot_event
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
from sopel_modules.SpiceBot_SBTools import bot_logging
@ -18,8 +17,6 @@ def setup(bot):
bot_logging(bot, 'SpiceBot_CommandsQuery', "Starting setup procedure")
bot_events_startup_register(bot, ['2002'])
startup_bot_event(bot, "SpiceBot_CommandsQuery")
if 'SpiceBot_CommandsQuery' not in bot.memory:
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
@ -115,32 +112,32 @@ def setup(bot):
validcomdict = {"comtype": comtype, "validcoms": validcoms}
filelinelist.append(validcomdict)
for atlinefound in filelinelist:
comtype = atlinefound["comtype"]
validcoms = atlinefound["validcoms"]
if len(filelinelist):
bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1
# default command to filename
if "validcoms" not in dict_from_file.keys():
dict_from_file["validcoms"] = validcoms
for atlinefound in filelinelist:
maincom = dict_from_file["validcoms"][0]
if len(dict_from_file["validcoms"]) > 1:
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
else:
comaliases = []
comtype = atlinefound["comtype"]
validcoms = atlinefound["validcoms"]
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
for comalias in comaliases:
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
# default command to filename
if "validcoms" not in dict_from_file.keys():
dict_from_file["validcoms"] = validcoms
maincom = dict_from_file["validcoms"][0]
if len(dict_from_file["validcoms"]) > 1:
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
else:
comaliases = []
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
for comalias in comaliases:
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
for comtype in ['module', 'nickname', 'rule']:
bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.")
set_bot_event(bot, "SpiceBot_CommandsQuery")
bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery")

View File

@ -5,7 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module
from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, startup_bot_event
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register
@ -54,8 +53,6 @@ def setup(bot):
bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure")
bot_events_startup_register(bot, ['2003'])
startup_bot_event(bot, "SpiceBot_GifSearch")
if 'SpiceBot_GifSearch' not in bot.memory:
bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}}
@ -83,7 +80,6 @@ def setup(bot):
for prefixcommand in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
commandsquery_register(bot, "prefix", prefixcommand)
set_bot_event(bot, "SpiceBot_GifSearch")
bot_events_trigger(bot, 2003, "SpiceBot_GifSearch")

View File

@ -1,25 +0,0 @@
# coding=utf-8
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
from .LoadOrder import check_bot_events, startup_bot_event, set_bot_event
from sopel_modules.SpiceBot_SBTools import bot_logging
import time
@sopel.module.event('001')
@sopel.module.rule('.*')
def bot_startup_connection(bot, trigger):
if check_bot_events(bot, ["startup_complete"]):
return
startup_bot_event(bot, "connected")
while not len(bot.channels.keys()) > 0:
pass
time.sleep(1)
set_bot_event(bot, "connected")
bot_logging(bot, 'Sopel_LoadOrder', "Connected to IRC")

View File

@ -1,70 +0,0 @@
# coding=utf8
"""Sopel_LoadOrder
Sopel LoadOrder is a poor mans way to create module load order dependencies
"""
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
from sopel_modules.SpiceBot_SBTools import bot_logging
import threading
def setup(bot):
bot_logging(bot, 'Sopel_LoadOrder', "Starting Module Events Logging")
threading.Thread(target=setup_thread, args=(bot,)).start()
def shutdown(bot):
if "Sopel_LoadOrder" in bot.memory:
del bot.memory["Sopel_LoadOrder"]
def setup_thread(bot):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
def list_bot_events(bot, list_type):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
return bot.memory["Sopel_LoadOrder"][list_type]
def check_bot_events(bot, listreq):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
if not isinstance(listreq, list):
listreq = [str(listreq)]
for requirement in listreq:
if requirement not in bot.memory["Sopel_LoadOrder"]["loaded"]:
return False
return True
def set_bot_event(bot, addonreq):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
if not isinstance(addonreq, list):
addonreq = [str(addonreq)]
bot.memory["Sopel_LoadOrder"]["loaded"].extend(addonreq)
def startup_bot_event(bot, addonreq):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
if not isinstance(addonreq, list):
addonreq = [str(addonreq)]
bot.memory["Sopel_LoadOrder"]["startup"].extend(addonreq)
def check_bot_startup(bot):
if "Sopel_LoadOrder" not in bot.memory:
bot.memory["Sopel_LoadOrder"] = {"loaded": [], "startup": []}
for startupitem in bot.memory["Sopel_LoadOrder"]["startup"]:
if startupitem not in bot.memory["Sopel_LoadOrder"]["loaded"]:
return False
return True

View File

@ -1,19 +0,0 @@
# coding=utf-8
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
from sopel_modules.SpiceBot_SBTools import bot_logging
from .LoadOrder import set_bot_event, check_bot_startup
@sopel.module.event('001')
@sopel.module.rule('.*')
def bot_startup_complete(bot, trigger):
while not check_bot_startup(bot):
pass
set_bot_event(bot, "startup_complete")
bot_logging(bot, 'Sopel_LoadOrder', "Module Events Logging Complete")

View File

@ -1,15 +0,0 @@
# coding=utf8
"""Sopel_LoadOrder
Sopel LoadOrder is a poor mans way to create module load order dependencies
"""
from __future__ import unicode_literals, absolute_import, division, print_function
from .LoadOrder import *
from .Connected import *
from .Startup_Complete import *
__author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net'
__version__ = '0.1.1'

View File

@ -7,7 +7,6 @@ from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_SBTools import bot_logging
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, startup_bot_event
def configure(config):
@ -25,25 +24,16 @@ def setup(bot):
bot_events_startup_register(bot, ['2004'])
startup_bot_event(bot, "SpiceBot_CommandsQuery")
bot_logs_setup_check(bot)
bot_events_trigger(bot, 2004, "SpiceBot_Logs")
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")
def shutdown(bot):
if "SpiceBot_Logs" in bot.memory:
del bot.memory["SpiceBot_Logs"]

View File

@ -5,7 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module
from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
import time
@ -63,5 +62,4 @@ def bot_startup_monologue_display(bot, trigger):
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")
bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys())
set_bot_event(bot, "SpiceBot_StartupMonologue")
bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue")