Passed
Push — master ( 449b8d...1f3828 )
by torrua
01:12
created

app.bot.telegram.handlers.bib_functions   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 35
dl 0
loc 78
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A bib_predy_kb_cpx_show() 0 8 1
A bib_predy_send_card() 0 13 3
A bib_predy_kb_cpx_hide() 0 8 1
A bib_predy_kb_cpx_switcher() 0 19 2
A bib_cancel() 0 8 1
1
# -*- coding: utf-8 -*-
2
"""Processing inline buttons calls received from telegram bot"""
3
4
from callbaker import info_from_callback
5
6
from app.bot.telegram import bot, cbq
7
from app.decorators import logging_time
8
from app.bot.telegram.models import TelegramWord as Word
9
from app.engine import Session
10
from app.bot.telegram.variables import mark_record_id, mark_slice_start
11
12
13
@logging_time
14
def bib_cancel(call: cbq):
15
    """
16
    Обработка нажатия кнопки 'Отмена'
17
    :param call:
18
    :return:
19
    """
20
    bot.delete_message(call.message.chat.id, call.message.message_id)
21
22
23
@logging_time
24
def bib_predy_send_card(call: cbq):
25
    """
26
    Обработка нажатия кнопки со словом на логлане
27
    :param call:
28
    :return:
29
    """
30
    info = info_from_callback(call.data)
31
    uid = call.message.chat.id
32
    with Session() as session:
33
        words = Word.by_request(session, info[mark_record_id])
34
        for word in words:
35
            word.send_card_to_user(session, bot, uid)
36
37
38
@logging_time
39
def bib_predy_kb_cpx_switcher(call: cbq, state: bool):
40
    """
41
    Обработка нажатия кнопки отображения/скрытия комплексных слов
42
    :param call:
43
    :param state:
44
    :return:
45
    """
46
    info = info_from_callback(call.data)
47
    slice_start = info.pop(mark_slice_start, 0)
48
49
    with Session() as session:
50
        word = Word.get_by_id(session, info[mark_record_id])
51
        keyboard = word.keyboard_cpx(show_list=state, slice_start=slice_start)
52
53
    bot.edit_message_reply_markup(
54
        chat_id=call.from_user.id,
55
        message_id=call.message.message_id,
56
        reply_markup=keyboard,
57
    )
58
59
60
@logging_time
61
def bib_predy_kb_cpx_show(call: cbq):
62
    """
63
    Обработка нажатия кнопки отображения комплексных слов
64
    :param call:
65
    :return:
66
    """
67
    bib_predy_kb_cpx_switcher(call, True)
68
69
70
@logging_time
71
def bib_predy_kb_cpx_hide(call: cbq):
72
    """
73
    Обработка нажатия кнопки скрытия комплексных слов
74
    :param call:
75
    :return:
76
    """
77
    bib_predy_kb_cpx_switcher(call, False)
78