reminder-bot/bot/keyboards/reminders.py

243 lines
7.4 KiB
Python

"""Inline keyboards for reminder management."""
from typing import Optional, List
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from aiogram.filters.callback_data import CallbackData
# ==================== Callback Data Classes ====================
class ReminderIntervalCallback(CallbackData, prefix="interval"):
"""Callback for selecting reminder interval."""
days: int
class ReminderActionCallback(CallbackData, prefix="reminder"):
"""Callback for reminder actions."""
action: str # done, snooze, pause, resume, delete, details, edit
reminder_id: int
class ReminderEditCallback(CallbackData, prefix="edit"):
"""Callback for editing reminder fields."""
action: str # text, interval, time, back
reminder_id: int
class SnoozeDelayCallback(CallbackData, prefix="snooze"):
"""Callback for snooze delay selection."""
reminder_id: int
hours: int
class ConfirmCallback(CallbackData, prefix="confirm"):
"""Callback for confirmation actions."""
action: str # yes, no
entity: str # create, delete, etc.
entity_id: Optional[int] = None
# ==================== Keyboard Builders ====================
def get_interval_selection_keyboard() -> InlineKeyboardMarkup:
"""
Get keyboard for selecting reminder interval.
Returns:
InlineKeyboardMarkup with interval options
"""
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(
text="Каждый день",
callback_data=ReminderIntervalCallback(days=1).pack()
)],
[InlineKeyboardButton(
text="Каждые 2 дня",
callback_data=ReminderIntervalCallback(days=2).pack()
)],
[InlineKeyboardButton(
text="Каждые 3 дня",
callback_data=ReminderIntervalCallback(days=3).pack()
)],
[InlineKeyboardButton(
text="Другое...",
callback_data=ReminderIntervalCallback(days=0).pack()
)],
]
)
return keyboard
def get_confirmation_keyboard(
entity: str,
entity_id: Optional[int] = None
) -> InlineKeyboardMarkup:
"""
Get confirmation keyboard.
Args:
entity: Entity type (create, delete, etc.)
entity_id: Optional entity ID
Returns:
InlineKeyboardMarkup with yes/no buttons
"""
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[
InlineKeyboardButton(
text="✅ Подтвердить",
callback_data=ConfirmCallback(action="yes", entity=entity, entity_id=entity_id).pack()
),
InlineKeyboardButton(
text="❌ Отменить",
callback_data=ConfirmCallback(action="no", entity=entity, entity_id=entity_id).pack()
),
]
]
)
return keyboard
def get_reminder_notification_keyboard(reminder_id: int) -> InlineKeyboardMarkup:
"""
Get keyboard for reminder notification.
Args:
reminder_id: Reminder ID
Returns:
InlineKeyboardMarkup with action buttons
"""
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[
InlineKeyboardButton(
text="✅ Выполнено",
callback_data=ReminderActionCallback(action="done", reminder_id=reminder_id).pack()
),
],
[
InlineKeyboardButton(
text="🔁 Напомнить позже",
callback_data=ReminderActionCallback(action="snooze", reminder_id=reminder_id).pack()
),
],
[
InlineKeyboardButton(
text="⏸ Пауза",
callback_data=ReminderActionCallback(action="pause", reminder_id=reminder_id).pack()
),
InlineKeyboardButton(
text="🗑 Удалить",
callback_data=ReminderActionCallback(action="delete", reminder_id=reminder_id).pack()
),
],
]
)
return keyboard
def get_snooze_delay_keyboard(reminder_id: int) -> InlineKeyboardMarkup:
"""
Get keyboard for selecting snooze delay.
Args:
reminder_id: Reminder ID
Returns:
InlineKeyboardMarkup with delay options
"""
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(
text="Через 1 час",
callback_data=SnoozeDelayCallback(reminder_id=reminder_id, hours=1).pack()
)],
[InlineKeyboardButton(
text="Через 3 часа",
callback_data=SnoozeDelayCallback(reminder_id=reminder_id, hours=3).pack()
)],
[InlineKeyboardButton(
text="Завтра",
callback_data=SnoozeDelayCallback(reminder_id=reminder_id, hours=24).pack()
)],
]
)
return keyboard
def get_reminder_details_keyboard(reminder_id: int, is_active: bool) -> InlineKeyboardMarkup:
"""
Get keyboard for reminder details view.
Args:
reminder_id: Reminder ID
is_active: Whether reminder is active
Returns:
InlineKeyboardMarkup with action buttons
"""
pause_button = InlineKeyboardButton(
text="⏸ Пауза" if is_active else "▶️ Возобновить",
callback_data=ReminderActionCallback(
action="pause" if is_active else "resume",
reminder_id=reminder_id
).pack()
)
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[
InlineKeyboardButton(
text="✏️ Изменить",
callback_data=ReminderActionCallback(action="edit", reminder_id=reminder_id).pack()
),
],
[pause_button],
[
InlineKeyboardButton(
text="🗑 Удалить",
callback_data=ReminderActionCallback(action="delete", reminder_id=reminder_id).pack()
),
],
]
)
return keyboard
def get_edit_menu_keyboard(reminder_id: int) -> InlineKeyboardMarkup:
"""
Get keyboard for editing reminder.
Args:
reminder_id: Reminder ID
Returns:
InlineKeyboardMarkup with edit options
"""
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(
text="Изменить текст",
callback_data=ReminderEditCallback(action="text", reminder_id=reminder_id).pack()
)],
[InlineKeyboardButton(
text="Изменить период",
callback_data=ReminderEditCallback(action="interval", reminder_id=reminder_id).pack()
)],
[InlineKeyboardButton(
text="Изменить время",
callback_data=ReminderEditCallback(action="time", reminder_id=reminder_id).pack()
)],
[InlineKeyboardButton(
text="⬅️ Назад",
callback_data=ReminderEditCallback(action="back", reminder_id=reminder_id).pack()
)],
]
)
return keyboard