Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/handlers/common.py
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand All @@ -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()
Expand Down
46 changes: 40 additions & 6 deletions src/handlers/room_admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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
from src.texts.callback_actions import CallbackAction
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:]}"

Expand Down Expand Up @@ -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)