SHOW:
|
|
- or go back to the newest paste.
| 1 | import telebot | |
| 2 | import config | |
| 3 | import random | |
| 4 | ||
| 5 | from telebot import types | |
| 6 | ||
| 7 | bot = telebot.TeleBot(config.TOKEN) | |
| 8 | ||
| 9 | @bot.message_handler(commands=['start']) | |
| 10 | def welcome(message): | |
| 11 | sti = open('static/welcome.webp', 'rb')
| |
| 12 | bot.send_sticker(message.chat.id, sti) | |
| 13 | ||
| 14 | # keyboard | |
| 15 | markup = types.ReplyKeyboardMarkup(resize_keyboard=True) | |
| 16 | item1 = types.KeyboardButton("🎲 Рандомное число")
| |
| 17 | item2 = types.KeyboardButton("😊 Как дела?")
| |
| 18 | ||
| 19 | markup.add(item1, item2) | |
| 20 | ||
| 21 | bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот созданный чтобы быть подопытным кроликом.".format(message.from_user, bot.get_me()),
| |
| 22 | parse_mode='html', reply_markup=markup) | |
| 23 | ||
| 24 | @bot.message_handler(content_types=['text']) | |
| 25 | def lalala(message): | |
| 26 | if message.chat.type == 'private': | |
| 27 | if message.text == '🎲 Рандомное число': | |
| 28 | bot.send_message(message.chat.id, str(random.randint(0,100))) | |
| 29 | elif message.text == '😊 Как дела?': | |
| 30 | ||
| 31 | markup = types.InlineKeyboardMarkup(row_width=2) | |
| 32 | item1 = types.InlineKeyboardButton("Хорошо", callback_data='good')
| |
| 33 | item2 = types.InlineKeyboardButton("Не очень", callback_data='bad')
| |
| 34 | ||
| 35 | markup.add(item1, item2) | |
| 36 | ||
| 37 | bot.send_message(message.chat.id, 'Отлично, сам как?', reply_markup=markup) | |
| 38 | else: | |
| 39 | bot.send_message(message.chat.id, 'Я не знаю что ответить 😢') | |
| 40 | ||
| 41 | @bot.callback_query_handler(func=lambda call: True) | |
| 42 | def callback_inline(call): | |
| 43 | try: | |
| 44 | if call.message: | |
| 45 | if call.data == 'good': | |
| 46 | bot.send_message(call.message.chat.id, 'Вот и отличненько 😊') | |
| 47 | elif call.data == 'bad': | |
| 48 | bot.send_message(call.message.chat.id, 'Бывает 😢') | |
| 49 | ||
| 50 | # remove inline buttons | |
| 51 | bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="😊 Как дела?", | |
| 52 | reply_markup=None) | |
| 53 | ||
| 54 | # show alert | |
| 55 | bot.answer_callback_query(callback_query_id=call.id, show_alert=False, | |
| 56 | text="ЭТО ТЕСТОВОЕ УВЕДОМЛЕНИЕ!!11") | |
| 57 | ||
| 58 | except Exception as e: | |
| 59 | print(repr(e)) | |
| 60 | ||
| 61 | # RUN | |
| 62 | bot.polling(none_stop=True) |