1
|
|
|
"""Processing inline buttons calls received from telegram bot""" |
2
|
|
|
|
3
|
|
|
from callbaker import info_from_callback |
4
|
|
|
from loglan_core import WordSelector |
5
|
|
|
|
6
|
|
|
from app.bot.telegram import bot, cbq |
7
|
|
|
from app.bot.telegram.keyboards import WordKeyboard |
8
|
|
|
from app.bot.telegram.models import export_as_str |
9
|
|
|
from app.bot.telegram.variables import Mark |
10
|
|
|
from app.decorators import logging_time |
11
|
|
|
from app.engine import async_session_maker |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
@logging_time |
15
|
|
|
async def bib_cancel(call: cbq): |
16
|
|
|
""" |
17
|
|
|
Обработка нажатия кнопки 'Отмена' |
18
|
|
|
:param call: |
19
|
|
|
:return: |
20
|
|
|
""" |
21
|
|
|
await bot.delete_message(call.message.chat.id, call.message.message_id) |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
@logging_time |
25
|
|
|
async def bib_predy_send_card(call: cbq): |
26
|
|
|
""" |
27
|
|
|
Обработка нажатия кнопки со logpua |
28
|
|
|
:param call: |
29
|
|
|
:return: |
30
|
|
|
""" |
31
|
|
|
info = info_from_callback(call.data) |
32
|
|
|
uid = call.message.chat.id |
33
|
|
|
|
34
|
|
|
async with async_session_maker() as session: |
35
|
|
|
word = await ( |
36
|
|
|
WordSelector() |
37
|
|
|
.filter_by(id=info[Mark.record_id]) |
38
|
|
|
.with_relationships() |
39
|
|
|
.scalar_async(session) |
40
|
|
|
) |
41
|
|
|
await bot.send_message( |
42
|
|
|
chat_id=uid, |
43
|
|
|
text=export_as_str(word), |
44
|
|
|
reply_markup=WordKeyboard(word).keyboard_cpx(), |
45
|
|
|
) |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@logging_time |
49
|
|
|
async def bib_predy_kb_cpx_switcher(call: cbq): |
50
|
|
|
""" |
51
|
|
|
Обработка нажатия кнопки отображения/скрытия комплексных слов |
52
|
|
|
:param call: |
53
|
|
|
:return: |
54
|
|
|
""" |
55
|
|
|
info = info_from_callback(call.data) |
56
|
|
|
slice_start = info.pop(Mark.slice_start, 0) |
57
|
|
|
action = info.pop(Mark.action, "") |
58
|
|
|
|
59
|
|
|
async with async_session_maker() as session: |
60
|
|
|
word = await ( |
61
|
|
|
WordSelector() |
62
|
|
|
.filter_by(id=info[Mark.record_id]) |
63
|
|
|
.with_relationships() |
64
|
|
|
.scalar_async(session) |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
keyboard = WordKeyboard(word).keyboard_cpx( |
68
|
|
|
action=action, slice_start=slice_start |
69
|
|
|
) |
70
|
|
|
|
71
|
|
|
await bot.edit_message_reply_markup( |
72
|
|
|
chat_id=call.from_user.id, |
73
|
|
|
message_id=call.message.message_id, |
74
|
|
|
reply_markup=keyboard, |
75
|
|
|
) |
76
|
|
|
|