bot: respect priority field of plugins

This commit is contained in:
dece 2020-11-03 16:22:57 +01:00
parent 8773141406
commit 474224b64e
2 changed files with 4 additions and 1 deletions

View file

@ -151,7 +151,9 @@ class Bot(irc.client.SimpleIRCClient, Logger):
def run_plugin_callbacks(self, event): def run_plugin_callbacks(self, event):
"""Run appropriate callbacks for each plugin.""" """Run appropriate callbacks for each plugin."""
etype = event.type etype = event.type
for plugin in filter(lambda p: p.is_ready, self.plugins): plugins = filter(lambda p: p.is_ready, self.plugins)
plugins = sorted(plugins, key=lambda p: p.priority, reverse=True)
for plugin in plugins:
callbacks = plugin.callbacks callbacks = plugin.callbacks
if etype not in callbacks: if etype not in callbacks:
continue continue

View file

@ -9,6 +9,7 @@ class Plugin:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.name = self.__class__.__name__.lower()[:-6] # Remove "Plugin". self.name = self.__class__.__name__.lower()[:-6] # Remove "Plugin".
self.priority = 0
self.config = self.__get_config() self.config = self.__get_config()
self.is_ready = self.__check_config() self.is_ready = self.__check_config()