Ejemplo n.º 1
0
def test_autodiscovery_failure_module():
    apps = ["example1", "example2", "example3"]

    with patch.object(core, "import_module") as m, patch.object(
            core.logger, "error") as logger_mock:
        m.side_effect = ImportError()
        core.autodiscovery(apps)
        assert m.call_count == 3
        assert logger_mock.call_count == 3
Ejemplo n.º 2
0
 def create_bot(self, app):
     token = app.config.get("API_TOKEN")
     autodiscovery(app.config.get("APPS", []))
     self.bot = telegram.Bot(token=token)
     self.dispatcher = Dispatcher(self.bot, None, workers=0)
     for handler in get_handlers():
         self.dispatcher.add_handler(handler)
     # log all errors
     self.dispatcher.add_error_handler(self.error)
Ejemplo n.º 3
0
    def create_bot(self, app, persistence):
        self.app = app
        self.persistence = persistence or DictPersistence()

        token = app.config.get("API_TOKEN")
        autodiscovery(app.config.get("APPS", []))
        self.bot = telegram.Bot(token=token)
        self.dispatcher = Dispatcher(self.bot,
                                     None,
                                     workers=0,
                                     use_context=True,
                                     persistence=self.persistence)
        setup_handlers(self.dispatcher)
        # log all errors
        self.dispatcher.add_error_handler(self.error)
Ejemplo n.º 4
0
def main():
    if not settings.API_TOKEN:
        logger.critical("Telegram API Token is missing(TELEGRAM_API_TOKEN)")
        return 1

    updater = Updater(settings.API_TOKEN)
    autodiscovery(settings.APPS)
    dp = updater.dispatcher
    for handler in get_handlers():
        dp.add_handler(handler)
    # log all errors
    dp.add_error_handler(error)
    updater.start_polling()
    updater.idle()
    return 0
Ejemplo n.º 5
0
def test_autodiscovery():
    apps = ["example1", "example2", "example3"]

    with patch.object(core, "import_module") as m:
        core.autodiscovery(apps)
        assert m.call_count == 3