Пример #1
0
def cli():
    def auto_reload_mixin(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            if namespace.autoreload and aiohttp_autoreload:
                logger.warning(
                    "Application started in live-reload mode. Please disable it in production!"
                )
                aiohttp_autoreload.start()
            elif namespace.autoreload and not aiohttp_autoreload:
                logger.warning("`aiohttp_autoreload` is not installed.", err=True)
            return func(*args, **kwargs)

        return wrapper

    @auto_reload_mixin
    def polling(skip_updates: bool):
        """
        Start application
        """
        from app.utils.executor import runner
        logger.info("starting polling...")

        runner.skip_updates = skip_updates
        runner.start_polling(reset_webhook=True)

    @auto_reload_mixin
    def webhook():
        """
        Run application in webhook mode
        """
        from app.utils.executor import runner
        logger.info("starting webhook...")
        runner.start_webhook(
            webhook_path=f'/{config.secret_str}/',

            host=config.LISTEN_IP,
            port=config.LISTEN_PORT,
        )

    parser = create_parser()
    namespace = parser.parse_args()
    if namespace.beta:
        config.now_token = config.TEST_BOT_TOKEN
        logger.info("use beta bot")
    else:
        config.now_token = config.BOT_TOKEN
        logger.info("use production bot")

    from app.utils import log
    from app import misc

    log.setup()
    misc.setup()
    if namespace.polling:
        polling(namespace.skip_updates)
    else:
        webhook()
Пример #2
0
def cli(config: Config):

    parser = create_parser()
    namespace = parser.parse_args()

    from app import misc
    from app.utils.executor import runner

    misc.setup(config)
    if namespace.polling:
        logger.info("starting polling...")

        runner.skip_updates = namespace.skip_updates
        runner.start_polling(reset_webhook=True)
    else:
        logger.info("starting webhook...")
        runner.start_webhook(**config.webhook.listener_kwargs)
Пример #3
0
def cli(config: Config):
    def auto_reload_mixin(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            if namespace.autoreload and aiohttp_autoreload:
                logger.warning(
                    "Application started in live-reload mode. Please disable it in production!"
                )
                aiohttp_autoreload.start()
            elif namespace.autoreload and not aiohttp_autoreload:
                logger.warning("`aiohttp_autoreload` is not installed.",
                               err=True)
            return func(*args, **kwargs)

        return wrapper

    @auto_reload_mixin
    def polling(skip_updates: bool):
        """
        Start application
        """
        from app.utils.executor import runner
        logger.info("starting polling...")

        runner.skip_updates = skip_updates
        runner.start_polling(reset_webhook=True)

    @auto_reload_mixin
    def webhook(webhook_config: WebhookConfig):
        """
        Run application in webhook mode
        """
        from app.utils.executor import runner
        logger.info("starting webhook...")
        runner.start_webhook(**webhook_config.listener_kwargs)

    parser = create_parser()
    namespace = parser.parse_args()

    from app import misc

    misc.setup(config)
    if namespace.polling:
        polling(namespace.skip_updates)
    else:
        webhook(config.webhook)
Пример #4
0
def cli():
    def polling(skip_updates: bool):
        """
        Запуск бота на лонгпуллинге
        """
        from app.utils.executor import runner

        logger.info("Starting polling...")

        runner.skip_updates = skip_updates
        runner.start_polling()

    parser = create_parser()
    namespace = parser.parse_args()

    from app import misc

    misc.setup()
    if namespace.skip_updates:
        polling(namespace.skip_updates)
Пример #5
0
from app.misc import runner, setup

setup()
runner.start_polling()
Пример #6
0
def cli():
    from app.utils import logging
    from app import misc

    logging.setup()
    misc.setup()
Пример #7
0
from app.utils import logging
from app import misc

if __name__ == "__main__":
    logging.setup()
    misc.setup()