hopefully last test of event system

This commit is contained in:
deathbybandaid 2019-05-05 22:21:03 -04:00
parent 072d4167ed
commit 152f059b46
10 changed files with 121 additions and 114 deletions

View File

@ -6,7 +6,7 @@ Sopel Commands Query responds to ? to display commands matching patterns
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
from .CommandsQuery import * from .CommandsQuery import *
from . QueryCommand import * from .QueryCommand import *
__author__ = 'Sam Zick' __author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net' __email__ = 'sam@deathbybandaid.net'

View File

@ -4,9 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module import sopel.module
import spicemanip from sopel_modules.SpiceBot_SBTools import github_dict
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, bot_privs, github_dict
@sopel.module.nickname_commands('help', 'docs', 'wiki') @sopel.module.nickname_commands('help', 'docs', 'wiki')

View File

@ -7,6 +7,7 @@ from sopel import module
from .gifsearch import getGif from .gifsearch import getGif
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs from sopel_modules.SpiceBot_SBTools import sopel_triggerargs
from sopel_modules.SpiceBot_Events.System import bot_events_check
import spicemanip import spicemanip
@ -14,7 +15,7 @@ import spicemanip
@module.commands('gif') @module.commands('gif')
def gif_trigger(bot, trigger): def gif_trigger(bot, trigger):
while "SpiceBot_GifSearch" not in bot.memory: while not bot_events_check(bot, '2003'):
pass pass
triggerargs, triggercommand = sopel_triggerargs(bot, trigger) triggerargs, triggercommand = sopel_triggerargs(bot, trigger)

View File

@ -9,12 +9,13 @@ import sopel.module
import spicemanip import spicemanip
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs from sopel_modules.SpiceBot_SBTools import sopel_triggerargs
from sopel_modules.SpiceBot_Events.System import bot_events_check
@sopel.module.commands('(.*)') @sopel.module.commands('(.*)')
def gifapi_triggers(bot, trigger): def gifapi_triggers(bot, trigger):
while "SpiceBot_GifSearch" not in bot.memory: while not bot_events_check(bot, '2003'):
pass pass
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command')

View File

@ -6,10 +6,11 @@ import sopel.module
from sopel.config.types import StaticSection, ValidatedAttribute from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, startup_bot_event 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 from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register
from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs, bot_logging from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, bot_logging
import spicemanip import spicemanip
@ -19,7 +20,6 @@ import requests
import json import json
from fake_useragent import UserAgent from fake_useragent import UserAgent
import random import random
import threading
# user agent and header # user agent and header
ua = UserAgent() ua = UserAgent()
@ -51,18 +51,8 @@ def configure(config):
def setup(bot): def setup(bot):
bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure") bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure")
bot_events_startup_register(bot, ['2003'])
threading.Thread(target=setup_thread, args=(bot,)).start()
def shutdown(bot):
if "SpiceBot_GifSearch" in bot.memory:
del bot.memory["SpiceBot_GifSearch"]
def setup_thread(bot):
startup_bot_event(bot, "SpiceBot_GifSearch") startup_bot_event(bot, "SpiceBot_GifSearch")
@ -94,24 +84,12 @@ def setup_thread(bot):
commandsquery_register(bot, "prefix", prefixcommand) commandsquery_register(bot, "prefix", prefixcommand)
set_bot_event(bot, "SpiceBot_GifSearch") set_bot_event(bot, "SpiceBot_GifSearch")
bot_events_trigger(bot, 2003, "SpiceBot_GifSearch")
@sopel.module.commands('gif') def shutdown(bot):
def gif_trigger(bot, trigger): if "SpiceBot_GifSearch" in bot.memory:
triggerargs, triggercommand = sopel_triggerargs(bot, trigger) del bot.memory["SpiceBot_GifSearch"]
if triggerargs == []:
return bot.osd("Please present a query to search.")
query = spicemanip.main(trigger.args[1], 0)
searchapis = bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys()
searchdict = {"query": query, "gifsearch": searchapis}
gifdict = getGif(bot, searchdict)
if gifdict["error"]:
bot.osd(gifdict["error"])
else:
bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"])))
def getGif(bot, searchdict): def getGif(bot, searchdict):
@ -273,3 +251,9 @@ def getGif(bot, searchdict):
# return dict # return dict
gifdict['error'] = None gifdict['error'] = None
return gifdict return gifdict
@sopel.module.event('2003')
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
bot_events_recieved(bot, trigger.event)

