diff --git a/EventManager.py b/EventManager.py index 23faba1b..33d4aa80 100644 --- a/EventManager.py +++ b/EventManager.py @@ -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: diff --git a/modules/auto_mode.py b/modules/auto_mode.py index 4d0c3a0b..2c33f260 100644 --- a/modules/auto_mode.py +++ b/modules/auto_mode.py @@ -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) diff --git a/modules/channel_op.py b/modules/channel_op.py index 43251609..4dc53b28 100644 --- a/modules/channel_op.py +++ b/modules/channel_op.py @@ -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): diff --git a/modules/commands.py b/modules/commands.py index c0158287..e75ae4d1 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -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) diff --git a/modules/karma.py b/modules/karma.py index 887d98df..e92b2c60 100644 --- a/modules/karma.py +++ b/modules/karma.py @@ -19,7 +19,7 @@ class Module(object): usage="") 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) diff --git a/modules/sed.py b/modules/sed.py index ca75706c..7d64669d 100644 --- a/modules/sed.py +++ b/modules/sed.py @@ -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) diff --git a/modules/youtube.py b/modules/youtube.py index 51bcac38..df965ec0 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -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)