mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
a bunch of events changes
This commit is contained in:
parent
2cb5915ff9
commit
60de9616c8
@ -47,18 +47,22 @@ class BotEvents(object):
|
||||
return str(eventnumber)
|
||||
|
||||
def trigger(self, bot, number, message="SpiceBot_Events"):
|
||||
number = str(number)
|
||||
pretriggerdict = {"number": str(number), "message": message}
|
||||
if number in self.defaultevents or self.check(self.BOT_CONNECTED):
|
||||
pretrigger = sopel.trigger.PreTrigger(
|
||||
bot.nick,
|
||||
":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
self.recieved({"number": number, "message": message})
|
||||
self.dispatch(bot, pretriggerdict)
|
||||
else:
|
||||
pretriggerdict = {"number": number, "message": message}
|
||||
self.SpiceBot_Events["trigger_queue"].append(pretriggerdict)
|
||||
|
||||
def dispatch(self, bot, pretriggerdict):
|
||||
number = pretriggerdict["number"]
|
||||
message = pretriggerdict["message"]
|
||||
pretrigger = sopel.trigger.PreTrigger(
|
||||
bot.nick,
|
||||
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
self.recieved({"number": number, "message": message})
|
||||
|
||||
def recieved(self, trigger):
|
||||
if isinstance(trigger, dict):
|
||||
eventnumber = str(trigger["number"])
|
||||
|
||||
@ -36,14 +36,14 @@ def setup(bot):
|
||||
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.event(botevents.RPL_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def unkickable_bot(bot, trigger):
|
||||
if bot.config.SpiceBot_Channels.operadmin:
|
||||
bot.write(('SAMODE', bot.nick, '+q'))
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.event(botevents.RPL_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def request_channels_list_initial(bot, trigger):
|
||||
|
||||
|
||||
19
sopel_modules/SpiceBot_Events/Connected.py
Normal file
19
sopel_modules/SpiceBot_Events/Connected.py
Normal file
@ -0,0 +1,19 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_Connected(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")
|
||||
@ -1,79 +0,0 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.trigger import PreTrigger
|
||||
|
||||
from sopel_modules.SpiceBot.Logs import botlogs
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
import time
|
||||
|
||||
|
||||
def setup(bot):
|
||||
botlogs.log('SpiceBot_Events', "Starting setup procedure")
|
||||
|
||||
|
||||
@sopel.module.event(botevents.RPL_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
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")
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_start(bot, trigger):
|
||||
"""This stage is redundant, but shows the system is working."""
|
||||
botlogs.log('SpiceBot_Events', trigger.args[1], True)
|
||||
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()
|
||||
@sopel.module.event(botevents.BOT_READY)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_startup_complete(bot, trigger):
|
||||
"""All events registered as required for startup have completed"""
|
||||
botlogs.log('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.rule('.*')
|
||||
def bot_events_connected(bot, trigger):
|
||||
"""For items tossed in a queue, this will trigger them accordingly"""
|
||||
botlogs.log('SpiceBot_Events', trigger.args[1], True)
|
||||
|
||||
while True:
|
||||
if len(botevents.SpiceBot_Events["trigger_queue"]):
|
||||
number = botevents.SpiceBot_Events["trigger_queue"][0]["number"]
|
||||
message = botevents.SpiceBot_Events["trigger_queue"][0]["message"]
|
||||
pretrigger = PreTrigger(
|
||||
bot.nick,
|
||||
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
del botevents.SpiceBot_Events["trigger_queue"][0]
|
||||
botevents.recieved({"number": number, "message": message})
|
||||
else:
|
||||
if botevents.startup_check():
|
||||
return
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_LOADED)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_complete(bot, trigger):
|
||||
"""This is here simply to log to stderr that this was recieved."""
|
||||
botlogs.log('SpiceBot_Events', trigger.args[1], True)
|
||||
15
sopel_modules/SpiceBot_Events/Loaded.py
Normal file
15
sopel_modules/SpiceBot_Events/Loaded.py
Normal file
@ -0,0 +1,15 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
|
||||
@botevents.startup_check_ready()
|
||||
@sopel.module.event(botevents.BOT_READY)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_startup_complete(bot, trigger):
|
||||
"""All events registered as required for startup have completed"""
|
||||
botevents.trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed")
|
||||
15
sopel_modules/SpiceBot_Events/Logging.py
Normal file
15
sopel_modules/SpiceBot_Events/Logging.py
Normal file
@ -0,0 +1,15 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Logs import botlogs
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED, botevents.BOT_LOADED)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_complete(bot, trigger):
|
||||
"""This is here simply to log to stderr that this was recieved."""
|
||||
botlogs.log('SpiceBot_Events', trigger.args[1], True)
|
||||
19
sopel_modules/SpiceBot_Events/Queue.py
Normal file
19
sopel_modules/SpiceBot_Events/Queue.py
Normal file
@ -0,0 +1,19 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_CONNECTED)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_connected(bot, trigger):
|
||||
"""For items tossed in a queue, this will trigger them accordingly"""
|
||||
|
||||
while True:
|
||||
if len(botevents.SpiceBot_Events["trigger_queue"]):
|
||||
pretriggerdict = botevents.SpiceBot_Events["trigger_queue"][0]
|
||||
botevents.dispatch(pretriggerdict)
|
||||
del botevents.SpiceBot_Events["trigger_queue"][0]
|
||||
14
sopel_modules/SpiceBot_Events/Ready.py
Normal file
14
sopel_modules/SpiceBot_Events/Ready.py
Normal file
@ -0,0 +1,14 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
|
||||
@sopel.module.event(botevents.BOT_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_start(bot, trigger):
|
||||
"""This stage is redundant, but shows the system is working."""
|
||||
botevents.trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures")
|
||||
15
sopel_modules/SpiceBot_Events/Welcome.py
Normal file
15
sopel_modules/SpiceBot_Events/Welcome.py
Normal file
@ -0,0 +1,15 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot.Events import botevents
|
||||
|
||||
|
||||
@sopel.module.event(botevents.RPL_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
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")
|
||||
@ -1,7 +1,12 @@
|
||||
# coding=utf8
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .Events import *
|
||||
from .Welcome import *
|
||||
from .Ready import *
|
||||
from .Connected import *
|
||||
from .Loaded import *
|
||||
from .Queue import *
|
||||
from .Logging import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
|
||||
@ -15,7 +15,7 @@ def setup(bot):
|
||||
botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs")
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.event(botevents.RPL_WELCOME)
|
||||
@sopel.module.rule('.*')
|
||||
def join_log_channel(bot, trigger):
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import time
|
||||
def bot_startup_monologue_start(bot, trigger):
|
||||
|
||||
# Startup
|
||||
botlogs.log('SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration", True)
|
||||
botlogs.log('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')
|
||||
|
||||
botevents.trigger(bot, botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue")
|
||||
@ -45,6 +45,7 @@ def bot_startup_monologue_channels(bot, trigger):
|
||||
botcount = len(bot.channels.keys())
|
||||
servercount = len(botchannels.SpiceBot_Channels['list'].keys())
|
||||
bot.memory['SpiceBot_StartupMonologue'].append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
botlogs.log('SpiceBot_StartupMonologue', "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
|
||||
botevents.trigger(bot, botevents.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user