View File

@ -3,12 +3,13 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute from sopel.config.types import StaticSection, ValidatedAttribute
import spicemanip import spicemanip
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, bot_logging from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, 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): def configure(config):
@ -23,21 +24,24 @@ class SpiceBot_Logs_MainSection(StaticSection):
def setup(bot): def setup(bot):
bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure") bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure")
bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False)
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {}
if 'SpiceBot_Logs_queue' not in bot.memory: bot_events_startup_register(bot, ['2004'])
bot.memory['SpiceBot_Logs_queue'] = []
startup_bot_event(bot, "SpiceBot_CommandsQuery")
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
set_bot_event(bot, "SpiceBot_Logs")
bot_events_trigger(bot, 2004, "SpiceBot_Logs")
def shutdown(bot): def shutdown(bot):
if "SpiceBot_Logs" in bot.memory: if "SpiceBot_Logs" in bot.memory:
del bot.memory["SpiceBot_Logs"] del bot.memory["SpiceBot_Logs"]
if "SpiceBot_Logs_queue" in bot.memory:
del bot.memory["SpiceBot_Logs_queue"]
@sopel.module.event('001') @sopel.module.event('1004')
@sopel.module.rule('.*') @sopel.module.rule('.*')
def join_log_channel(bot, trigger): def join_log_channel(bot, trigger):
if bot.config.SpiceBot_Logs.logging_channel: if bot.config.SpiceBot_Logs.logging_channel:
@ -47,35 +51,16 @@ def join_log_channel(bot, trigger):
if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin: if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin:
bot.write(('SAJOIN', bot.nick, channel)) bot.write(('SAJOIN', bot.nick, channel))
if 'SpiceBot_Logs_queue' not in bot.memory: if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs_queue'] = [] bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
while 'SpiceBot_Logs_queue' in bot.memory: while 'SpiceBot_Logs' in bot.memory:
if len(bot.memory['SpiceBot_Logs_queue']): if len(bot.memory['SpiceBot_Logs']["queue"]):
bot.say(str(bot.memory['SpiceBot_Logs_queue'][0]), channel) bot.say(str(bot.memory['SpiceBot_Logs']["queue"][0]), channel)
del bot.memory['SpiceBot_Logs_queue'][0] del bot.memory['SpiceBot_Logs']["queue"][0]
@sopel.module.nickname_commands('logs') @sopel.module.event('2004')
def bot_command_action(bot, trigger): @sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
if not command_permissions_check(bot, trigger, ['admins', 'owner']): bot_events_recieved(bot, trigger.event)
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
return
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
logtype = spicemanip.main(triggerargs, 1) or None
if not logtype or not inlist(bot, logtype, bot.memory['SpiceBot_Logs'].keys()):
bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs'].keys(), 'andlist'), trigger.sender, 'action')
return
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
if len(bot.memory['SpiceBot_Logs'][logtype]) == 0:
bot.osd("No logs found for " + str(logtype) + ".")
return
bot.osd("Is Examining " + str(logtype) + " log(s).")
for line in bot.memory['SpiceBot_Logs'][logtype]:
bot.osd(" " + str(line))

View File

@ -0,0 +1,38 @@
# coding=utf-8
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
import spicemanip
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
from sopel_modules.SpiceBot_Events.System import bot_events_check
@sopel.module.nickname_commands('logs')
def bot_command_action(bot, trigger):
while not bot_events_check(bot, '2004'):
pass
if not command_permissions_check(bot, trigger, ['admins', 'owner']):
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
return
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
logtype = spicemanip.main(triggerargs, 1) or None
if not logtype or not inlist(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()):
bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs']["logs"].keys(), 'andlist'), trigger.sender, 'action')
return
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) == 0:
bot.osd("No logs found for " + str(logtype) + ".")
return
bot.osd("Is Examining " + str(logtype) + " log(s).")
for line in bot.memory['SpiceBot_Logs']["logs"][logtype]:
bot.osd(" " + str(line))

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
from .Logs import * from .Logs import *
from .Logs_Command import *
__author__ = 'Sam Zick' __author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net' __email__ = 'sam@deathbybandaid.net'

