From 793fdb0e840175596478382ab26afeb273d08075 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 9 Jan 2018 15:18:38 -0600 Subject: [PATCH] config option for loading bot "plugins" as it turns out, i can't use a module __init__.py to load bot stuff, if that code would refer to django models, because the django code will try to do stuff before the apps are initialized, and then the entire house of cards crumbles apart. so, i will explicitly load these bot "plugins" separately, after the modules proper are all initialized --- bot/management/commands/starthitomi.py | 5 +++++ hitomi/settings.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/bot/management/commands/starthitomi.py b/bot/management/commands/starthitomi.py index a78940e..ccf772a 100644 --- a/bot/management/commands/starthitomi.py +++ b/bot/management/commands/starthitomi.py @@ -1,5 +1,6 @@ """Start the Discord bot and connect to Discord.""" import asyncio +import importlib import logging from django.conf import settings @@ -16,6 +17,10 @@ async def on_ready(): """Print some basic login info to the console, when the bot connects.""" logger.info("Logged in as {0:s} ({1:s})".format(hitomi.user.name, hitomi.user.id)) + # now load bot plugins + for plugin in settings.BOT_PLUGINS: + importlib.import_module(plugin) + @hitomi.event async def on_message(message): diff --git a/hitomi/settings.py b/hitomi/settings.py index 9b7d185..4a42b1a 100644 --- a/hitomi/settings.py +++ b/hitomi/settings.py @@ -132,6 +132,8 @@ DISCORD_BOT_MAX_MESSAGES = 5000 LOGGER_BASE_DIR = './logs' WEATHER_WEATHER_UNDERGROUND_API_KEY = 'key' +BOT_PLUGINS = [] + # get local settings