split config-defined plugins and builtin plugins

master
BuildTools 4 years ago
parent a9bd68c7db
commit fbed938766
  1. 0
      default_plugins/authy.py
  2. 0
      default_plugins/hotload.py
  3. 8
      main.py
  4. 14
      plugin_manager.py

@ -1,3 +1,9 @@
from client import client from client import client
olive = client() from sys import argv, exit
olive = None
if len(argv) < 2:
olive = client() # is this clean? who knows!
else:
olive = client(config_path = argv[1])
olive.run() olive.run()

@ -3,21 +3,25 @@ import sys
class plugin_manager(): class plugin_manager():
def __init__(self, logger, plugin_path = "./plugins"): def __init__(self, logger, plugin_path = "./plugins"):
sys.path.append(plugin_path) # needed to __import__ scripts without a hassle, shouldn't cause an issue self.logger = logger
plugins = [name.split(".py")[0] for name in os.listdir(plugin_path) if name.endswith(".py")]
self.plugins_loaded = [] self.plugins_loaded = []
self.load_folder("./default_plugins")
self.load_folder(plugin_path)
def load_folder(self, path):
sys.path.append(path) # needed to __import__ scripts without a hassle, shouldn't cause an issue
plugins = [name.split(".py")[0] for name in os.listdir(path) if name.endswith(".py")]
for plugin in plugins: for plugin in plugins:
try: try:
module = __import__(plugin) module = __import__(plugin)
except: except:
logger.write(f"error loading plugin {plugin}") self.logger.write(f"error loading plugin {plugin}")
continue continue
if not(hasattr(module, "run")) or not(hasattr(module, "hooks")): if not(hasattr(module, "run")) or not(hasattr(module, "hooks")):
logger.write(f"plugin {plugin} is invalid: crucial attribute missing!") self.logger.write(f"plugin {plugin} is invalid: crucial attribute missing!")
continue continue
else: else:
self.plugins_loaded.append(module) self.plugins_loaded.append(module)
logger.write(f"loaded plugin {module.__name__}") # this name will be used for hotloading self.logger.write(f"loaded plugin {module.__name__}") # this name will be used for hotloading
def handle(self, event, ctx, bot): def handle(self, event, ctx, bot):
for plugin in self.plugins_loaded: for plugin in self.plugins_loaded:
if event in plugin.hooks: if event in plugin.hooks:

Loading…
Cancel
Save