Skip to content

Commit a48cafe

Browse files
committed
Ensure hooks are triggering in priority order
1 parent 0f76506 commit a48cafe

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Update mylife.py for website changes
2424
- Fixed handling of colons in core IRC parser
2525
- Fix FML random URL
26+
- Ensure hooks are triggered according to priority
2627
### Removed
2728
- twitch.py removed due to outdated API and lack of maintainer
2829
- Remove unused run_before events/tasks

cloudbot/bot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ def add_hook(hook, _event):
311311
if hook.clients and _event.conn.type not in hook.clients:
312312
return True
313313

314-
coro = self.plugin_manager.launch(hook, _event)
315-
tasks.append(coro)
314+
tasks.append((hook, _event))
316315

317316
if hook.action is Action.HALTALL:
318317
halted = True
@@ -396,5 +395,10 @@ def add_hook(hook, _event):
396395
# The hook has an action of Action.HALT* so stop adding new tasks
397396
break
398397

398+
tasks.sort(key=lambda t: t[0].priority)
399+
399400
# Run the tasks
400-
await asyncio.gather(*tasks, loop=self.loop)
401+
await asyncio.gather(*[
402+
asyncio.ensure_future(self.plugin_manager.launch(hook, _event))
403+
for hook, _event in tasks
404+
], loop=self.loop)

0 commit comments

Comments
 (0)