Skip to content

Commit

Permalink
bot: check defined sections in post_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Oct 30, 2020
1 parent 096135e commit 35e4916
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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``.
Expand Down

0 comments on commit 35e4916

Please sign in to comment.