From a251e101d5d43d9a976e55227c06d03c8e093be5 Mon Sep 17 00:00:00 2001 From: kitiketov Date: Tue, 9 Dec 2025 20:42:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BA=D0=BE=D1=80=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=B0=D1=81=D1=81=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B2=D0=B8=D0=B7=D1=83?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=8D=D1=84=D1=84=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/common.py | 16 ++++++++----- src/handlers/room_admin.py | 46 +++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/handlers/common.py b/src/handlers/common.py index a4b630d..0d797d6 100644 --- a/src/handlers/common.py +++ b/src/handlers/common.py @@ -1,15 +1,21 @@ from aiogram import F, Router -from aiogram.types import Message, CallbackQuery, ReactionTypeEmoji -from aiogram.filters import Command from aiogram.fsm.context import FSMContext +from aiogram.types import Message, CallbackQuery, ReactionTypeEmoji -import base64 -from src.db import db from src.keyboards import common_kb from src.states.states import CallbackFactory from src.texts import messages from src.texts.callback_actions import CallbackAction +EFFECT_IDS = { + '🔥': "5104841245755180586", + '👍': "5107584321108051014", + '👎': "5104858069142078462", + '❤️': "5044134455711629726", + '🎉': "5046509860389126442", + '💩': "5046589136895476101" +} + async def set_reaction(message: Message) -> None: """ @@ -34,7 +40,7 @@ async def get_room_name(room_iden): @router.callback_query(CallbackFactory.filter(F.action == CallbackAction.CANCEL)) async def cancel( - call: CallbackQuery, callback_data: CallbackFactory, state: FSMContext + call: CallbackQuery, callback_data: CallbackFactory, state: FSMContext ): if callback_data.room_iden == "None": await state.clear() diff --git a/src/handlers/room_admin.py b/src/handlers/room_admin.py index 700b3ad..f8bd47d 100644 --- a/src/handlers/room_admin.py +++ b/src/handlers/room_admin.py @@ -1,10 +1,15 @@ +import asyncio +import base64 + from aiogram import F, Router +from aiogram.exceptions import TelegramRetryAfter from aiogram.types import Message, CallbackQuery from aiogram.filters import Command from aiogram.fsm.context import FSMContext -import base64 +from src.config import logger from src.db import db +from src.handlers.common import EFFECT_IDS from src.keyboards import common_kb, room_admin_kb from src.states.states import CallbackFactory, RemoveCallbackFactory from src.texts import messages, text @@ -12,6 +17,9 @@ from src.utilities import utils +RATE_LIMIT_DELAY = 0.05 + + async def get_room_name(room_iden): return f"{room_iden[:-4]}:{room_iden[-4:]}" @@ -152,8 +160,34 @@ async def start_event( ) for user_id in members: - await call.bot.send_message( - chat_id=user_id, - text=messages.event_started_notify(room_name), - reply_markup=await common_kb.ok_kb("None", asAdmin=False), - ) + try: + await call.bot.send_message( + chat_id=user_id, + text=messages.event_started_notify(room_name), + reply_markup=await common_kb.ok_kb("None", asAdmin=False), + message_effect_id=EFFECT_IDS["🎉"], + ) + except TelegramRetryAfter as e: + await asyncio.sleep(e.retry_after) + try: + await call.bot.send_message( + chat_id=user_id, + text=messages.event_started_notify(room_name), + reply_markup=await common_kb.ok_kb("None", asAdmin=False), + message_effect_id=EFFECT_IDS["🎉"], + ) + except Exception as retry_error: + logger.warning( + "Failed to notify user %s in room %s after retry: %s", + user_id, + callback_data.room_iden, + retry_error, + ) + except Exception as e: + logger.warning( + "Failed to notify user %s in room %s: %s", + user_id, + callback_data.room_iden, + e, + ) + await asyncio.sleep(RATE_LIMIT_DELAY)