Merge remote-tracking branch 'origin/refresh' into refresh
This commit is contained in:
commit
56a3ca30c8
2 changed files with 17 additions and 5 deletions
11
core/bot.py
11
core/bot.py
|
@ -68,6 +68,17 @@ class Bot(threading.Thread):
|
||||||
|
|
||||||
# run plugin loader
|
# run plugin loader
|
||||||
self.plugins = collections.defaultdict(list)
|
self.plugins = collections.defaultdict(list)
|
||||||
|
|
||||||
|
""" plugins format
|
||||||
|
{'PLUGIN_TYPE': [(<COMPILED_PLUGIN_FUNTION>,
|
||||||
|
{PLUGIN_ARGS}),
|
||||||
|
(<COMPILED_PLUGIN_FUNTION>,
|
||||||
|
{PLUGIN_ARGS})],
|
||||||
|
'PLUGIN_TYPE': [(<COMPILED_PLUGIN_FUNTION>,
|
||||||
|
{PLUGIN_ARGS})]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
self.threads = {}
|
self.threads = {}
|
||||||
|
|
||||||
self.loader = PluginLoader(self)
|
self.loader = PluginLoader(self)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import collections
|
||||||
|
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.tricks import Trick
|
from watchdog.tricks import Trick
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
from core import main
|
from core import main
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ class PluginLoader(object):
|
||||||
self.observer.start()
|
self.observer.start()
|
||||||
|
|
||||||
self.load_all()
|
self.load_all()
|
||||||
|
pprint(bot.plugins)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""shuts down the plugin reloader"""
|
"""shuts down the plugin reloader"""
|
||||||
|
@ -58,7 +60,7 @@ class PluginLoader(object):
|
||||||
disabled = self.bot.config.get('disabled_plugins', [])
|
disabled = self.bot.config.get('disabled_plugins', [])
|
||||||
if title in disabled:
|
if title in disabled:
|
||||||
self.bot.logger.info("Did not load plugins from: {} (plugin disabled)".format(filename))
|
self.bot.logger.info("Did not load plugins from: {} (plugin disabled)".format(filename))
|
||||||
return None
|
return
|
||||||
|
|
||||||
# compile the file and eval it in a namespace
|
# compile the file and eval it in a namespace
|
||||||
try:
|
try:
|
||||||
|
@ -67,13 +69,12 @@ class PluginLoader(object):
|
||||||
eval(code, namespace)
|
eval(code, namespace)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.bot.logger.exception("Error compiling {}:".format(filename))
|
self.bot.logger.exception("Error compiling {}:".format(filename))
|
||||||
#self.bot.logger.error(traceback.format_exc())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# remove plugins already loaded from this file
|
# remove plugins already loaded from this file
|
||||||
for name, data in self.bot.plugins.items():
|
for plug_type, data in self.bot.plugins.items():
|
||||||
self.bot.plugins[name] = [x for x in data
|
self.bot.plugins[plug_type] = [x for x in data
|
||||||
if x[0]._filename != filename]
|
if x[0]._filename != filename]
|
||||||
|
|
||||||
# stop all currently running instances of the plugins from this file
|
# stop all currently running instances of the plugins from this file
|
||||||
for func, handler in list(self.bot.threads.items()):
|
for func, handler in list(self.bot.threads.items()):
|
||||||
|
|
Reference in a new issue