def bind_filters(bot: telebot.TeleBot): bot.add_custom_filter(CalendarCallbackFilter()) bot.add_custom_filter(CalendarZoomCallbackFilter())
bot.answer_callback_query(callback_query_id=call.id, text='Not available :(', show_alert=True) # Any other products @bot.callback_query_handler(func=None, config=products_factory.filter()) def products_callback(call: types.CallbackQuery): callback_data: dict = products_factory.parse(callback_data=call.data) product_id = int(callback_data['product_id']) product = PRODUCTS[product_id] text = f"Product name: {product['name']}\n" \ f"Product price: {product['price']}" bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=text, reply_markup=back_keyboard()) @bot.callback_query_handler(func=lambda c: c.data == 'back') def back_callback(call: types.CallbackQuery): bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Products:', reply_markup=products_keyboard()) bot.add_custom_filter(ProductsCallbackFilter()) bot.infinity_polling()
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) # !ban /ban .ban !бан /бан .бан @bot.message_handler(is_reply=True, text=TextFilter(starts_with=('!', '/', '.'), ends_with=['ban', 'бан'], ignore_case=True)) def ban_command_handler(message: types.Message): if len(message.text) == 4 and message.chat.type != 'private': try: bot.ban_chat_member(message.chat.id, message.reply_to_message.from_user.id) bot.reply_to(message.reply_to_message, 'Banned.') except Exception as err: print(err.args) return if __name__ == '__main__': bot.add_custom_filter(TextMatchFilter()) bot.add_custom_filter(IsReplyFilter()) bot.infinity_polling()
) text = _("This is clicker.\n\n") + text.format(number=clicks) bot.send_message(message.chat.id, text, reply_markup=keyboards.clicker_keyboard(_)) @bot.callback_query_handler(func=None, text=custom_filters.TextFilter(equals='click')) def click_handler(call: types.CallbackQuery): if not users_clicks.get(call.from_user.id): users_clicks[call.from_user.id] = 1 else: users_clicks[call.from_user.id] += 1 clicks = users_clicks[call.from_user.id] text = __(singular="You have {number} click", plural="You have {number} clicks", n=clicks) text = _("This is clicker.\n\n") + text.format(number=clicks) bot.edit_message_text(text, call.from_user.id, call.message.message_id, reply_markup=keyboards.clicker_keyboard(_)) if __name__ == '__main__': bot.add_custom_filter(custom_filters.TextMatchFilter()) bot.infinity_polling()