2021-09-11 22:21:35 +03:00
|
|
|
import telebot
|
|
|
|
|
|
|
|
bot = telebot.TeleBot('TOKEN')
|
|
|
|
|
|
|
|
|
|
|
|
# AdvancedCustomFilter is for list, string filter values
|
2021-09-12 19:36:23 +03:00
|
|
|
class MainFilter(telebot.custom_filters.AdvancedCustomFilter):
|
2021-09-11 22:21:35 +03:00
|
|
|
key='text'
|
|
|
|
@staticmethod
|
|
|
|
def check(message, text):
|
|
|
|
return message.text in text
|
|
|
|
|
|
|
|
# SimpleCustomFilter is for boolean values, such as is_admin=True
|
2021-09-12 19:36:23 +03:00
|
|
|
class IsAdmin(telebot.custom_filters.SimpleCustomFilter):
|
2021-09-11 22:21:35 +03:00
|
|
|
key='is_admin'
|
|
|
|
@staticmethod
|
|
|
|
def check(message: telebot.types.Message):
|
2021-09-12 17:38:54 +03:00
|
|
|
return bot.get_chat_member(message.chat.id,message.from_user.id).status in ['administrator','creator']
|
2021-09-11 22:21:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(is_admin=True, commands=['admin']) # Check if user is admin
|
|
|
|
def admin_rep(message):
|
|
|
|
bot.send_message(message.chat.id, "Hi admin")
|
|
|
|
|
|
|
|
@bot.message_handler(is_admin=False, commands=['admin']) # If user is not admin
|
|
|
|
def not_admin(message):
|
|
|
|
bot.send_message(message.chat.id, "You are not admin")
|
|
|
|
|
|
|
|
@bot.message_handler(text=['hi']) # Response to hi message
|
|
|
|
def welcome_hi(message):
|
|
|
|
bot.send_message(message.chat.id, 'You said hi')
|
|
|
|
|
|
|
|
@bot.message_handler(text=['bye']) # Response to bye message
|
|
|
|
def bye_user(message):
|
|
|
|
bot.send_message(message.chat.id, 'You said bye')
|
|
|
|
|
|
|
|
|
|
|
|
# Do not forget to register filters
|
2021-09-11 22:27:04 +03:00
|
|
|
bot.add_custom_filter(MainFilter())
|
|
|
|
bot.add_custom_filter(IsAdmin())
|
2021-09-11 22:21:35 +03:00
|
|
|
|
2021-09-28 19:17:09 +03:00
|
|
|
bot.infinity_polling(skip_pending=True) # Skip old updates
|