|
@@ -1,7 +1,5 @@
|
|
|
-import importlib
|
|
|
import logging
|
|
|
import time
|
|
|
-from threading import Thread
|
|
|
|
|
|
from command_system import RollbotResponse, RollbotFailure, as_plugin
|
|
|
|
|
@@ -14,7 +12,7 @@ def lift_response(call, response):
|
|
|
|
|
|
|
|
|
class Rollbot:
|
|
|
- def __init__(self, logger=logging.getLogger(__name__), plugins={}, aliases={}, responses={}, lookup={}, sleep_time=0.0, session_factory=None, callback=None):
|
|
|
+ def __init__(self, logger=logging.getLogger(__name__), plugin_classes={}, aliases={}, responses={}, lookup={}, sleep_time=0.0, session_factory=None, callback=None):
|
|
|
self.logger = logger
|
|
|
self.session_factory = session_factory or (lambda: None)
|
|
|
self.callback = callback or (lambda txt, gid: self.logger.info(f"Responding to {gid} with {txt}"))
|
|
@@ -23,20 +21,16 @@ class Rollbot:
|
|
|
self.to_stop = set()
|
|
|
|
|
|
self.logger.info("Loading command plugins")
|
|
|
- for module, classes in plugins.items():
|
|
|
- plugin_module = importlib.import_module("plugins." + module)
|
|
|
- for class_name in classes:
|
|
|
- self.logger.info(class_name)
|
|
|
- plugin_class = getattr(plugin_module, class_name)
|
|
|
- plugin_instance = plugin_class(logger=logger)
|
|
|
- if plugin_instance.command in self.commands:
|
|
|
- self.logger.error(f"Duplicate command word '{plugin_instance.command}'")
|
|
|
- raise ValueError(f"Duplicate command word '{plugin_instance.command}'")
|
|
|
- self.commands[plugin_instance.command] = plugin_instance
|
|
|
- if "on_start" in plugin_class.__dict__:
|
|
|
- self.to_start.add(plugin_instance)
|
|
|
- if "on_shutdown" in plugin_class.__dict__:
|
|
|
- self.to_stop.add(plugin_instance)
|
|
|
+ for plugin_class in plugin_classes:
|
|
|
+ plugin_instance = plugin_class(logger=logger)
|
|
|
+ if plugin_instance.command in self.commands:
|
|
|
+ self.logger.error(f"Duplicate command word '{plugin_instance.command}'")
|
|
|
+ raise ValueError(f"Duplicate command word '{plugin_instance.command}'")
|
|
|
+ self.commands[plugin_instance.command] = plugin_instance
|
|
|
+ if "on_start" in plugin_class.__dict__:
|
|
|
+ self.to_start.add(plugin_instance)
|
|
|
+ if "on_shutdown" in plugin_class.__dict__:
|
|
|
+ self.to_stop.add(plugin_instance)
|
|
|
self.logger.info(f"Finished loading plugins, {len(self.commands)} commands found")
|
|
|
|
|
|
self.logger.info("Loading simple responses")
|
|
@@ -135,7 +129,3 @@ class Rollbot:
|
|
|
|
|
|
t = time.time() - t
|
|
|
self.logger.info(f"Exiting command thread for {message.message_id} after {t:.3f}s")
|
|
|
-
|
|
|
- def handle_command_threaded(self, message):
|
|
|
- t = Thread(target=lambda: self.handle_command(message))
|
|
|
- t.start()
|