Update KICK, and prepare for another overhault of the event system

This commit is contained in:
deathbybandaid 2019-05-15 14:44:44 -04:00
parent 0269ad567d
commit 805e075e6c
2 changed files with 63 additions and 11 deletions

View File

@ -16,10 +16,20 @@ class BotEvents(object):
Events will be assigned a 4-digit number above 1000. Events will be assigned a 4-digit number above 1000.
This allows you to do, ``@module.event(botevents.BOT_WELCOME)```` This allows you to do, ``@module.event(botevents.BOT_WELCOME)````
Triggers handled by this module will be processed immediately.
Others will be placed into a queue.
Triggers will be logged by ID and content
""" """
def __init__(self): def __init__(self):
self.SpiceBot_Events = {"assigned_IDs": [1000]} self.SpiceBot_Events = {
"assigned_IDs": [1000],
"triggers_recieved": {},
"trigger_queue": [],
"startup_required": []
}
def __getattr__(self, name): def __getattr__(self, name):
''' will only get called for undefined attributes ''' ''' will only get called for undefined attributes '''
@ -28,6 +38,44 @@ class BotEvents(object):
setattr(self, name, str(eventnumber)) setattr(self, name, str(eventnumber))
return str(eventnumber) return str(eventnumber)
def trigger(self, number, message="SpiceBot_Events"):
number = str(number)
if number in [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED, self.BOT_LOADED]:
pretrigger = PreTrigger(
sopel.bot.nick,
":SpiceBot_Events " + number + " " + str(sopel.bot.nick) + " :" + message
)
sopel.bot.dispatch(pretrigger)
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 eventnumber not in self.SpiceBot_Events["triggers_recieved"]:
self.SpiceBot_Events["triggers_recieved"][eventnumber] = []
self.SpiceBot_Events["assigned_IDs"]["triggers_recieved"][eventnumber].append(message_payload)
def check(self, checklist):
if not isinstance(checklist, list):
checklist = [str(checklist)]
for number in checklist:
if str(number) not in self.SpiceBot_Events["triggers_recieved"].keys():
return False
return True
def startup_add(self, startlist):
if not isinstance(startlist, list):
startlist = [str(startlist)]
self.SpiceBot_Events["startup_required"].extend(startlist)
def startup_check(self):
for number in self.SpiceBot_Events["startup_required"]:
if str(number) not in self.SpiceBot_Events["triggers_recieved"].keys():
return False
return True
botevents = BotEvents() botevents = BotEvents()
@ -41,6 +89,12 @@ def register_trigger(number, message):
bot, trigger = args[0:2] bot, trigger = args[0:2]
return function(*args, **kwargs) return function(*args, **kwargs)
return _nop return _nop
ideas:
while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]):
pass
""" """

View File

@ -12,7 +12,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.bot import sopel.bot
from sopel import tools, module from sopel import tools, module
from sopel.tools import Identifier from sopel.tools import Identifier
from sopel.module import HALFOP
from sopel.config.types import StaticSection, ValidatedAttribute from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_SBTools import bot_logging from sopel_modules.SpiceBot_SBTools import bot_logging
@ -28,8 +27,8 @@ __version__ = '0.1.2'
def configure(config): def configure(config):
config.define_section("MAXTARGCONFIG_KICK", MAXTARGCONFIG_KICK, validate=False) config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
config.MAXTARGCONFIG_KICK.configure_setting('kick', 'MAXTARG limit for KICK') config.SpiceBot_Kick.configure_setting('kick', 'MAXTARG limit for KICK')
def setup(bot): def setup(bot):
@ -41,7 +40,7 @@ def setup(bot):
# verify config settings for server # verify config settings for server
bot_logging(bot, 'SpiceBot_Kick', "Checking for config settings") bot_logging(bot, 'SpiceBot_Kick', "Checking for config settings")
bot.config.define_section("MAXTARGCONFIG_KICK", MAXTARGCONFIG_KICK, validate=False) bot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
@module.event('005') @module.event('005')
@ -63,10 +62,10 @@ def parse_event_005(bot, trigger):
except IndexError: except IndexError:
value = None value = None
if value: if value:
bot.config.MAXTARGCONFIG_KICK.kick = int(value) bot.config.SpiceBot_Kick.kick = int(value)
class MAXTARGCONFIG_KICK(StaticSection): class SpiceBot_Kick(StaticSection):
kick = ValidatedAttribute('kick', default=1) kick = ValidatedAttribute('kick', default=1)
@ -80,7 +79,6 @@ class SopelKICK:
The bot must be a channel operator in specified channel for this to work. The bot must be a channel operator in specified channel for this to work.
.. versionadded:: 7.0 .. versionadded:: 7.0
""" """
if self.channels[channel].privileges[self.nick] < HALFOP:
self.write(['KICK', channel, nick], text) self.write(['KICK', channel, nick], text)
@ -89,9 +87,9 @@ class SopelWrapperKICK(object):
def kick(self, nick, channel=None, message=None): def kick(self, nick, channel=None, message=None):
if channel is None: if channel is None:
if self._trigger.is_privmsg: if self._trigger.is_privmsg:
return raise RuntimeError('Error: KICK requires a channel.')
else: else:
channel = self._trigger.sender channel = self._trigger.sender
if nick is None: if nick is None:
return raise RuntimeError('Error: KICK requires a nick.')
self._bot.kick(nick, channel, message) self._bot.kick(nick, channel, message)