triggers are self recieved

This commit is contained in:
deathbybandaid 2019-05-16 15:12:19 -04:00
parent 94dd65136f
commit 8f7a82a5d5
10 changed files with 16 additions and 65 deletions

View File

@ -61,7 +61,6 @@ def shutdown(bot):
@sopel.module.event(botevents.BOT_CONNECTED)
@sopel.module.rule('.*')
def trigger_channel_list_initial(bot, trigger):
botevents.recieved(trigger)
# Unkickable
bot.write(('SAMODE', bot.nick, '+q'))
@ -132,9 +131,3 @@ def bot_part_empty(bot):
bot.part(channel, "Leaving Empty Channel")
if channel.lower() in bot.memory['SpiceBot_Channels']['channels']:
del bot.memory['SpiceBot_Channels']['channels'][channel.lower()]
@sopel.module.event(botevents.BOT_CHANNELS)
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
botevents.recieved(trigger)

View File

@ -173,7 +173,6 @@ def shutdown(bot):
@sopel.module.event(botevents.BOT_LOADED)
@sopel.module.rule('.*')
def bot_events_complete(bot, trigger):
botevents.recieved(trigger)
for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
if comtype not in ['module', 'nickname', 'rule']:
@ -212,9 +211,3 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
for comalias in comaliases:
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys():
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor}
@sopel.module.event(botevents.BOT_COMMANDSQUERY)
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
botevents.recieved(trigger)

View File

@ -11,7 +11,7 @@ from sopel_modules.SpiceBot_SBTools import bot_logging
import time
@botevents.event('001')
@sopel.module.event('001')
@sopel.module.rule('.*')
def bot_startup_connection(bot, trigger):
botevents.trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System")
@ -21,33 +21,31 @@ def bot_startup_connection(bot, trigger):
botevents.trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC")
@botevents.event(botevents.BOT_WELCOME)
@sopel.module.event(botevents.BOT_WELCOME)
@sopel.module.rule('.*')
def bot_events_start(bot, trigger):
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
botevents.recieved(trigger)
botevents.trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures")
@botevents.startup_check_ready()
@botevents.event(botevents.BOT_READY)
@sopel.module.event(botevents.BOT_READY)
@sopel.module.rule('.*')
def bot_events_startup_complete(bot, trigger):
botevents.trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed")
@botevents.event(botevents.BOT_READY)
@sopel.module.event(botevents.BOT_READY)
@sopel.module.rule('.*')
def bot_events_ready(bot, trigger):
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
botevents.recieved(trigger)
@botevents.event(botevents.BOT_CONNECTED)
@sopel.module.event(botevents.BOT_CONNECTED)
@sopel.module.rule('.*')
def bot_events_connected(bot, trigger):
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
botevents.recieved(trigger)
while True:
if len(botevents.SpiceBot_Events["trigger_queue"]):
number = botevents.SpiceBot_Events["trigger_queue"][0]["number"]
@ -58,10 +56,10 @@ def bot_events_connected(bot, trigger):
)
bot.dispatch(pretrigger)
del botevents.SpiceBot_Events["trigger_queue"][0]
botevents.recieved({"number": number, "message": message})
@botevents.event(botevents.BOT_LOADED)
@sopel.module.event(botevents.BOT_LOADED)
@sopel.module.rule('.*')
def bot_events_complete(bot, trigger):
bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True)
botevents.recieved(trigger)

View File

