Skip to content

Commit e3daa50

Browse files
Update GiftedPremium type to layer 217
Co-authored-by: KurimuzonAkuma <[email protected]>
1 parent 2084b37 commit e3daa50

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pyrogram/types/messages_and_media/gifted_premium.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from random import choice
2020
from typing import Optional
2121

22-
from pyrogram import raw, types
22+
from pyrogram import raw, types, utils
2323
from ..object import Object
2424
from .message import Str
2525

@@ -44,7 +44,10 @@ class GiftedPremium(Object):
4444
The paid amount, in the smallest units of the cryptocurrency; 0 if none
4545
4646
month_count (``int``):
47-
Number of months the Telegram Premium subscription will be active
47+
Number of months the Telegram Premium subscription will be active.
48+
49+
day_count (``int``):
50+
Number of days the Telegram Premium subscription will be active.
4851
4952
sticker (:obj:`~pyrogram.types.Sticker`):
5053
A sticker to be shown in the transaction information; may be None if unknown
@@ -66,6 +69,7 @@ def __init__(
6669
cryptocurrency: Optional[str] = None,
6770
cryptocurrency_amount: Optional[int] = None,
6871
month_count: Optional[int] = None,
72+
day_count: Optional[int] = None,
6973
sticker: Optional["types.Sticker"] = None,
7074
caption: Optional[Str] = None,
7175
caption_entities: Optional[list["types.MessageEntity"]] = None
@@ -78,6 +82,7 @@ def __init__(
7882
self.cryptocurrency = cryptocurrency
7983
self.cryptocurrency_amount = cryptocurrency_amount
8084
self.month_count = month_count
85+
self.day_count = day_count
8186
self.sticker = sticker
8287
self.caption = caption
8388
self.caption_entities = caption_entities
@@ -110,8 +115,9 @@ async def _parse(
110115
amount=gifted_premium.amount,
111116
cryptocurrency=getattr(gifted_premium, "crypto_currency", None),
112117
cryptocurrency_amount=getattr(gifted_premium, "crypto_amount", None),
113-
month_count=gifted_premium.months,
118+
day_count=gifted_premium.days,
119+
month_count=utils.get_premium_duration_month_count(gifted_premium.days),
114120
sticker=sticker,
115121
caption=caption,
116-
caption_entities=caption_entities
122+
caption_entities=caption_entities or None
117123
)

pyrogram/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,14 @@ def is_list_like(obj):
713713
Ported from https://github.com/LonamiWebs/Telethon/blob/1cb5ff1dd54ecfad41711fc5a4ecf36d2ad8eaf6/telethon/utils.py#L902
714714
"""
715715
return isinstance(obj, (list, tuple, set, dict, range))
716+
717+
718+
def get_premium_duration_month_count(day_count: int) -> int:
719+
return max(1, day_count // 30)
720+
721+
722+
def get_premium_duration_day_count(month_count: int) -> int:
723+
if month_count <= 0 or month_count > 10000000:
724+
return 7
725+
726+
return month_count * 30 + month_count // 3 + month_count // 12

0 commit comments

Comments
 (0)