1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

new TextFilter examples were added

This commit is contained in:
abdullaev388 2022-02-12 21:53:40 +05:00
parent 6822f18cbb
commit 8c3d1e608c
2 changed files with 36 additions and 0 deletions

View File

@ -90,6 +90,24 @@ async def poll_question_handler_ignore_case(poll: types.Poll):
print(poll.question + ' ignore case') print(poll.question + ' ignore case')
# either hi or contains one of (привет, salom)
@bot.message_handler(text=TextFilter(equals="hi", contains=('привет', 'salom'), ignore_case=True))
async def multiple_patterns_handler(message: types.Message):
await bot.send_message(message.chat.id, message.text)
# starts with one of (mi, mea) for ex. minor, milk, meal, meat
@bot.message_handler(text=TextFilter(starts_with=['mi', 'mea'], ignore_case=True))
async def multiple_starts_with_handler(message: types.Message):
await bot.send_message(message.chat.id, message.text)
# ends with one of (es, on) for ex. Jones, Davies, Johnson, Wilson
@bot.message_handler(text=TextFilter(ends_with=['es', 'on'], ignore_case=True))
async def multiple_ends_with_handler(message: types.Message):
await bot.send_message(message.chat.id, message.text)
if __name__ == '__main__': if __name__ == '__main__':
bot.add_custom_filter(TextMatchFilter()) bot.add_custom_filter(TextMatchFilter())
asyncio.run(bot.polling()) asyncio.run(bot.polling())

View File

@ -88,6 +88,24 @@ def poll_question_handler_ignore_case(poll: types.Poll):
print(poll.question + ' ignore case') print(poll.question + ' ignore case')
# either hi or contains one of (привет, salom)
@bot.message_handler(text=TextFilter(equals="hi", contains=('привет', 'salom'), ignore_case=True))
def multiple_patterns_handler(message: types.Message):
bot.send_message(message.chat.id, message.text)
# starts with one of (mi, mea) for ex. minor, milk, meal, meat
@bot.message_handler(text=TextFilter(starts_with=['mi', 'mea'], ignore_case=True))
def multiple_starts_with_handler(message: types.Message):
bot.send_message(message.chat.id, message.text)
# ends with one of (es, on) for ex. Jones, Davies, Johnson, Wilson
@bot.message_handler(text=TextFilter(ends_with=['es', 'on'], ignore_case=True))
def multiple_ends_with_handler(message: types.Message):
bot.send_message(message.chat.id, message.text)
if __name__ == '__main__': if __name__ == '__main__':
bot.add_custom_filter(TextMatchFilter()) bot.add_custom_filter(TextMatchFilter())
bot.infinity_polling() bot.infinity_polling()