diff --git a/src/handlers/admin_panel.py b/src/handlers/admin_panel.py
index 5a339ad..628601e 100644
--- a/src/handlers/admin_panel.py
+++ b/src/handlers/admin_panel.py
@@ -22,6 +22,32 @@ from ..core.models import User, Lottery, Participation, Account
logger = logging.getLogger(__name__)
+async def safe_edit_message(
+ callback: CallbackQuery,
+ text: str,
+ reply_markup: InlineKeyboardMarkup | None = None,
+ parse_mode: str = "Markdown"
+) -> bool:
+ """
+ Безопасное редактирование сообщения с обработкой ошибки 'message is not modified'
+
+ Returns:
+ bool: True если сообщение отредактировано, False если не изменилось
+ """
+ try:
+ await callback.message.edit_text(
+ text,
+ reply_markup=reply_markup,
+ parse_mode=parse_mode
+ )
+ return True
+ except TelegramBadRequest as e:
+ if "message is not modified" in str(e):
+ await callback.answer("Сообщение уже актуально", show_alert=False)
+ return False
+ raise
+
+
# Состояния для админки
class AdminStates(StatesGroup):
# Создание розыгрыша
@@ -2623,18 +2649,18 @@ async def conduct_lottery_draw_confirm(callback: CallbackQuery):
prizes_count = len(lottery.prizes) if lottery.prizes else 0
# Формируем сообщение с подтверждением
- text = f"⚠️ Подтверждение проведения розыгрыша\n\n"
- text += f"🎲 Розыгрыш: {lottery.title}\n"
- text += f"👥 Участников: {participants_count}\n"
- text += f"🏆 Призов: {prizes_count}\n\n"
+ text = f"⚠️ *Подтверждение проведения розыгрыша*\n\n"
+ text += f"🎲 *Розыгрыш:* {lottery.title}\n"
+ text += f"👥 *Участников:* {participants_count}\n"
+ text += f"🏆 *Призов:* {prizes_count}\n\n"
if lottery.prizes:
- text += "Призы:\n"
+ text += "*Призы:*\n"
for i, prize in enumerate(lottery.prizes, 1):
text += f"{i}. {prize}\n"
text += "\n"
- text += "❗️ Внимание: После проведения розыгрыша результаты нельзя будет изменить!\n\n"
+ text += "❗️ *Внимание:* После проведения розыгрыша результаты нельзя будет изменить!\n\n"
text += "Продолжить?"
buttons = [
@@ -2642,13 +2668,7 @@ async def conduct_lottery_draw_confirm(callback: CallbackQuery):
[InlineKeyboardButton(text="❌ Отмена", callback_data=f"admin_lottery_{lottery_id}")]
]
- try:
- await callback.message.edit_text(text, reply_markup=InlineKeyboardMarkup(inline_keyboard=buttons))
- except TelegramBadRequest as e:
- if "message is not modified" in str(e):
- await callback.answer("Сообщение уже актуально", show_alert=False)
- else:
- raise
+ await safe_edit_message(callback, text, InlineKeyboardMarkup(inline_keyboard=buttons))
@admin_router.callback_query(F.data.startswith("admin_conduct_confirmed_"))