From 35e4916c55ed2e99507fe0ce67faa3a9c9567d46 Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Fri, 30 Oct 2020 15:29:38 +0100 Subject: [PATCH] bot: check defined sections in post_setup --- sopel/bot.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/sopel/bot.py b/sopel/bot.py index 974ead850d..c84ffe9137 100644 --- a/sopel/bot.py +++ b/sopel/bot.py @@ -254,7 +254,7 @@ def setup(self): """ self.setup_logging() self.setup_plugins() - self._scheduler.start() + self.post_setup() def setup_logging(self): """Set up logging based on config options.""" @@ -322,6 +322,34 @@ def setup_plugins(self): else: LOGGER.warning("Warning: Couldn't load any plugins") + # post setup + + def post_setup(self): + """Perform post-setup actions. + + This method handles everything that should happen after all the plugins + are loaded, and before the bot can connect to the IRC server. + + At the moment, this method checks for undefined configuration options, + and starts the job scheduler. + + .. versionadded:: 7.1 + """ + settings = self.settings + for section_name, section in settings.get_defined_sections(): + for option_name in settings.parser.options(section_name): + if not hasattr(section, option_name): + LOGGER.warning( + 'Config option `%s.%s` is not defined by its section ' + 'and may not be recognized by Sopel.', + section_name, + option_name, + ) + + self._scheduler.start() + + # plugins management + def reload_plugin(self, name): """Reload a plugin. @@ -448,6 +476,8 @@ def get_plugin_meta(self, name): return self._plugins[name].get_meta_description() + # callable management + @deprecated( reason="Replaced by specific `unregister_*` methods.", version='7.1', @@ -605,6 +635,8 @@ def msg(self, recipient, text, max_messages=1): """ self.say(text, recipient, max_messages) + # message dispatch + def call_rule(self, rule, sopel, trigger): # rate limiting if not trigger.admin and not rule.is_unblockable(): @@ -852,6 +884,8 @@ def _update_running_triggers(self, running_triggers): self._running_triggers = [ t for t in running_triggers if t.is_alive()] + # event handlers + def on_scheduler_error(self, scheduler, exc): """Called when the Job Scheduler fails. @@ -965,6 +999,8 @@ def _shutdown(self): # Avoid calling shutdown methods if we already have. self.shutdown_methods = [] + # URL callbacks management + def register_url_callback(self, pattern, callback): """Register a ``callback`` for URLs matching the regex ``pattern``.