Support importing plugins in assistant when ran as module

This commit is contained in:
Lonami Exo 2019-05-11 20:44:35 +02:00
parent 560d4bed09
commit 5d41246e73

View File

@ -378,9 +378,18 @@ bot.start(bot_token=TOKEN)
# the now downloaded `plugins/` folder). We try importing them so # the now downloaded `plugins/` folder). We try importing them so
# that the example runs fine without them, but optionally load them. # that the example runs fine without them, but optionally load them.
try: try:
# Standalone script assistant.py with folder plugins/
import plugins import plugins
plugins.init(bot) plugins.init(bot)
except ImportError: except ImportError:
pass try:
# Running as a module with `python -m assistant` and structure:
# assistant/
# __main__.py (this file)
# plugins/ (cloned)
from . import plugins
plugins.init(bot)
except ImportError:
plugins = None
bot.run_until_disconnected() bot.run_until_disconnected()