-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandlers.py
More file actions
45 lines (39 loc) · 1.68 KB
/
handlers.py
File metadata and controls
45 lines (39 loc) · 1.68 KB
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
44
45
from glob import glob
from random import choice
from utils import get_smile, play_random_numbers, main_keyboard
def greet_user(update, context):
print("Вызван /start")
context.user_data['emoji'] = get_smile(context.user_data)
update.message.reply_text(
f"Здравствуй, пользователь {context.user_data['emoji']}!",
reply_markup=main_keyboard()
)
def talk_to_me(update, context):
context.user_data['emoji'] = get_smile(context.user_data)
text = update.message.text
print(text)
my_keyboard = ReplyKeyboardMarkup([['Прислать котика']])
update.message.reply_text(f"{text} {context.user_data['emoji']}", reply_markup=main_keyboard())
def guess_number(update, context):
print(context.args)
if context.args:
try:
user_number = int(context.args[0])
message = play_random_numbers(user_number)
except (TypeError, ValueError):
message = "Введите целое число"
else:
message = "Введите число"
update.message.reply_text(message, reply_markup=main_keyboard())
def send_cat_picture(update, context):
cat_photo_list = glob('images/cat*.jp*g')
cat_photo_filename = choice(cat_photo_list)
chat_id = update.effective_chat.id
context.bot.send_photo(chat_id=chat_id, photo=open(cat_photo_filename, 'rb'), reply_markup=main_keyboard())
def user_coordinates(update, context):
context.user_data['emoji'] = get_smile(context.user_data)
coords = update.message.location
update.message.reply_text(
f"Ваши координаты {coords} {context.user_data['emoji']}!",
reply_markup=main_keyboard()
)