Skip to content

Commit 93c323b

Browse files
committed
Ensure hooks are triggering in priority order
1 parent 2fc1fda commit 93c323b

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
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Fix FML random URL
3131
- Update tvdb.py to v3 TVDB API
3232
- Fix channel parameter handling in IRC client
33+
- Ensure hooks are triggered according to priority
3334
### Removed
3435
- twitch.py removed due to outdated API and lack of maintainer
3536
- metacritic.py removed due to broken scraper and lack of maintainer

cloudbot/bot.py

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

325-
coro = self.plugin_manager.launch(hook, _event)
326-
tasks.append(coro)
325+
tasks.append((hook, _event))
327326

328327
if hook.action is Action.HALTALL:
329328
halted = True
@@ -417,5 +416,10 @@ def add_hook(hook, _event):
417416
# The hook has an action of Action.HALT* so stop adding new tasks
418417
break
419418

419+
tasks.sort(key=lambda t: t[0].priority)
420+
420421
# Run the tasks
421-
await asyncio.gather(*tasks, loop=self.loop)
422+
await asyncio.gather(*[
423+
asyncio.ensure_future(self.plugin_manager.launch(hook, _event))
424+
for hook, _event in tasks
425+
], loop=self.loop)

0 commit comments

Comments
 (0)