From 98f60d498b91ea4bd7127b6e10ad96f0cd5e9b6d Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Fri, 17 Jul 2020 23:37:06 +0200 Subject: [PATCH] [telegram] Fix telegram api key update bug --- kibicara/platforms/telegram/bot.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/kibicara/platforms/telegram/bot.py b/kibicara/platforms/telegram/bot.py index bbdb631..2bbd550 100644 --- a/kibicara/platforms/telegram/bot.py +++ b/kibicara/platforms/telegram/bot.py @@ -18,13 +18,7 @@ class TelegramBot(Censor): def __init__(self, telegram_model): super().__init__(telegram_model.hood) self.telegram_model = telegram_model - try: - self.bot = Bot(token=telegram_model.api_token) - self.dp = self._create_dispatcher() - except exceptions.ValidationError: - self.telegram_model.enabled = False - finally: - self.enabled = self.telegram_model.enabled + self.enabled = self.telegram_model.enabled def _create_dispatcher(self): dp = Dispatcher(self.bot) @@ -35,8 +29,8 @@ class TelegramBot(Censor): async def run(self): try: - if not self.dp: - self.dp = self._create_dispatcher() + self.bot = Bot(token=self.telegram_model.api_token) + self.dp = self._create_dispatcher() logger.debug(f'Bot {self.telegram_model.hood.name} starting.') await gather(self.dp.start_polling(), self._push()) except CancelledError: @@ -45,6 +39,7 @@ class TelegramBot(Censor): raise except exceptions.ValidationError: logger.debug(f'Bot {self.telegram_model.hood.name} has invalid auth token.') + await self.telegram_model.update(enabled=False) finally: logger.debug(f'Bot {self.telegram_model.hood.name} stopped.')