aboutsummaryrefslogtreecommitdiff
path: root/handlers/user/announcements.py
diff options
context:
space:
mode:
authorTolmachev Igor <me@igorek.dev>2026-03-26 16:23:52 +0300
committerTolmachev Igor <me@igorek.dev>2026-03-26 16:23:52 +0300
commit9c905f22de4fa2e2f60ea9d473c14cb075a244e2 (patch)
tree366fa6c5fb5bbe1d29e383effa7df816cadf22a4 /handlers/user/announcements.py
parent4d0f8a48502dfa6bc7e9b39444573fe7377bdfce (diff)
downloadvpn_manager_bot-9c905f22de4fa2e2f60ea9d473c14cb075a244e2.tar.gz
vpn_manager_bot-9c905f22de4fa2e2f60ea9d473c14cb075a244e2.zip
Add invoices command
Diffstat (limited to 'handlers/user/announcements.py')
-rw-r--r--handlers/user/announcements.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/handlers/user/announcements.py b/handlers/user/announcements.py
index 8f4aa43..dc85b54 100644
--- a/handlers/user/announcements.py
+++ b/handlers/user/announcements.py
@@ -16,11 +16,17 @@ router = Router(name="announcements")
16PAGE_SIZE = 5 16PAGE_SIZE = 5
17 17
18 18
19async def get_reply_markup(page: int, session: AsyncSession) -> InlineKeyboardMarkup: 19async def get_reply_markup(
20 page: int,
21 session: AsyncSession,
22) -> InlineKeyboardMarkup | None:
20 total = await session.scalar(select(count()).select_from(Announcement)) 23 total = await session.scalar(select(count()).select_from(Announcement))
21 assert total is not None 24 assert total is not None
22 total_pages = ceil(total / PAGE_SIZE) 25 total_pages = ceil(total / PAGE_SIZE)
23 26
27 if total == 0:
28 return None
29
24 page = max(0, min(page, total_pages - 1)) 30 page = max(0, min(page, total_pages - 1))
25 query = ( 31 query = (
26 select(Announcement) 32 select(Announcement)
@@ -64,10 +70,13 @@ async def get_reply_markup(page: int, session: AsyncSession) -> InlineKeyboardMa
64 70
65@router.message(Command("announcements")) 71@router.message(Command("announcements"))
66async def command(msg: Message, bot: Bot, session: AsyncSession) -> None: 72async def command(msg: Message, bot: Bot, session: AsyncSession) -> None:
67 await msg.answer( 73 reply_markup = await get_reply_markup(0, session)
68 "Выберете анонс для просмотра.", 74
69 reply_markup=await get_reply_markup(0, session), 75 if reply_markup is None:
70 ) 76 await msg.answer("Нету анонсов для просмотра.")
77 return
78
79 await msg.answer("Выберете анонс для просмотра.", reply_markup=reply_markup)
71 80
72 81
73@router.callback_query(AnnouncePageClb.filter()) 82@router.callback_query(AnnouncePageClb.filter())
@@ -80,7 +89,7 @@ async def page(
80 89
81 reply_markup = await get_reply_markup(callback_data.page, session) 90 reply_markup = await get_reply_markup(callback_data.page, session)
82 await clb.message.edit_text( 91 await clb.message.edit_text(
83 "Выберете анонс для просмотра.", 92 "Выберете анонс для просмотра:",
84 reply_markup=reply_markup, 93 reply_markup=reply_markup,
85 ) 94 )
86 95