From 711354b37e180a168ae74140953fc6120cf1c2d9 Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Thu, 17 Apr 2025 09:17:18 +0800 Subject: [PATCH] feat: remove chat assoc if admin kicked bot from chat --- efb_telegram_master/chat_binding.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/efb_telegram_master/chat_binding.py b/efb_telegram_master/chat_binding.py index b6accf56..cae83ec4 100644 --- a/efb_telegram_master/chat_binding.py +++ b/efb_telegram_master/chat_binding.py @@ -151,6 +151,8 @@ def __init__(self, channel: 'TelegramChannel'): self.bot.dispatcher.add_handler( MessageHandler(Filters.status_update.migrate, self.chat_migration)) + self.bot.dispatcher.add_handler( + MessageHandler(Filters.status_update.left_chat_member, self.chat_left)) def pre_link_check(self, message: Message): """Check if the bot would work properly in a linked group. @@ -955,6 +957,18 @@ def update_group_info(self, update: Update, context: CallbackContext): if pic_resized and getattr(pic_resized, 'close', None): pic_resized.close() + def chat_left(self, update: Update, context: CallbackContext): + """Triggered by any message update with either + ``left_chat_member``. + """ + assert isinstance(update, Update) + assert update.effective_message + + message = update.effective_message + if message.left_chat_member is not None and message.left_chat_member.id == self.bot.me.id: + chat_id = ChatID(str(message.chat.id)) + self.db.remove_chat_assoc(master_uid=utils.chat_id_to_str(self.channel.channel_id, chat_id)) + def chat_migration(self, update: Update, context: CallbackContext): """Triggered by any message update with either ``migrate_from_chat_id`` or ``migrate_to_chat_id``