Total Complexity | 4 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding:utf-8 -*- |
||
2 | """ |
||
3 | Telegram bot messages functions |
||
4 | """ |
||
5 | from loglan_core import WordSelector |
||
6 | |||
7 | from app.bot.telegram import bot, msg |
||
8 | from app.bot.telegram.handlers.commands import send_message_by_key |
||
9 | from app.bot.telegram.keyboards import WordKeyboard |
||
10 | from app.bot.telegram.models import export_as_str |
||
11 | from app.engine import Session |
||
12 | |||
13 | |||
14 | async def bot_text_messages_handler(message: msg) -> None: |
||
15 | """ |
||
16 | Handle user's text messages |
||
17 | :param message: |
||
18 | :return: None |
||
19 | """ |
||
20 | |||
21 | user_request = message.text.removeprefix("/") |
||
22 | with Session() as session: |
||
23 | words = WordSelector().by_name(user_request).with_relationships().all(session) |
||
24 | |||
25 | if words: |
||
26 | for word in words: |
||
27 | await bot.send_message( |
||
28 | chat_id=message.chat.id, |
||
29 | text=export_as_str(word), |
||
30 | reply_markup=WordKeyboard(word).keyboard_cpx(), |
||
31 | ) |
||
32 | else: |
||
33 | await send_message_by_key(user_request, message.chat.id) |
||
34 |