55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import asyncio
|
|
|
|
from aiogram.types import CallbackQuery, Message
|
|
from aiogram_dialog import DialogManager
|
|
from aiogram_dialog.widgets.input import MessageInput
|
|
from aiogram_dialog.widgets.kbd import Button
|
|
|
|
from app.infrastructure.database.crud import get_users
|
|
|
|
|
|
async def message_data(
|
|
message: Message,
|
|
widget: MessageInput,
|
|
manager: DialogManager,
|
|
):
|
|
manager.dialog_data["message"] = message
|
|
await manager.next()
|
|
|
|
|
|
async def choose_recipients(
|
|
callback: CallbackQuery,
|
|
button: Button,
|
|
manager: DialogManager,
|
|
):
|
|
manager.dialog_data["recipients"] = button.widget_id
|
|
await manager.next()
|
|
|
|
|
|
async def confirm_mailing(
|
|
callback: CallbackQuery,
|
|
button: Button,
|
|
manager: DialogManager,
|
|
):
|
|
print(manager.dialog_data["recipients"])
|
|
users = list(await get_users(
|
|
manager.middleware_data["session"],
|
|
exclude_admins=manager.dialog_data["recipients"] == "send_users",
|
|
))
|
|
|
|
await asyncio.gather(
|
|
*[
|
|
callback.bot.copy_message(
|
|
chat_id=user.tg_id,
|
|
from_chat_id=manager.dialog_data["message"].chat.id,
|
|
message_id=manager.dialog_data["message"].message_id,
|
|
)
|
|
for user in users
|
|
]
|
|
)
|
|
await callback.bot.send_message(
|
|
chat_id=callback.from_user.id,
|
|
text=f"Разослано сообщений: {len(users)}",
|
|
)
|
|
await manager.done()
|