From 0ca6693de2acb181c2fefe216ba546230ac4d4a0 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 28 Nov 2019 21:07:46 -0600 Subject: [PATCH] hook: Add do_sieve keyword to control sieving --- cloudbot/plugin.py | 24 ++++++++++++------------ cloudbot/plugin_hooks.py | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cloudbot/plugin.py b/cloudbot/plugin.py index 3a778a697..34505a243 100644 --- a/cloudbot/plugin.py +++ b/cloudbot/plugin.py @@ -586,6 +586,16 @@ async def _start_periodic(self, hook): await self.launch(hook, event) await asyncio.sleep(interval) + async def _launch(self, hook, event): + # we don't need sieves on on_start hooks. + if hook.do_sieve and hook.type not in ("on_start", "on_stop", "periodic"): + for sieve in self.bot.plugin_manager.sieves: + event = await self._sieve(sieve, event, hook) + if event is None: + return False + + return await self._execute_hook(hook, event) + async def launch(self, hook, event): """ Dispatch a given event to a given hook using a given bot object. @@ -597,21 +607,11 @@ async def launch(self, hook, event): :rtype: bool """ - if hook.type not in ("on_start", "on_stop", "periodic"): # we don't need sieves on on_start hooks. - for sieve in self.bot.plugin_manager.sieves: - event = await self._sieve(sieve, event, hook) - if event is None: - return False - if hook.lock: async with hook.lock: - # Run the plugin with the message, and wait for it to finish - result = await self._execute_hook(hook, event) - else: - result = await self._execute_hook(hook, event) + return await self._launch(hook, event) - # Return the result - return result + return await self._launch(hook, event) class Plugin: diff --git a/cloudbot/plugin_hooks.py b/cloudbot/plugin_hooks.py index 8f5de894e..120ac7f42 100644 --- a/cloudbot/plugin_hooks.py +++ b/cloudbot/plugin_hooks.py @@ -51,6 +51,7 @@ def __init__(self, _type, plugin, func_hook): self.single_thread = func_hook.kwargs.pop("singlethread", False) self.action = func_hook.kwargs.pop("action", Action.CONTINUE) self.priority = func_hook.kwargs.pop("priority", Priority.NORMAL) + self.do_sieve = func_hook.kwargs.pop("do_sieve", True) lock = func_hook.kwargs.pop("lock", None)