fix: заменить HTML на Markdown, добавить safe_edit_message для обработки 'message is not modified'
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
@@ -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"⚠️ <b>Подтверждение проведения розыгрыша</b>\n\n"
|
||||
text += f"🎲 <b>Розыгрыш:</b> {lottery.title}\n"
|
||||
text += f"👥 <b>Участников:</b> {participants_count}\n"
|
||||
text += f"🏆 <b>Призов:</b> {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 += "<b>Призы:</b>\n"
|
||||
text += "*Призы:*\n"
|
||||
for i, prize in enumerate(lottery.prizes, 1):
|
||||
text += f"{i}. {prize}\n"
|
||||
text += "\n"
|
||||
|
||||
text += "❗️ <b>Внимание:</b> После проведения розыгрыша результаты нельзя будет изменить!\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_"))
|
||||
|
||||
Reference in New Issue
Block a user