Skip to content

Commit

Permalink
hook: Add do_sieve keyword to control sieving
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Dec 21, 2019
1 parent f6dbd49 commit 0ca6693
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cloudbot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cloudbot/plugin_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0ca6693

Please sign in to comment.