mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
split events
This commit is contained in:
parent
8cfa4166d3
commit
6ab6d26331
@ -1,28 +1,27 @@
|
|||||||
#!/usr/bin/env python
|
# coding=utf-8
|
||||||
#coding=utf-8
|
|
||||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
|
||||||
|
|
||||||
# sopel imports
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
import sopel
|
|
||||||
|
|
||||||
|
import sopel.module
|
||||||
|
|
||||||
|
from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_check
|
||||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def configure(config):
|
@sopel.module.event('001')
|
||||||
pass
|
@sopel.module.rule('.*')
|
||||||
|
def bot_startup_connection(bot, trigger):
|
||||||
|
bot_events_trigger(bot, 1001, "Welcome to the SpiceBot Events System")
|
||||||
|
|
||||||
|
if bot_events_check(bot, '1004'):
|
||||||
|
return
|
||||||
|
|
||||||
def setup(bot):
|
while not len(bot.channels.keys()) > 0:
|
||||||
bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure.")
|
pass
|
||||||
bot_events_setup_check(bot)
|
time.sleep(1)
|
||||||
bot_events_startup_register(bot, ['1001', '1002', '1003', '1004'])
|
bot_events_trigger(bot, 1003, "Bot Connected to IRC")
|
||||||
|
|
||||||
|
|
||||||
def shutdown(bot):
|
|
||||||
if "SpiceBot_Events" in bot.memory:
|
|
||||||
del bot.memory["SpiceBot_Events"]
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event('1001')
|
@sopel.module.event('1001')
|
||||||
@ -55,78 +54,3 @@ def bot_events_connected(bot, trigger):
|
|||||||
def bot_events_monologue(bot, trigger):
|
def bot_events_monologue(bot, trigger):
|
||||||
bot_events_recieved(bot, trigger.event)
|
bot_events_recieved(bot, trigger.event)
|
||||||
bot.osd('SpiceBot_Events complete', bot.channels.keys())
|
bot.osd('SpiceBot_Events complete', bot.channels.keys())
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event('001')
|
|
||||||
@sopel.module.rule('.*')
|
|
||||||
def bot_startup_connection(bot, trigger):
|
|
||||||
bot_events_trigger(bot, 1001, "Welcome to the SpiceBot Events System")
|
|
||||||
|
|
||||||
if bot_events_check(bot, '1004'):
|
|
||||||
return
|
|
||||||
|
|
||||||
while not len(bot.channels.keys()) > 0:
|
|
||||||
pass
|
|
||||||
time.sleep(1)
|
|
||||||
bot_events_trigger(bot, 1003, "Bot Connected to IRC")
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_trigger(bot, number, message):
|
|
||||||
|
|
||||||
bot_events_setup_check(bot)
|
|
||||||
|
|
||||||
bot.memory["SpiceBot_Events"]["triggers"][str(number)] = message
|
|
||||||
|
|
||||||
pretrigger = sopel.trigger.PreTrigger(
|
|
||||||
bot.nick,
|
|
||||||
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
|
||||||
)
|
|
||||||
bot.dispatch(pretrigger)
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_setup_check(bot):
|
|
||||||
if "SpiceBot_Events" not in bot.memory:
|
|
||||||
bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": []}
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_check(bot, listreq):
|
|
||||||
|
|
||||||
bot_events_setup_check(bot)
|
|
||||||
|
|
||||||
if not isinstance(listreq, list):
|
|
||||||
listreq = [str(listreq)]
|
|
||||||
|
|
||||||
for requirement in listreq:
|
|
||||||
if requirement not in bot.memory["SpiceBot_Events"]["loaded"]:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_startup_register(bot, addonreq):
|
|
||||||
|
|
||||||
bot_events_setup_check(bot)
|
|
||||||
|
|
||||||
if not isinstance(addonreq, list):
|
|
||||||
addonreq = [str(addonreq)]
|
|
||||||
|
|
||||||
bot.memory["SpiceBot_Events"]["startup"].extend(addonreq)
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_recieved(bot, number):
|
|
||||||
|
|
||||||
bot_events_setup_check(bot)
|
|
||||||
|
|
||||||
if str(number) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
|
||||||
bot.memory["SpiceBot_Events"]["loaded"].append(str(number))
|
|
||||||
|
|
||||||
|
|
||||||
def bot_events_startup_check(bot):
|
|
||||||
|
|
||||||
bot_events_setup_check(bot)
|
|
||||||
|
|
||||||
for startupitem in bot.memory["SpiceBot_Events"]["startup"]:
|
|
||||||
if str(startupitem) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|||||||
84
sopel_modules/SpiceBot_Events/System.py
Normal file
84
sopel_modules/SpiceBot_Events/System.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#coding=utf-8
|
||||||
|
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||||
|
|
||||||
|
# sopel imports
|
||||||
|
import sopel
|
||||||
|
|
||||||
|
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||||
|
|
||||||
|
|
||||||
|
def configure(config):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure.")
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
bot_events_startup_register(bot, ['1001', '1002', '1003', '1004'])
|
||||||
|
|
||||||
|
|
||||||
|
def shutdown(bot):
|
||||||
|
if "SpiceBot_Events" in bot.memory:
|
||||||
|
del bot.memory["SpiceBot_Events"]
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_trigger(bot, number, message):
|
||||||
|
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
|
||||||
|
bot.memory["SpiceBot_Events"]["triggers"][str(number)] = message
|
||||||
|
|
||||||
|
pretrigger = sopel.trigger.PreTrigger(
|
||||||
|
bot.nick,
|
||||||
|
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
||||||
|
)
|
||||||
|
bot.dispatch(pretrigger)
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_setup_check(bot):
|
||||||
|
if "SpiceBot_Events" not in bot.memory:
|
||||||
|
bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": []}
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_check(bot, listreq):
|
||||||
|
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
|
||||||
|
if not isinstance(listreq, list):
|
||||||
|
listreq = [str(listreq)]
|
||||||
|
|
||||||
|
for requirement in listreq:
|
||||||
|
if requirement not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_startup_register(bot, addonreq):
|
||||||
|
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
|
||||||
|
if not isinstance(addonreq, list):
|
||||||
|
addonreq = [str(addonreq)]
|
||||||
|
|
||||||
|
bot.memory["SpiceBot_Events"]["startup"].extend(addonreq)
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_recieved(bot, number):
|
||||||
|
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
|
||||||
|
if str(number) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||||
|
bot.memory["SpiceBot_Events"]["loaded"].append(str(number))
|
||||||
|
|
||||||
|
|
||||||
|
def bot_events_startup_check(bot):
|
||||||
|
|
||||||
|
bot_events_setup_check(bot)
|
||||||
|
|
||||||
|
for startupitem in bot.memory["SpiceBot_Events"]["startup"]:
|
||||||
|
if str(startupitem) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
@ -1,6 +1,7 @@
|
|||||||
# coding=utf8
|
# coding=utf8
|
||||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
from .System import *
|
||||||
from .Events import *
|
from .Events import *
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user