Skip to content

Commit

Permalink
Update methods and types to Layer 194
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Nov 28, 2024
1 parent 8e5c740 commit 66f8ad4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
12 changes: 10 additions & 2 deletions pyrogram/methods/bots/create_invoice_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from typing import Union, List, Optional

import pyrogram
from pyrogram import raw, types
from pyrogram import utils, raw, types


class CreateInvoiceLink:
Expand All @@ -31,6 +32,7 @@ async def create_invoice_link(
currency: str,
prices: List["types.LabeledPrice"],
provider_token: Optional[str] = None,
subscription_period: datetime = None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[List[int]] = None,
start_parameter: Optional[str] = None,
Expand Down Expand Up @@ -73,6 +75,11 @@ async def create_invoice_link(
provider_token (``str``, *optional*):
Payment provider token, obtained via `@BotFather <https://t.me/botfather>`_. Pass an empty string for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
subscription_period (:py:obj:`~datetime.datetime`, *optional*):
The number of seconds the subscription will be active for before the next payment.
The currency must be set to “XTR” (Telegram Stars) if the parameter is used.
Currently, it must always be 2592000 (30 days) if specified.
max_tip_amount (``int``, *optional*):
The maximum accepted amount for tips in the smallest units of the currency (integer, **not** float/double). For example, for a maximum tip of ``US$ 1.45`` pass ``max_tip_amount = 145``. See the exp parameter in `currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
Expand Down Expand Up @@ -148,7 +155,8 @@ async def create_invoice_link(
phone_to_provider=send_phone_number_to_provider,
email_to_provider=send_email_to_provider,
max_tip_amount=max_tip_amount,
suggested_tip_amounts=suggested_tip_amounts
suggested_tip_amounts=suggested_tip_amounts,
subscription_period=utils.datetime_to_timestamp(subscription_period)
),
payload=payload.encode() if isinstance(payload, str) else payload,
provider=provider_token,
Expand Down
1 change: 0 additions & 1 deletion pyrogram/methods/messages/forward_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ async def forward_messages(
The relevant Stars will be withdrawn from the bot's balance.
For bots only.
Returns:
:obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message`: In case *message_ids* was not
a list, a single message is returned, otherwise a list of messages is returned.
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/methods/payments/get_star_gifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class GetStarGifts:
async def get_star_gifts(
self: "pyrogram.Client",
) -> List["types.StarGift"]:
"""Get all available star gifts to send.
"""Get all available star gifts that can be sent to other users.
.. include:: /_includes/usable-by/users.rst
.. include:: /_includes/usable-by/users-bots.rst
Returns:
List of :obj:`~pyrogram.types.StarGift`: On success, a list of star gifts is returned.
Expand Down
1 change: 1 addition & 0 deletions pyrogram/methods/payments/send_star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def send_star_gift(
hide_my_name (``bool``, *optional*):
If True, your name will be hidden from visitors to the gift recipient's profile.
For userbots only.
Defaults to None.
Returns:
Expand Down
11 changes: 9 additions & 2 deletions pyrogram/types/messages_and_media/star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class StarGift(Object):
is_sold_out (``bool``, *optional*):
True, if the star gift is sold out.
is_converted (``bool``, *optional*):
True, if the gift was converted to Telegram Stars.
Only for the receiver of the gift.
"""

def __init__(
Expand All @@ -104,7 +108,8 @@ def __init__(
is_limited: Optional[bool] = None,
is_name_hidden: Optional[bool] = None,
is_saved: Optional[bool] = None,
is_sold_out: Optional[bool] = None
is_sold_out: Optional[bool] = None,
is_converted: Optional[bool] = None
):
super().__init__(client)

Expand All @@ -125,6 +130,7 @@ def __init__(
self.is_name_hidden = is_name_hidden
self.is_saved = is_saved
self.is_sold_out = is_sold_out
self.is_converted = is_converted

@staticmethod
async def _parse(
Expand Down Expand Up @@ -187,7 +193,7 @@ async def _parse_action(
message: "raw.base.Message",
users: dict
) -> "StarGift":
action = message.action
action = message.action # type: raw.types.MessageActionStarGift

doc = action.gift.sticker
attributes = {type(i): i for i in doc.attributes}
Expand All @@ -209,6 +215,7 @@ async def _parse_action(
is_limited=getattr(action.gift, "limited", None),
is_name_hidden=getattr(action, "name_hidden", None),
is_saved=getattr(action, "saved", None),
is_converted=getattr(action, "converted", None),
from_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
message_id=message.id,
caption=caption,
Expand Down
14 changes: 11 additions & 3 deletions pyrogram/types/messages_and_media/successful_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from typing import Union, Optional

from pyrogram import utils
from pyrogram import raw
from pyrogram import types
from ..object import Object
Expand Down Expand Up @@ -49,13 +51,16 @@ class SuccessfulPayment(Object):
Payment information provided by the user. Only available to the bot that received the payment.
is_recurring (``bool``, *optional*):
True, if this is a recurring payment.
True, if the payment is a recurring payment for a subscription.
is_first_recurring (``bool``, *optional*):
True, if this is the first recurring payment.
True, if the payment is the first payment for a subscription.
invoice_slug (``str``, *optional*):
Name of the invoice.
subscription_expiration_date (:py:obj:`~datetime.datetime`, *optional*):
Expiration date of the subscription, in Unix time; for recurring payments only.
"""

def __init__(
Expand All @@ -69,7 +74,8 @@ def __init__(
order_info: Optional["types.OrderInfo"] = None,
is_recurring: Optional[bool] = None,
is_first_recurring: Optional[bool] = None,
invoice_slug: Optional[str] = None
invoice_slug: Optional[str] = None,
subscription_expiration_date: datetime = None,
):
super().__init__()

Expand All @@ -83,6 +89,7 @@ def __init__(
self.is_recurring = is_recurring
self.is_first_recurring = is_first_recurring
self.invoice_slug = invoice_slug
self.subscription_expiration_date = subscription_expiration_date

@staticmethod
def _parse(
Expand Down Expand Up @@ -136,4 +143,5 @@ def _parse(
is_recurring=getattr(successful_payment, "recurring_used", None),
is_first_recurring=getattr(successful_payment, "recurring_init", None),
invoice_slug=getattr(successful_payment, "invoice_slug", None),
subscription_expiration_date=utils.timestamp_to_datetime(successful_payment.subscription_until_date),
)

0 comments on commit 66f8ad4

Please sign in to comment.