mailig skip blocked users
This commit is contained in:
@@ -26,29 +26,44 @@ async def choose_recipients(
|
|||||||
await manager.next()
|
await manager.next()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def confirm_mailing(
|
async def confirm_mailing(
|
||||||
callback: CallbackQuery,
|
callback: CallbackQuery,
|
||||||
button: Button,
|
button: Button,
|
||||||
manager: DialogManager,
|
manager: DialogManager,
|
||||||
):
|
):
|
||||||
print(manager.dialog_data["recipients"])
|
print(manager.dialog_data["recipients"])
|
||||||
|
|
||||||
users = list(await get_users(
|
users = list(await get_users(
|
||||||
manager.middleware_data["session"],
|
manager.middleware_data["session"],
|
||||||
exclude_admins=manager.dialog_data["recipients"] == "send_users",
|
exclude_admins=manager.dialog_data["recipients"] == "send_users",
|
||||||
))
|
))
|
||||||
|
|
||||||
await asyncio.gather(
|
message = manager.dialog_data["message"]
|
||||||
*[
|
source_chat_id = message.chat.id
|
||||||
callback.bot.copy_message(
|
source_message_id = message.message_id
|
||||||
|
|
||||||
|
success_count = 0
|
||||||
|
|
||||||
|
# Создаём задачу с обработкой ошибок для каждого пользователя
|
||||||
|
async def send_to_user(user):
|
||||||
|
nonlocal success_count
|
||||||
|
try:
|
||||||
|
await callback.bot.copy_message(
|
||||||
chat_id=user.tg_id,
|
chat_id=user.tg_id,
|
||||||
from_chat_id=manager.dialog_data["message"].chat.id,
|
from_chat_id=source_chat_id,
|
||||||
message_id=manager.dialog_data["message"].message_id,
|
message_id=source_message_id,
|
||||||
)
|
)
|
||||||
for user in users
|
success_count += 1
|
||||||
]
|
except Exception:
|
||||||
)
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
await asyncio.gather(*[send_to_user(user) for user in users])
|
||||||
|
|
||||||
await callback.bot.send_message(
|
await callback.bot.send_message(
|
||||||
chat_id=callback.from_user.id,
|
chat_id=callback.from_user.id,
|
||||||
text=f"Разослано сообщений: {len(users)}",
|
text=f"Рассылка завершена.\nУспешно отправлено: {success_count} из {len(users)}",
|
||||||
)
|
)
|
||||||
await manager.done()
|
await manager.done()
|
||||||
Reference in New Issue
Block a user