@ -46,16 +46,21 @@ class BotEvents(object):
":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message
)
bot.dispatch(pretrigger)
self.recieved({"number": number, "message": message})
else:
pretriggerdict = {"number": number, "message": message}
self.SpiceBot_Events["trigger_queue"].append(pretriggerdict)
def recieved(self, trigger):
eventnumber = str(trigger.event)
message_payload = trigger.args[1]
if isinstance(trigger, dict):
eventnumber = str(trigger["number"])
message = str(trigger["message"])
else:
eventnumber = str(trigger.event)
message = trigger.args[1]
if eventnumber not in self.SpiceBot_Events["triggers_recieved"]:
self.SpiceBot_Events["triggers_recieved"][eventnumber] = []
self.SpiceBot_Events["triggers_recieved"][eventnumber].append(message_payload)
self.SpiceBot_Events["triggers_recieved"][eventnumber].append(message)
def check(self, checklist):
if not isinstance(checklist, list):
@ -96,18 +101,6 @@ class BotEvents(object):
return _nop
return actual_decorator
def event(self, *event_list):
def actual_decorator(function):
@functools.wraps(function)
def add_attribute(function):
if not hasattr(function, "event"):
function.event = []
function.event.extend(event_list)
self.recieved(function)
return function
return add_attribute
return actual_decorator
botevents = BotEvents()

View File

@ -249,9 +249,3 @@ def getGif(bot, searchdict):
# return dict
gifdict['error'] = None
return gifdict
@sopel.module.event(botevents.BOT_GIFSEARCH)
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
botevents.recieved(trigger)

View File

@ -21,8 +21,6 @@ def shutdown(bot):
@sopel.module.event(botevents.BOT_LOADED)
@sopel.module.rule('.*')
def bot_events_complete(bot, trigger):
botevents.recieved(trigger)
for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())

View File

@ -12,7 +12,6 @@ from .Logs import stdio_logs_fetch
@sopel.module.event(botevents.BOT_STARTUPMONOLOGUE)
@sopel.module.rule('.*')
def bot_startup_monologue_start(bot, trigger):
botevents.recieved(trigger)
debuglines = stdio_logs_fetch(bot)

View File

@ -46,7 +46,6 @@ def shutdown(bot):
@sopel.module.event(botevents.BOT_CONNECTED)
@sopel.module.rule('.*')
def join_log_channel(bot, trigger):
botevents.recieved(trigger)
if bot.config.SpiceBot_Logs.logging_channel:
channel = bot.config.SpiceBot_Logs.logging_channel
@ -129,9 +128,3 @@ def get_running_pid(bot):
pidnum = e
pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
return pidnum
@sopel.module.event(botevents.BOT_LOGS)
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
botevents.recieved(trigger)

View File

@ -14,9 +14,3 @@ def setup(bot):
if 'SpiceBot_StartupMonologue' not in bot.memory:
bot.memory['SpiceBot_StartupMonologue'] = []
@sopel.module.event(botevents.BOT_STARTUPMONOLOGUE, botevents.BOT_STARTUPMONOLOGUE_CHANNELS, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, botevents.BOT_STARTUPMONOLOGUE_CONNECTED)
@sopel.module.rule('.*')
def bot_events_setup(bot, trigger):
botevents.recieved(trigger)

View File

@ -13,7 +13,6 @@ import time
@sopel.module.event(botevents.BOT_CONNECTED)
@sopel.module.rule('.*')
def bot_startup_monologue_start(bot, trigger):
botevents.recieved(trigger)
# Startup
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration")
@ -25,7 +24,6 @@ def bot_startup_monologue_start(bot, trigger):
@sopel.module.event(botevents.BOT_COMMANDSQUERY)
@sopel.module.rule('.*')
def bot_startup_monologue_commands(bot, trigger):
botevents.recieved(trigger)
availablecomsnum, availablecomsfiles = 0, 0
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
@ -41,7 +39,6 @@ def bot_startup_monologue_commands(bot, trigger):
@sopel.module.event(botevents.BOT_CHANNELS)
@sopel.module.rule('.*')
def bot_startup_monologue_channels(bot, trigger):
botevents.recieved(trigger)
botcount = len(bot.channels.keys())
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
@ -53,7 +50,6 @@ def bot_startup_monologue_channels(bot, trigger):
@sopel.module.event(botevents.BOT_LOADED)
@sopel.module.rule('.*')
def bot_startup_monologue_display(bot, trigger):
botevents.recieved(trigger)
timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])
bot.memory['SpiceBot_StartupMonologue'].append("Startup took " + timesince)