From d5994e732d7b1dfa469cf400132ba49c8f75315e Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Mon, 23 Mar 2026 18:40:40 +0300 Subject: Add new_invoice command --- libs/msg.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'libs') 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 from typing import AsyncGenerator, Iterable from aiogram import Bot +from aiogram.enums import ButtonStyle from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter +from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup from models import RichText +from models.callback_data import PayInvoiceData -async def publish( +async def publish_announcement( bot: Bot, users: Iterable[int], rich_text: RichText, @@ -23,3 +26,35 @@ async def publish( await asyncio.sleep(5) yield n + + +async def send_invoice( + bot: Bot, + users: Iterable[int], + rich_text: RichText, + invoice_id: int, +) -> AsyncGenerator[int]: + callback_data = PayInvoiceData(invoice_id=invoice_id).pack() + reply_markup = InlineKeyboardMarkup( + inline_keyboard=[ + [ + InlineKeyboardButton( + text="Оплатить", + style=ButtonStyle.PRIMARY, + callback_data=callback_data, + ) + ] + ] + ) + + for n, user_id in enumerate(users, start=1): + for _ in range(5): + try: + await rich_text.send(bot, user_id, reply_markup=reply_markup) + break + except TelegramRetryAfter as e: + await asyncio.sleep(e.retry_after + 1) + except TelegramAPIError: + await asyncio.sleep(5) + + yield n -- cgit v1.3