Change how specific events assure their hooks gets the event independant of
loading order
This commit is contained in:
parent
ef16817ad5
commit
b699c120a0
7 changed files with 26 additions and 20 deletions
|
@ -53,6 +53,9 @@ class EventHook(object):
|
||||||
self._call_notify = None
|
self._call_notify = None
|
||||||
self._stored_events = []
|
self._stored_events = []
|
||||||
|
|
||||||
|
def _make_event(self, kwargs):
|
||||||
|
return Event(self.bot, self.name, **kwargs)
|
||||||
|
|
||||||
def _get_path(self):
|
def _get_path(self):
|
||||||
path = [self.name]
|
path = [self.name]
|
||||||
parent = self.parent
|
parent = self.parent
|
||||||
|
@ -69,8 +72,8 @@ class EventHook(object):
|
||||||
self._hooks.sort(key=lambda x: x.priority)
|
self._hooks.sort(key=lambda x: x.priority)
|
||||||
|
|
||||||
if replay:
|
if replay:
|
||||||
for event in self._stored_events:
|
for kwargs in self._stored_events:
|
||||||
callback.call(event)
|
callback.call(self._make_event(kwargs))
|
||||||
self._stored_events = None
|
self._stored_events = None
|
||||||
|
|
||||||
def _unhook(self, hook):
|
def _unhook(self, hook):
|
||||||
|
@ -95,17 +98,20 @@ class EventHook(object):
|
||||||
def call_for_result(self, default=None, max=None, **kwargs):
|
def call_for_result(self, default=None, max=None, **kwargs):
|
||||||
results = self.call(max=max, **kwargs)
|
results = self.call(max=max, **kwargs)
|
||||||
return default if not len(results) else results[0]
|
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):
|
def call(self, max=None, **kwargs):
|
||||||
self.bot.log.debug("calling event: \"%s\" (params: %s)",
|
self.bot.log.debug("calling event: \"%s\" (params: %s)",
|
||||||
[self._get_path(), kwargs])
|
[self._get_path(), kwargs])
|
||||||
start = time.monotonic()
|
start = time.monotonic()
|
||||||
|
|
||||||
event = Event(self.bot, self.name, **kwargs)
|
event = self._make_event(kwargs)
|
||||||
if self._call_notify:
|
if self._call_notify:
|
||||||
self._call_notify(self, event)
|
self._call_notify(self, event)
|
||||||
|
|
||||||
if not self._stored_events == None:
|
|
||||||
self._stored_events.append(event)
|
|
||||||
called = 0
|
called = 0
|
||||||
returns = []
|
returns = []
|
||||||
for hook in self._hooks:
|
for hook in self._hooks:
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Module(object):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
bot.events.on("postboot").on("configure").on(
|
||||||
"channelset").call(setting="automode",
|
"channelset").assure_call(setting="automode",
|
||||||
help="Disable/Enable automode",
|
help="Disable/Enable automode",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
|
|
||||||
|
|
|
@ -32,19 +32,19 @@ class Module(object):
|
||||||
bot.events.on("received").on("message").on("channel").hook(self.highlight_spam)
|
bot.events.on("received").on("message").on("channel").hook(self.highlight_spam)
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
bot.events.on("postboot").on("configure").on(
|
||||||
"channelset").call(setting="highlight-spam-threshold",
|
"channelset").assure_call(setting="highlight-spam-threshold",
|
||||||
help="Set the number of nicknames in a message that qualifies as spam",
|
help="Set the number of nicknames in a message that "
|
||||||
validate=Utils.int_or_none)
|
"qualifies as spam", validate=Utils.int_or_none)
|
||||||
bot.events.on("postboot").on("configure").on(
|
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",
|
help="Enable/Disable highlight spam protection",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
bot.events.on("postboot").on("configure").on(
|
bot.events.on("postboot").on("configure").on(
|
||||||
"channelset").call(setting="highlight-spam-ban",
|
"channelset").assure_call(setting="highlight-spam-ban",
|
||||||
help="Enable/Disable banning highlight spammers instead of just kicking",
|
help="Enable/Disable banning highlight spammers "
|
||||||
validate=Utils.bool_or_none)
|
"instead of just kicking", validate=Utils.bool_or_none)
|
||||||
bot.events.on("postboot").on("configure").on(
|
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)")
|
help="Set ban format ($n = nick, $u = username, $h = hostname)")
|
||||||
|
|
||||||
def kick(self, event):
|
def kick(self, event):
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Module(object):
|
||||||
help="Get more output from the last command", skip_out=True)
|
help="Get more output from the last command", skip_out=True)
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
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")
|
help="Set the command prefix used in this channel")
|
||||||
|
|
||||||
bot.events.on("new").on("user", "channel").hook(self.new)
|
bot.events.on("new").on("user", "channel").hook(self.new)
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Module(object):
|
||||||
usage="<target>")
|
usage="<target>")
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
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",
|
help="Disable/Enable automatically responding to karma changes",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,12 @@ class Module(object):
|
||||||
self.channel_message)
|
self.channel_message)
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
bot.events.on("postboot").on("configure").on(
|
||||||
"channelset").call(setting="sed",
|
"channelset").assure_call(setting="sed",
|
||||||
help="Disable/Enable sed in a channel",
|
help="Disable/Enable sed in a channel",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
bot.events.on("postboot").on("configure").on(
|
bot.events.on("postboot").on("configure").on(
|
||||||
"channelset").call(setting="sed-sender-only",
|
"channelset").assure_call(setting="sed-sender-only",
|
||||||
help=
|
replayable=True, help=
|
||||||
"Disable/Enable sed only looking at the messages sent by the user",
|
"Disable/Enable sed only looking at the messages sent by the user",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Module(object):
|
||||||
self.channel_message)
|
self.channel_message)
|
||||||
|
|
||||||
bot.events.on("postboot").on("configure").on(
|
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",
|
help="Disable/Enable automatically getting info from youtube URLs",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue