feat: групповые уведомления о добавлении счетов с копируемым форматом
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
@@ -87,13 +87,14 @@ async def process_single_account(message: Message, club_card: str, account_numbe
|
||||
if owner:
|
||||
text += f"👤 Владелец: {owner.first_name}\n\n"
|
||||
|
||||
# Отправляем уведомление владельцу
|
||||
# Отправляем уведомление владельцу с форматированием
|
||||
try:
|
||||
await message.bot.send_message(
|
||||
owner.telegram_id,
|
||||
f"✅ К вашему профилю добавлен счет:\n\n"
|
||||
f"💳 {account_number}\n\n"
|
||||
f"Теперь вы можете участвовать в розыгрышах с этим счетом!"
|
||||
f"💳 `{account_number}`\n\n"
|
||||
f"Теперь вы можете участвовать в розыгрышах!",
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
text += "📨 Владельцу отправлено уведомление\n\n"
|
||||
except Exception as e:
|
||||
@@ -156,12 +157,6 @@ async def process_accounts_data(message: Message, state: FSMContext):
|
||||
errors.append(f"Строка {i}: некорректный номер карты после счета {account_number}")
|
||||
i += 1
|
||||
continue
|
||||
club_card = lines[i].strip()
|
||||
# Пропускаем, если следующая строка содержит мусор
|
||||
if not club_card or any(x in club_card.lower() for x in ['viposnova', '0.00', ':']):
|
||||
errors.append(f"Строка {i}: некорректный номер карты после счета {account_number}")
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Создаем счет
|
||||
try:
|
||||
@@ -178,20 +173,9 @@ async def process_accounts_data(message: Message, state: FSMContext):
|
||||
'club_card': club_card,
|
||||
'account_number': account_number,
|
||||
'account_id': account.id,
|
||||
'owner': owner
|
||||
'owner': owner,
|
||||
'owner_id': owner.telegram_id if owner else None
|
||||
})
|
||||
|
||||
# Отправляем уведомление владельцу
|
||||
if owner:
|
||||
try:
|
||||
await message.bot.send_message(
|
||||
owner.telegram_id,
|
||||
f"✅ К вашему профилю добавлен счет:\n\n"
|
||||
f"💳 {account_number}\n\n"
|
||||
f"Теперь вы можете участвовать в розыгрышах!"
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
except ValueError as e:
|
||||
errors.append(f"Счет {account_number} (карта {club_card}): {str(e)}")
|
||||
@@ -200,6 +184,43 @@ async def process_accounts_data(message: Message, state: FSMContext):
|
||||
|
||||
i += 1
|
||||
|
||||
# Группируем счета по владельцам и отправляем групповые уведомления
|
||||
if accounts_data:
|
||||
from collections import defaultdict
|
||||
accounts_by_owner = defaultdict(list)
|
||||
|
||||
for acc in accounts_data:
|
||||
if acc['owner_id']:
|
||||
accounts_by_owner[acc['owner_id']].append(acc['account_number'])
|
||||
|
||||
# Отправляем групповые уведомления
|
||||
for owner_id, account_numbers in accounts_by_owner.items():
|
||||
try:
|
||||
if len(account_numbers) == 1:
|
||||
# Одиночное уведомление
|
||||
notification_text = (
|
||||
"✅ К вашему профилю добавлен счет:\n\n"
|
||||
f"💳 `{account_numbers[0]}`\n\n"
|
||||
"Теперь вы можете участвовать в розыгрышах!"
|
||||
)
|
||||
else:
|
||||
# Групповое уведомление
|
||||
notification_text = (
|
||||
f"✅ К вашему профилю добавлено счетов: *{len(account_numbers)}*\n\n"
|
||||
"💳 *Ваши счета:*\n"
|
||||
)
|
||||
for acc_num in account_numbers:
|
||||
notification_text += f"• `{acc_num}`\n"
|
||||
notification_text += "\nТеперь вы можете участвовать в розыгрышах!"
|
||||
|
||||
await message.bot.send_message(
|
||||
owner_id,
|
||||
notification_text,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
except Exception as e:
|
||||
pass # Игнорируем ошибки отправки уведомлений
|
||||
|
||||
# Формируем отчет
|
||||
text = f"📊 **Результаты добавления счетов**\n\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user