From 950e8b3ac667e870e03ca0e82d957fe411edc904 Mon Sep 17 00:00:00 2001 From: Byron Torres Date: Tue, 29 Mar 2022 01:56:13 +0000 Subject: [PATCH] Ignore messaged forwarded from self Messages from the bot which have been forwarded to group chats are ignored. This avoids duplicate substitution messages. Messages from the bot which have been forwarded to the bot as a private message are not ignored. This continues to allow for intentional duplication or replacement of old faulty proxy links for newer ones. --- linkchanbot | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/linkchanbot b/linkchanbot index 41b94ea..b73bb7a 100755 --- a/linkchanbot +++ b/linkchanbot @@ -673,8 +673,7 @@ def main(): dp.add_handler(ChosenInlineResultHandler(cb_chosen_inline_result)) dp.add_handler(MessageHandler( - # (not) messages from this bot - ~Filters.via_bot(username=BOT_USERNAME) & ( + ( # non-edited messages Filters.update.message | Filters.update.channel_post ) & ( @@ -683,6 +682,14 @@ def main(): Filters.entity(MessageEntity.TEXT_LINK) | Filters.caption_entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.TEXT_LINK) + ) & ( + # not messages created via this bot (inline queries, etc.) + ~Filters.via_bot(username=BOT_USERNAME) + ) & ~( + # not messages from bot forwarded to group chats + # (forwarded to bot's private chat is OK) + Filters.forwarded_from(username=BOT_USERNAME) + & ~Filters.chat_type.private ), cb_link_handler )) -- 2.38.5