Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kb #82

Merged
merged 8 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions app/bot/telegram/handlers/bib_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from app.bot.telegram import bot, cbq
from app.bot.telegram.keyboards import WordKeyboard
from app.bot.telegram.models import export_as_str
from app.bot.telegram.variables import mark_record_id, mark_slice_start
from app.bot.telegram.variables import Mark
from app.decorators import logging_time
from app.engine import async_session_maker

Expand All @@ -24,7 +24,7 @@ async def bib_cancel(call: cbq):
@logging_time
async def bib_predy_send_card(call: cbq):
"""
Обработка нажатия кнопки со словом на логлане
Обработка нажатия кнопки со logpua
:param call:
:return:
"""
Expand All @@ -34,7 +34,7 @@ async def bib_predy_send_card(call: cbq):
async with async_session_maker() as session:
word = await (
WordSelector()
.filter_by(id=info[mark_record_id])
.filter_by(id=info[Mark.record_id])
.with_relationships()
.scalar_async(session)
)
Expand All @@ -46,50 +46,30 @@ async def bib_predy_send_card(call: cbq):


@logging_time
async def bib_predy_kb_cpx_switcher(call: cbq, state: bool):
async def bib_predy_kb_cpx_switcher(call: cbq):
"""
Обработка нажатия кнопки отображения/скрытия комплексных слов
:param call:
:param state:
:return:
"""
info = info_from_callback(call.data)
slice_start = info.pop(mark_slice_start, 0)
slice_start = info.pop(Mark.slice_start, 0)
action = info.pop(Mark.action, "")

async with async_session_maker() as session:
word = await (
WordSelector()
.filter_by(id=info[mark_record_id])
.filter_by(id=info[Mark.record_id])
.with_relationships()
.scalar_async(session)
)

keyboard = WordKeyboard(word).keyboard_cpx(
show_list=state, slice_start=slice_start
action=action, slice_start=slice_start
)

await bot.edit_message_reply_markup(
chat_id=call.from_user.id,
message_id=call.message.message_id,
reply_markup=keyboard,
)


@logging_time
async def bib_predy_kb_cpx_show(call: cbq):
"""
Обработка нажатия кнопки отображения комплексных слов
:param call:
:return:
"""
await bib_predy_kb_cpx_switcher(call, True)


@logging_time
async def bib_predy_kb_cpx_hide(call: cbq):
"""
Обработка нажатия кнопки скрытия комплексных слов
:param call:
:return:
"""
await bib_predy_kb_cpx_switcher(call, False)
27 changes: 10 additions & 17 deletions app/bot/telegram/handlers/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
from app.bot.telegram.handlers.bib_functions import bib_cancel
from app.bot.telegram.handlers.bib_functions import (
bib_predy_send_card,
bib_predy_kb_cpx_hide,
bib_predy_kb_cpx_show,
)
from app.bot.telegram.variables import (
action_predy_send_card,
action_predy_kb_cpx_hide,
action_predy_kb_cpx_show,
bib_predy_kb_cpx_switcher,
)

from app.bot.telegram.variables import (
Action,
cancel,
close,
mark_entity,
mark_action,
Mark,
entity_predy,
)
from app.decorators import logging_time
Expand All @@ -40,8 +35,8 @@ async def bot_callback_inline(call: cbq):
return

info = info_from_callback(call.data)
current_entity = info.get(mark_entity, None)
current_action = info.get(mark_action, None)
current_entity = info.get(Mark.entity, None)
current_action = info.get(Mark.action, None)

if not (current_entity and current_action):
return
Expand All @@ -56,7 +51,7 @@ async def entity_selector_general(call: cbq):
:return:
"""
info = info_from_callback(call.data)
current_entity = info.get(mark_entity, None)
current_entity = info.get(Mark.entity, None)

if current_entity == entity_predy:
await action_selector_predy(call)
Expand All @@ -69,13 +64,11 @@ async def action_selector_predy(call: cbq):
:return:
"""
info = info_from_callback(call.data)
current_action = info.get(mark_action, None)
current_action = info.get(Mark.action, None)

actions = {
action_predy_send_card: bib_predy_send_card,
action_predy_kb_cpx_hide: bib_predy_kb_cpx_hide,
action_predy_kb_cpx_show: bib_predy_kb_cpx_show,
Action.send_card: bib_predy_send_card,
}

if action_to_run := actions.get(current_action):
if action_to_run := actions.get(current_action, bib_predy_kb_cpx_switcher):
await action_to_run(call)
Loading
Loading