mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
enhance events system
This commit is contained in:
parent
8f7a82a5d5
commit
4311d69520
@ -11,39 +11,45 @@ from sopel_modules.SpiceBot_SBTools import bot_logging
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event('001')
|
@sopel.module.event(botevents.RPL_WELCOME)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_startup_connection(bot, trigger):
|
def bot_startup_welcome(bot, trigger):
|
||||||
|
"""The Bot events system does not start until RPL_WELCOME 001 is recieved
|
||||||
|
from the server"""
|
||||||
botevents.trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System")
|
botevents.trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System")
|
||||||
while not len(bot.channels.keys()) > 0:
|
|
||||||
pass
|
|
||||||
time.sleep(1)
|
|
||||||
botevents.trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC")
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_WELCOME)
|
@sopel.module.event(botevents.BOT_WELCOME)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_events_start(bot, trigger):
|
def bot_events_start(bot, trigger):
|
||||||
|
"""This stage is redundant, but shows the system is working."""
|
||||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
||||||
botevents.trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures")
|
botevents.trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures")
|
||||||
|
|
||||||
|
|
||||||
|
@sopel.module.event(botevents.BOT_WELCOME)
|
||||||
|
@sopel.module.rule('.*')
|
||||||
|
def bot_startup_connection(bot, trigger):
|
||||||
|
"""Here, we wait until we are in at least one channel"""
|
||||||
|
while not len(bot.channels.keys()):
|
||||||
|
pass
|
||||||
|
time.sleep(1)
|
||||||
|
botevents.trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC")
|
||||||
|
|
||||||
|
|
||||||
@botevents.startup_check_ready()
|
@botevents.startup_check_ready()
|
||||||
@sopel.module.event(botevents.BOT_READY)
|
@sopel.module.event(botevents.BOT_READY)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_events_startup_complete(bot, trigger):
|
def bot_events_startup_complete(bot, trigger):
|
||||||
botevents.trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed")
|
"""All events registered as required for startup have completed"""
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_READY)
|
|
||||||
@sopel.module.rule('.*')
|
|
||||||
def bot_events_ready(bot, trigger):
|
|
||||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
||||||
|
botevents.trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed")
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_CONNECTED)
|
@sopel.module.event(botevents.BOT_CONNECTED)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_events_connected(bot, trigger):
|
def bot_events_connected(bot, trigger):
|
||||||
|
"""For items tossed in a queue, this will trigger then accordingly"""
|
||||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -57,9 +63,13 @@ def bot_events_connected(bot, trigger):
|
|||||||
bot.dispatch(pretrigger)
|
bot.dispatch(pretrigger)
|
||||||
del botevents.SpiceBot_Events["trigger_queue"][0]
|
del botevents.SpiceBot_Events["trigger_queue"][0]
|
||||||
botevents.recieved({"number": number, "message": message})
|
botevents.recieved({"number": number, "message": message})
|
||||||
|
else:
|
||||||
|
if botevents.startup_check():
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_LOADED)
|
@sopel.module.event(botevents.BOT_LOADED)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_events_complete(bot, trigger):
|
def bot_events_complete(bot, trigger):
|
||||||
|
"""This is here simply to log to stderr that this was recieved."""
|
||||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
|
||||||
|
|||||||
@ -24,11 +24,17 @@ class BotEvents(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.RPL_WELCOME = '001' # This is a defined IRC event
|
||||||
|
self.BOT_WELCOME = '1001'
|
||||||
|
self.BOT_READY = '1002'
|
||||||
|
self.BOT_CONNECTED = '1003'
|
||||||
|
self.BOT_LOADED = '1004'
|
||||||
|
self.defaultevents = [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED, self.BOT_LOADED]
|
||||||
self.SpiceBot_Events = {
|
self.SpiceBot_Events = {
|
||||||
"assigned_IDs": [1000],
|
"assigned_IDs": [1000, 1001, 1002, 1003, 1004],
|
||||||
"triggers_recieved": {},
|
"triggers_recieved": {},
|
||||||
"trigger_queue": [],
|
"trigger_queue": [],
|
||||||
"startup_required": []
|
"startup_required": [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED]
|
||||||
}
|
}
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
@ -40,7 +46,7 @@ class BotEvents(object):
|
|||||||
|
|
||||||
def trigger(self, bot, number, message="SpiceBot_Events"):
|
def trigger(self, bot, number, message="SpiceBot_Events"):
|
||||||
number = str(number)
|
number = str(number)
|
||||||
if number in [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED, self.BOT_LOADED]:
|
if number in self.defaultevents or self.check(self.BOT_CONNECTED):
|
||||||
pretrigger = PreTrigger(
|
pretrigger = PreTrigger(
|
||||||
bot.nick,
|
bot.nick,
|
||||||
":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message
|
":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message
|
||||||
@ -107,4 +113,3 @@ botevents = BotEvents()
|
|||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure")
|
bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure")
|
||||||
botevents.startup_add([botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED])
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user