View File

@ -95,24 +95,21 @@ def command_permissions_check(bot, trigger, privslist):
def bot_logging(bot, logtype, logentry): def bot_logging(bot, logtype, logentry):
if 'SpiceBot_Logs_queue' not in bot.memory: if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs_queue'] = [] bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
logmessage = "[" + logtype + "] " + logentry + "" logmessage = "[" + logtype + "] " + logentry + ""
bot.memory['SpiceBot_Logs_queue'].append(logmessage) bot.memory['SpiceBot_Logs']["queue"].append(logmessage)
stderr("\n" + logmessage + "\n") stderr("\n" + logmessage + "\n")
if 'SpiceBot_Logs' not in bot.memory: if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys():
bot.memory['SpiceBot_Logs'] = {} bot.memory['SpiceBot_Logs']["logs"][logtype] = []
if logtype not in bot.memory['SpiceBot_Logs'].keys(): bot.memory['SpiceBot_Logs']["logs"][logtype].append(logentry)
bot.memory['SpiceBot_Logs'][logtype] = [] if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) > 10:
del bot.memory['SpiceBot_Logs']["logs"][logtype][0]
bot.memory['SpiceBot_Logs'][logtype].append(logentry)
if len(bot.memory['SpiceBot_Logs'][logtype]) > 10:
del bot.memory['SpiceBot_Logs'][logtype][0]
""" """

View File

@ -2,38 +2,36 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
from sopel import module import sopel.module
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, check_bot_events
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
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
import time import time
@module.event('001') def setup(bot):
@module.rule('.*') bot_logging(bot, 'SpiceBot_StartupMonologue', "Starting setup procedure")
@module.thread(True) bot_events_startup_register(bot, ['2005'])
def bot_startup_monologue(bot, trigger):
while not check_bot_events(bot, ["connected"]): if 'SpiceBot_StartupMonologue' not in bot.memory:
pass bot.memory['SpiceBot_StartupMonologue'] = []
if check_bot_events(bot, ["SpiceBot_StartupMonologue"]):
startup_reconnect(bot, trigger)
else:
startup_fresh(bot, trigger)
def startup_fresh(bot, trigger): @sopel.module.event('1003')
@sopel.module.rule('.*')
def bot_startup_monologue_start(bot, trigger):
# Startup # Startup
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration") bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration")
bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION') bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION')
startupcomplete = [bot.nick + " startup complete"] bot.memory['SpiceBot_StartupMonologue'].append(bot.nick + " startup complete")
while not check_bot_events(bot, ["SpiceBot_CommandsQuery"]):
pass @sopel.module.event('2002')
@sopel.module.rule('.*')
def bot_startup_monologue_commands(bot, trigger):
availablecomsnum, availablecomsfiles = 0, 0 availablecomsnum, availablecomsfiles = 0, 0
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
@ -41,31 +39,35 @@ def startup_fresh(bot, trigger):
for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype] availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
startupcomplete.append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
while not check_bot_events(bot, ["SpiceBot_Channels"]):
pass @sopel.module.event('2001')
@sopel.module.rule('.*')
def bot_startup_monologue_channels(bot, trigger):
botcount = len(bot.channels.keys()) botcount = len(bot.channels.keys())
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
startupcomplete.append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") bot.memory['SpiceBot_StartupMonologue'].append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
while not check_bot_events(bot, ["startup_complete"]):
pass @sopel.module.event('1004')
@sopel.module.rule('.*')
def bot_startup_monologue_display(bot, trigger):
timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])
startupcomplete.append("Startup took " + timesince) bot.memory['SpiceBot_StartupMonologue'].append("Startup took " + timesince)
# Announce to chan, then handle some closing stuff # Announce to chan, then handle some closing stuff
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete") bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")
bot.osd(startupcomplete, bot.channels.keys()) bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys())
set_bot_event(bot, "SpiceBot_StartupMonologue") set_bot_event(bot, "SpiceBot_StartupMonologue")
bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue")
def startup_reconnect(bot, trigger): @sopel.module.event('2005')
@sopel.module.rule('.*')
# Startup def bot_events_setup(bot, trigger):
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " has reconnected.") bot_events_recieved(bot, trigger.event)
bot.osd(" has reconnected.", bot.channels.keys(), 'ACTION')