-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelebot1.py
43 lines (30 loc) · 1.26 KB
/
telebot1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import telebot
from telebot import types, util
from parse_anekdot import parse_anekdots, ANEKDOT_TYPE, STORY_TYPE
token = os.environ.get('API_TELEBOT', '')
bot = telebot.TeleBot(token)
markup = types.InlineKeyboardMarkup()
markup.row_width = 2
markup.add(types.InlineKeyboardButton("Анекдоты", callback_data=ANEKDOT_TYPE),
types.InlineKeyboardButton("Истории", callback_data=STORY_TYPE),
types.InlineKeyboardButton("Raise error", callback_data="error"),
)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.send_message(message.chat.id, "Choose type:", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
if call.data == 'error':
raise RuntimeError()
else:
bot.answer_callback_query(call.id, "Loading...")
content = parse_anekdots(call.data)
splitted_text = util.smart_split(content, chars_per_string=3000)
for text in splitted_text:
bot.send_message(call.from_user.id, text)
bot.send_message(call.from_user.id, "Choose type:", reply_markup=markup)
@bot.message_handler(commands=['test'])
def send_welcome(message):
bot.reply_to(message, "works")
bot.infinity_polling()