Change how specific events assure their hooks gets the event independant of

loading order
This commit is contained in:
jesopo 2018-08-28 14:55:08 +01:00
parent ef16817ad5
commit b699c120a0
7 changed files with 26 additions and 20 deletions

View file

@ -53,6 +53,9 @@ class EventHook(object):
self._call_notify = None
self._stored_events = []
def _make_event(self, kwargs):
return Event(self.bot, self.name, **kwargs)
def _get_path(self):
path = [self.name]
parent = self.parent
@ -69,8 +72,8 @@ class EventHook(object):
self._hooks.sort(key=lambda x: x.priority)
if replay:
for event in self._stored_events:
callback.call(event)
for kwargs in self._stored_events:
callback.call(self._make_event(kwargs))
self._stored_events = None
def _unhook(self, hook):
@ -95,17 +98,20 @@ class EventHook(object):
def call_for_result(self, default=None, max=None, **kwargs):
results = self.call(max=max, **kwargs)
return default if not len(results) else results[0]
def assure_call(self, **kwargs):
if not self._stored_events == None:
self._stored_events.append(kwargs)
else:
self.call(kwargs)
def call(self, max=None, **kwargs):
self.bot.log.debug("calling event: \"%s\" (params: %s)",
[self._get_path(), kwargs])
start = time.monotonic()
event = Event(self.bot, self.name, **kwargs)
event = self._make_event(kwargs)
if self._call_notify:
self._call_notify(self, event)
if not self._stored_events == None:
self._stored_events.append(event)
called = 0
returns = []
for hook in self._hooks:

View file

@ -5,7 +5,7 @@ class Module(object):
self.bot = bot
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="automode",
"channelset").assure_call(setting="automode",
help="Disable/Enable automode",
validate=Utils.bool_or_none)

View file

@ -32,19 +32,19 @@ class Module(object):
bot.events.on("received").on("message").on("channel").hook(self.highlight_spam)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="highlight-spam-threshold",
help="Set the number of nicknames in a message that qualifies as spam",
validate=Utils.int_or_none)
"channelset").assure_call(setting="highlight-spam-threshold",
help="Set the number of nicknames in a message that "
"qualifies as spam", validate=Utils.int_or_none)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="highlight-spam-protection",
"channelset").assure_call(setting="highlight-spam-protection",
help="Enable/Disable highlight spam protection",
validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="highlight-spam-ban",
help="Enable/Disable banning highlight spammers instead of just kicking",
validate=Utils.bool_or_none)
"channelset").assure_call(setting="highlight-spam-ban",
help="Enable/Disable banning highlight spammers "
"instead of just kicking", validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="ban-format",
"channelset").assure_call(setting="ban-format",
help="Set ban format ($n = nick, $u = username, $h = hostname)")
def kick(self, event):

View file

@ -60,7 +60,7 @@ class Module(object):
help="Get more output from the last command", skip_out=True)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="command-prefix",
"channelset").assure_call(setting="command-prefix",
help="Set the command prefix used in this channel")
bot.events.on("new").on("user", "channel").hook(self.new)

View file

@ -19,7 +19,7 @@ class Module(object):
usage="<target>")
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="karma-verbose",
"channelset").assure_call(setting="karma-verbose",
help="Disable/Enable automatically responding to karma changes",
validate=Utils.bool_or_none)

View file

@ -11,12 +11,12 @@ class Module(object):
self.channel_message)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="sed",
"channelset").assure_call(setting="sed",
help="Disable/Enable sed in a channel",
validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="sed-sender-only",
help=
"channelset").assure_call(setting="sed-sender-only",
replayable=True, help=
"Disable/Enable sed only looking at the messages sent by the user",
validate=Utils.bool_or_none)

View file

@ -26,7 +26,7 @@ class Module(object):
self.channel_message)
bot.events.on("postboot").on("configure").on(
"channelset").call(setting="auto-youtube",
"channelset").assure_call(setting="auto-youtube",
help="Disable/Enable automatically getting info from youtube URLs",
validate=Utils.bool_or_none)