-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.py
57 lines (53 loc) · 3.04 KB
/
callbacks.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from functions import get_hometask
from db import get_login, get_password
from config import Q_NUM, LOG_CHAT_ID
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
def callbacks(app):
@app.on_callback_query()
async def callback_query(app, CallbackQuery):
data = CallbackQuery.data
user_id = CallbackQuery.from_user.id
if data.startswith('next_'):
n = int(data.split("_")[1])
info_message = await CallbackQuery.edit_message_text("Получение дз...")
try:
hometask = await get_hometask(get_login(user_id), get_password(user_id), Q_NUM, data)
except Exception as e:
await CallbackQuery.edit_message_text(f'Чет ошибка какая-то: {e}')
return
inlineKeyboard = [
[InlineKeyboardButton("на эту неделю", callback_data=f"start"),
InlineKeyboardButton("-->", callback_data=f"next_{n+1}")]
]
await CallbackQuery.edit_message_text(hometask, reply_markup=InlineKeyboardMarkup(inlineKeyboard))
await CallbackQuery.answer()
await app.send_message(LOG_CHAT_ID, f"User {user_id} (@{CallbackQuery.from_user.username}) got {data} hometask")
elif data.startswith('previous_'):
n = int(data.split("_")[1])
info_message = await CallbackQuery.edit_message_text("Получение дз...")
try:
hometask = await get_hometask(get_login(user_id), get_password(user_id), Q_NUM, data)
except Exception as e:
await CallbackQuery.edit_message_text(f'Чет ошибка какая-то: {e}')
return
inlineKeyboard = [
[InlineKeyboardButton("<--", callback_data=f"previous_{n+1}"),
InlineKeyboardButton("на эту неделю", callback_data=f"start")]
]
await CallbackQuery.edit_message_text(hometask, reply_markup=InlineKeyboardMarkup(inlineKeyboard))
await CallbackQuery.answer()
await app.send_message(LOG_CHAT_ID, f"User {user_id} (@{CallbackQuery.from_user.username}) got {data} hometask")
elif data == 'start':
info_message = await CallbackQuery.edit_message_text("Получение дз...")
try:
hometask = await get_hometask(get_login(user_id), get_password(user_id), Q_NUM, data)
except Exception as e:
await CallbackQuery.edit_message_text(f'Чет ошибка какая-то: {e}')
return
inlineKeyboard = [
[InlineKeyboardButton("<--", callback_data=f"previous_1"),
InlineKeyboardButton("-->", callback_data=f"next_1")]
]
await CallbackQuery.edit_message_text(hometask, reply_markup=InlineKeyboardMarkup(inlineKeyboard))
await CallbackQuery.answer()
await app.send_message(LOG_CHAT_ID, f"User {user_id} (@{CallbackQuery.from_user.username}) got hometask")