diff options
| author | Tolmachev Igor <me@igorek.dev> | 2026-03-23 18:40:40 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2026-03-23 18:40:40 +0300 |
| commit | d5994e732d7b1dfa469cf400132ba49c8f75315e (patch) | |
| tree | a091b84babf7829ae6193d78fb8dc090336b0f9b /libs | |
| parent | f7b7e87cffc9dcb2817b070d7a003ac234c96ec3 (diff) | |
| download | vpn_manager_bot-d5994e732d7b1dfa469cf400132ba49c8f75315e.tar.gz vpn_manager_bot-d5994e732d7b1dfa469cf400132ba49c8f75315e.zip | |
Add new_invoice command
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/msg.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/libs/msg.py b/libs/msg.py index 9bcc52a..05bddfc 100644 --- a/libs/msg.py +++ b/libs/msg.py | |||
| @@ -2,12 +2,15 @@ import asyncio | |||
| 2 | from typing import AsyncGenerator, Iterable | 2 | from typing import AsyncGenerator, Iterable |
| 3 | 3 | ||
| 4 | from aiogram import Bot | 4 | from aiogram import Bot |
| 5 | from aiogram.enums import ButtonStyle | ||
| 5 | from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter | 6 | from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter |
| 7 | from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup | ||
| 6 | 8 | ||
| 7 | from models import RichText | 9 | from models import RichText |
| 10 | from models.callback_data import PayInvoiceData | ||
| 8 | 11 | ||
| 9 | 12 | ||
| 10 | async def publish( | 13 | async def publish_announcement( |
| 11 | bot: Bot, | 14 | bot: Bot, |
| 12 | users: Iterable[int], | 15 | users: Iterable[int], |
| 13 | rich_text: RichText, | 16 | rich_text: RichText, |
| @@ -23,3 +26,35 @@ async def publish( | |||
| 23 | await asyncio.sleep(5) | 26 | await asyncio.sleep(5) |
| 24 | 27 | ||
| 25 | yield n | 28 | yield n |
| 29 | |||
| 30 | |||
| 31 | async def send_invoice( | ||
| 32 | bot: Bot, | ||
| 33 | users: Iterable[int], | ||
| 34 | rich_text: RichText, | ||
| 35 | invoice_id: int, | ||
| 36 | ) -> AsyncGenerator[int]: | ||
| 37 | callback_data = PayInvoiceData(invoice_id=invoice_id).pack() | ||
| 38 | reply_markup = InlineKeyboardMarkup( | ||
| 39 | inline_keyboard=[ | ||
| 40 | [ | ||
| 41 | InlineKeyboardButton( | ||
| 42 | text="Оплатить", | ||
| 43 | style=ButtonStyle.PRIMARY, | ||
| 44 | callback_data=callback_data, | ||
| 45 | ) | ||
| 46 | ] | ||
| 47 | ] | ||
| 48 | ) | ||
| 49 | |||
| 50 | for n, user_id in enumerate(users, start=1): | ||
| 51 | for _ in range(5): | ||
| 52 | try: | ||
| 53 | await rich_text.send(bot, user_id, reply_markup=reply_markup) | ||
| 54 | break | ||
| 55 | except TelegramRetryAfter as e: | ||
| 56 | await asyncio.sleep(e.retry_after + 1) | ||
| 57 | except TelegramAPIError: | ||
| 58 | await asyncio.sleep(5) | ||
| 59 | |||
| 60 | yield n | ||
