Пример #1
0
def main():
    app = Kutana()
    # set_logger_level(logging.DEBUG)

    backend = Vkontakte(SHUF_SETTINGS['TOKEN'])
    app.add_backend(backend)
    app.config['settings'] = SHUF_SETTINGS
    app.config['prefixes'] = ('еш ', 'есб ', 'esb ', 'ешаф ', 'eshuf '
                              )  # ('шаф ', 'sb ', 'шб ', 'shuf ', 'shufbot ')
    app.config['inform_time'] = time(20, 50)  # 12:00
    app.config['votekick_time'] = 5 * 60
    init_db(app)

    app.add_plugins(load_plugins(os.path.join(os.curdir, 'bot', 'plugins')))

    return app
Пример #2
0
def run():
    """
    This function runs kutana application using provided
    configuration and CLI options.

    Refer to its source to create more specific starter for
    your application.
    """

    # Parse provided arguments
    args = parser.parse_args()

    # Setup logger
    if args.debug:
        logger.set_logger_level(logging.DEBUG)

    # Import configuration
    if not os.path.isfile(args.config):
        logger.logger.error(f"Couldn't open confiuration file: {args.config}")
        exit(1)

    with open(args.config) as fh:
        config = yaml.safe_load(fh)

    # Create application
    app = Kutana()

    # Update configuration
    app.config.update(config)

    # Setup i18n
    set_default_language(config.get("language", "en"))
    load_translations(args.translations)

    # Add each backend from config
    add_backends(app, config.get("backends"))

    # Add each storage from config
    add_storages(app, config.get("storages"))

    # Load and register plugins from provided path
    app.add_plugins(load_plugins(args.plugins))

    # Run application
    app.run()
Пример #3
0
    def test_functions(self):
        loaded_plugins = load_plugins("test/test_plugins/")

        self.assertEqual(len(loaded_plugins), 1)
        self.assertEqual(loaded_plugins[0].name, "Memory")

        executor = Executor()
        executor.register_plugins(*loaded_plugins)

        loop = asyncio.get_event_loop()

        loop.run_until_complete(
            executor(
                "message",
                objdict(
                    ctrl_type="debug",
                    convert_to_message=DebugController.convert_to_message)))

        self.assertEqual(loaded_plugins[0].memory, "message")
Пример #4
0
    def test_load_plugins(self):
        loaded_plugins = load_plugins("test/test_plugins/")
        loaded_plugins.sort(key=lambda plugin: plugin.name)

        self.assertEqual(len(loaded_plugins), 3)

        self.assertEqual(loaded_plugins[0].name, "Memory")
        self.assertEqual(loaded_plugins[1].name, "My file")
        self.assertEqual(loaded_plugins[2].name, "My file twice")

        app = Kutana()
        app.register_plugins(loaded_plugins)

        loop = asyncio.get_event_loop()

        loop.run_until_complete(app.startup())

        loop.run_until_complete(app.process(DebugManager(), "message"))

        self.assertEqual(loaded_plugins[0].memory, "message")
        self.assertEqual(loaded_plugins[1].my_file, ":)")
        self.assertEqual(loaded_plugins[2].my_file, ":):)")
Пример #5
0
from kutana import Kutana, VKController, load_plugins, load_configuration


# Create engine
kutana = Kutana()

# Create VKController
kutana.add_controller(
    VKController(token = "d6842a32a19fefc24f1ac19b17cba1c9243f4bf1ecdf426215d193d96135a111d0d537f6e2df8f1452482")
)

# Load and register plugins
kutana.executor.register_plugins(*load_plugins("/root/bot/example/"))

# Run engine
kutana.run()
Пример #6
0
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()
Пример #7
0
import json
import kutana

# Import configuration
with open("config.json") as fh:
    config = json.load(fh)

# Create application
app = kutana.Kutana()

# Add manager to application
app.add_backend(kutana.backends.Vkontakte(token=config["vk_token"]))

# Load and register plugins
app.add_plugins(kutana.load_plugins("plugins/"))

if __name__ == "__main__":
    # Run application
    app.run()
Пример #8
0
import json
from kutana import Kutana, load_plugins
from kutana.backends import Vkontakte

# Import configuration
with open("config.json") as fh:
    config = json.load(fh)

# Create application
app = Kutana()

# Add manager to application
app.add_backend(Vkontakte(token=config["vk_token"]))

# Load and register plugins
app.add_plugins(load_plugins("plugins/"))

if __name__ == "__main__":
    # Run application
    app.run()
Пример #9
0
from kutana import Kutana, VKController, load_plugins, \
    load_configuration

# Create engine
kutana = Kutana()

# Create VKController
controller = VKController(load_configuration("vk_token", "configuration.json"))

# Add controller to engine
kutana.add_controller(controller)

# Load and register plugins
kutana.executor.register_plugins(*load_plugins("example/plugins/"))

# Run engine
kutana.run()