-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
28 lines (21 loc) · 1016 Bytes
/
utils.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
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, User
from models import Like
def format_text(user: User, text):
return '{0}\nSender: {1} {2}'.format(text or '', user.first_name or '', user.last_name or '')
def get_button(data, text, like_count):
if like_count:
button_text = '{0} {1}'.format(text, like_count)
else:
button_text = text
return InlineKeyboardButton(button_text, callback_data=data)
def get_reply_markup(like_dict=None):
if like_dict and isinstance(like_dict, dict):
return InlineKeyboardMarkup([
[get_button(data, text, like_dict.get(data)) for data, text in Like.BUTTON_LABELS[:2]],
[get_button(data, text, like_dict.get(data)) for data, text in Like.BUTTON_LABELS[2:]]
])
else:
return InlineKeyboardMarkup([
[get_button(data, text, None) for data, text in Like.BUTTON_LABELS[:2]],
[get_button(data, text, None) for data, text in Like.BUTTON_LABELS[2:]]
])