aboutsummaryrefslogtreecommitdiff
path: root/libs/msg.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/msg.py')
-rw-r--r--libs/msg.py37
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
2from typing import AsyncGenerator, Iterable 2from typing import AsyncGenerator, Iterable
3 3
4from aiogram import Bot 4from aiogram import Bot
5from aiogram.enums import ButtonStyle
5from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter 6from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter
7from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
6 8
7from models import RichText 9from models import RichText
10from models.callback_data import PayInvoiceData
8 11
9 12
10async def publish( 13async 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
31async 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