From 86a0a8cd6850f6f35dfe147ae54ae33e27a11702 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Tue, 14 Sep 2021 15:00:27 +0500 Subject: [PATCH] Little fixes and example Fixed is_forwarded custom filter & created example --- examples/custom_filters/is_filter_example.py | 21 ++++++++++++++++++++ telebot/custom_filters.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 examples/custom_filters/is_filter_example.py diff --git a/examples/custom_filters/is_filter_example.py b/examples/custom_filters/is_filter_example.py new file mode 100644 index 0000000..46d769c --- /dev/null +++ b/examples/custom_filters/is_filter_example.py @@ -0,0 +1,21 @@ +import telebot +from telebot import custom_filters + +bot = telebot.TeleBot('TOKEN') + + +# Check if message is a reply +@bot.message_handler(is_reply=True) +def start_filter(message): + bot.send_message(message.chat.id, "Looks like you replied to my message.") + +# Check if message was forwarded +@bot.message_handler(is_forwarded=True) +def text_filter(message): + bot.send_message(message.chat.id, "I do not accept forwarded messages!") + +# Do not forget to register filters +bot.add_custom_filter(custom_filters.IsReplyFilter()) +bot.add_custom_filter(custom_filters.ForwardFilter()) + +bot.polling(non_stop=True) \ No newline at end of file diff --git a/telebot/custom_filters.py b/telebot/custom_filters.py index dd1f1a2..9a3c233 100644 --- a/telebot/custom_filters.py +++ b/telebot/custom_filters.py @@ -97,7 +97,7 @@ class ForwardFilter(SimpleCustomFilter): key = 'is_forwarded' def check(self, message): - return message.forward_from_chat is not None + return message.forward_from is not None class IsReplyFilter(SimpleCustomFilter): """