Telezab/app/bot/keyboards/active_triggers.py
UdoChudo ccb47d527f
All checks were successful
Build and Push Docker Images / build (push) Successful in 1m28s
refactor: modularize Telegram bot and add RabbitMQ client foundation
- Рефакторинг Telegram бота на модульную структуру для удобства поддержки и расширения
- Создан общий RabbitMQ клиент для Flask и Telegram компонентов
- Подготовлена базовая архитектура для будущего масштабирования и новых функций

Signed-off-by: UdoChudo <stream@udochudo.ru>
2025-06-16 09:08:46 +05:00

40 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
from config import REGIONS_PER_PAGE
def create_region_keyboard(regions, page, page_size=REGIONS_PER_PAGE):
markup = InlineKeyboardMarkup(row_width=2)
start = page * page_size
end = start + page_size
page_regions = regions[start:end]
for region in page_regions:
region_id_str = f"{region['id']:02d}" # 2 цифры, с ведущими нулями
button_text = f"{region['id']:02d}: {region['name']}"
button = InlineKeyboardButton(text=button_text, callback_data=f"region_{region_id_str}")
markup.add(button)
# Пагинация
navigation_buttons = []
if page > 0:
navigation_buttons.append(InlineKeyboardButton("⬅️", callback_data=f"regions_page_{page - 1}"))
if end < len(regions):
navigation_buttons.append(InlineKeyboardButton("➡️", callback_data=f"regions_page_{page + 1}"))
if navigation_buttons:
markup.add(*navigation_buttons)
# Кнопка отмены в самый низ
cancel_button = InlineKeyboardButton("Отмена", callback_data="cancel_input")
markup.add(cancel_button)
return markup
def create_group_keyboard(groups, region_id):
markup = InlineKeyboardMarkup()
for group in groups:
markup.add(InlineKeyboardButton(text=group['name'], callback_data=f"group_{group['groupid']}"))
markup.add(InlineKeyboardButton(text="Все группы региона\n(Долгое выполнение)", callback_data=f"all_groups_{region_id}"))
return markup