Skip to content

Commit 35e4916

Browse files
committed
bot: check defined sections in post_setup
1 parent 096135e commit 35e4916

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

sopel/bot.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def setup(self):
254254
"""
255255
self.setup_logging()
256256
self.setup_plugins()
257-
self._scheduler.start()
257+
self.post_setup()
258258

259259
def setup_logging(self):
260260
"""Set up logging based on config options."""
@@ -322,6 +322,34 @@ def setup_plugins(self):
322322
else:
323323
LOGGER.warning("Warning: Couldn't load any plugins")
324324

325+
# post setup
326+
327+
def post_setup(self):
328+
"""Perform post-setup actions.
329+
330+
This method handles everything that should happen after all the plugins
331+
are loaded, and before the bot can connect to the IRC server.
332+
333+
At the moment, this method checks for undefined configuration options,
334+
and starts the job scheduler.
335+
336+
.. versionadded:: 7.1
337+
"""
338+
settings = self.settings
339+
for section_name, section in settings.get_defined_sections():
340+
for option_name in settings.parser.options(section_name):
341+
if not hasattr(section, option_name):
342+
LOGGER.warning(
343+
'Config option `%s.%s` is not defined by its section '
344+
'and may not be recognized by Sopel.',
345+
section_name,
346+
option_name,
347+
)
348+
349+
self._scheduler.start()
350+
351+
# plugins management
352+
325353
def reload_plugin(self, name):
326354
"""Reload a plugin.
327355
@@ -448,6 +476,8 @@ def get_plugin_meta(self, name):
448476

449477
return self._plugins[name].get_meta_description()
450478

479+
# callable management
480+
451481
@deprecated(
452482
reason="Replaced by specific `unregister_*` methods.",
453483
version='7.1',
@@ -605,6 +635,8 @@ def msg(self, recipient, text, max_messages=1):
605635
"""
606636
self.say(text, recipient, max_messages)
607637

638+
# message dispatch
639+
608640
def call_rule(self, rule, sopel, trigger):
609641
# rate limiting
610642
if not trigger.admin and not rule.is_unblockable():
@@ -852,6 +884,8 @@ def _update_running_triggers(self, running_triggers):
852884
self._running_triggers = [
853885
t for t in running_triggers if t.is_alive()]
854886

887+
# event handlers
888+
855889
def on_scheduler_error(self, scheduler, exc):
856890
"""Called when the Job Scheduler fails.
857891
@@ -965,6 +999,8 @@ def _shutdown(self):
965999
# Avoid calling shutdown methods if we already have.
9661000
self.shutdown_methods = []
9671001

1002+
# URL callbacks management
1003+
9681004
def register_url_callback(self, pattern, callback):
9691005
"""Register a ``callback`` for URLs matching the regex ``pattern``.
9701006

0 commit comments

Comments
 (0)