From 5e9a947284b51a6afed6a89e8c070eaef55ffc7f Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Mon, 31 Aug 2020 14:08:53 +0200 Subject: [PATCH] [telegram] Add username to telegram bots --- kibicara/platforms/telegram/bot.py | 3 +++ kibicara/platforms/telegram/model.py | 1 + 2 files changed, 4 insertions(+) diff --git a/kibicara/platforms/telegram/bot.py b/kibicara/platforms/telegram/bot.py index 2bbd550..3f5c9a2 100644 --- a/kibicara/platforms/telegram/bot.py +++ b/kibicara/platforms/telegram/bot.py @@ -32,6 +32,9 @@ class TelegramBot(Censor): self.bot = Bot(token=self.telegram_model.api_token) self.dp = self._create_dispatcher() logger.debug(f'Bot {self.telegram_model.hood.name} starting.') + user = await self.bot.get_me() + if user.username: + await self.telegram_model.update(username=user.username) await gather(self.dp.start_polling(), self._push()) except CancelledError: logger.debug(f'Bot {self.telegram_model.hood.name} received Cancellation.') diff --git a/kibicara/platforms/telegram/model.py b/kibicara/platforms/telegram/model.py index 16bc053..a5beae1 100644 --- a/kibicara/platforms/telegram/model.py +++ b/kibicara/platforms/telegram/model.py @@ -11,6 +11,7 @@ class Telegram(Model): hood: ForeignKey(Hood) api_token: Text(unique=True) welcome_message: Text() + username: Text(allow_null=True) = None enabled: Boolean() = True class Mapping(Mapping):