示例#1
0
 def run(self):
     if should_run_webhook():
         self._run_webhook()
     else:
         self._run_polling()
     # Run the cleanup worker in a seperate thread.
     self._run_cleanup_worker()
示例#2
0
 def run(self):
     try:
         if should_run_webhook():
             self._run_webhook()
         else:
             self._run_polling()
         # Run the cleanup worker in a seperate thread.
         self._run_cleanup_worker()
     except Exception as e:
         print(e)
示例#3
0
    def exit(self):
        """
        Called once when the app is about to exit.
        """

        if not should_run_webhook():
            return

        # clean up running threads
        self.update_queue.stop()
        self.dispatcher_thread.join()
        self.cleanup_worker_thread.join()
        self.dispatcher.stop()
示例#4
0
    def setup(self):
        """
        Called once when the app launches.
        """

        # set webhook
        if not should_run_webhook():
            return

        webhook_url = "{}{}".format(get_active_config().APP_URL, self.token)

        current_webhook_url = self.bot.get_webhook_info().url

        if current_webhook_url != webhook_url:
            logger.info(f"setting webhook url to: {webhook_url}")
            self.bot.set_webhook(webhook_url)
示例#5
0
    def __init__(self, token, app=None):
        self.token = token
        self.app = app

        if should_run_webhook():
            self.bot = Bot(self.token)
            self.update_queue = Queue()
            self.dispatcher = Dispatcher(self.bot,
                                         self.update_queue,
                                         use_context=True)
        else:
            self.updater = Updater(self.token, use_context=True)

            self.bot = self.updater.bot
            self.update_queue = None
            self.dispatcher = self.updater.dispatcher

        self.handlers_manager = HandlersManager(self.dispatcher, self.app)
        self.worker = CleanupWorker(self.bot, self.app)