class KutanaTest(unittest.TestCase): def setUp(self): self.app = None self.target = [] @contextmanager def debug_manager(self, queue): if self.app is None: self.app = Kutana() self.manager = DebugManager(*queue) self.app.add_manager(self.manager) self.plugin = Plugin() self.plugins = [self.plugin] try: yield self.plugin finally: for plugin in self.plugins: self.app.register_plugins([plugin]) self.app.run() self.assertEqual(self.target, self.manager.replies)
import json from kutana import Kutana, VKManager, load_plugins, TGManager # Load configuration with open("configuration.json") as fh: config = json.load(fh) # Create application app = Kutana() # Add manager to application app.add_manager(VKManager(config["vk_token"])) app.add_manager(TGManager(config["tg_token"])) # Load and register plugins app.register_plugins(load_plugins("plugins/")) if __name__ == "__main__": # Run application app.run()
with open("config.json", "r") as fh: config = json.load(fh) app.config["names"] = config["info"]["names"] # Register plugins app.register_plugins(load_plugins("plugins/")) # Add managers from configuration for manager_conf in config["managers"]: manager = None if manager_conf["type"] == "vkontakte": manager = VKManager elif manager_conf["type"] == "telegram": manager = TGManager if manager is None: raise ValueError("Unknown manager type: {}".format( manager_conf["type"])) kwargs = manager_conf kwargs.pop("type") app.add_manager(manager(**kwargs)) # Start engine if this file was run if __name__ == "__main__": app.run()