feat: add admin promotion broadcast system and psql health check
- Add `/push` command for admins to broadcast messages to all users with approve/decline confirmation flow (handlers/ads.py) - Add common handler for undefined commands and delete callback - Add `UserRepository.get_users()` to fetch all users - Add `UserService.send_promotion_to_users()` with error logging - Add promotion confirmation keyboard and FSM state - Add PostgreSQL availability check in startup.sh before migrations - Add new text constants for promotion flow
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.types import Message, ReactionTypeEmoji, User as TelegramUser
|
||||
from remnawave import RemnawaveSDK
|
||||
@@ -21,6 +23,8 @@ from texts import (
|
||||
TICKET_STATUS_EMOJIS,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class UserServiceError(Exception): ...
|
||||
|
||||
@@ -261,3 +265,16 @@ class UserService:
|
||||
ticket = await self.ticket_repository.get_ticket_by_thread_id(session, thread_id=thread_id)
|
||||
|
||||
return await self.user_repository.get_referal_by_user_id(session, ticket.creator_id)
|
||||
|
||||
async def send_promotion_to_users(self, session: AsyncSession, msg: Message) -> list[User]:
|
||||
users = await self.user_repository.get_users(session)
|
||||
|
||||
sent: list[User] = []
|
||||
for user in users:
|
||||
try:
|
||||
await msg.copy_to(user.id)
|
||||
sent.append(user)
|
||||
except Exception:
|
||||
logger.critical("failed to send a message to user %d.", user.id, exc_info=True)
|
||||
|
||||
return sent
|
||||
|
||||
Reference in New Issue
Block a user