pyrofork: Fix generate subcription invite link method

This commit is contained in:
Yasir Aris M 2024-08-24 10:24:17 +07:00 committed by GitHub
parent d3ffd68690
commit bc76b9ccca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 36 deletions

View file

@ -33,6 +33,8 @@ class CreateChatInviteLink:
expire_date: datetime = None, expire_date: datetime = None,
member_limit: int = None, member_limit: int = None,
creates_join_request: bool = None creates_join_request: bool = None
subscription_period: int = None,
subscription_price: int = None
) -> "types.ChatInviteLink": ) -> "types.ChatInviteLink":
"""Create an additional invite link for a chat. """Create an additional invite link for a chat.
@ -64,6 +66,13 @@ class CreateChatInviteLink:
True, if users joining the chat via the link need to be approved by chat administrators. True, if users joining the chat via the link need to be approved by chat administrators.
If True, member_limit can't be specified. If True, member_limit can't be specified.
subscription_period (``int``, *optional*):
Date when the subscription will expire.
for now, only 30 days is supported (30*24*60*60).
subscription_price (``int``, *optional*):
Subscription price (stars).
Returns: Returns:
:obj:`~pyrogram.types.ChatInviteLink`: On success, the new invite link is returned. :obj:`~pyrogram.types.ChatInviteLink`: On success, the new invite link is returned.
@ -75,6 +84,9 @@ class CreateChatInviteLink:
# Create a new link for up to 3 new users # Create a new link for up to 3 new users
link = await app.create_chat_invite_link(chat_id, member_limit=3) link = await app.create_chat_invite_link(chat_id, member_limit=3)
# Create subcription link
link = await app.create_chat_invite_link(chat_id, subscription_period=60*24*60*60, subscription_price=1)
""" """
r = await self.invoke( r = await self.invoke(
raw.functions.messages.ExportChatInvite( raw.functions.messages.ExportChatInvite(
@ -82,7 +94,11 @@ class CreateChatInviteLink:
expire_date=utils.datetime_to_timestamp(expire_date), expire_date=utils.datetime_to_timestamp(expire_date),
usage_limit=member_limit, usage_limit=member_limit,
title=name, title=name,
request_needed=creates_join_request request_needed=creates_join_request,
subscription_pricing=raw.types.StarsSubscriptionPricing(
period=subscription_period,
amount=subscription_price
) if subscription_period and subscription_price is not None else None
) )
) )

View file

@ -22,15 +22,12 @@ from typing import Union
import pyrogram import pyrogram
from pyrogram import raw from pyrogram import raw
from pyrogram import types from pyrogram import types
from pyrogram import utils
class ExportChatInviteLink: class ExportChatInviteLink:
async def export_chat_invite_link( async def export_chat_invite_link(
self: "pyrogram.Client", self: "pyrogram.Client",
chat_id: Union[int, str], chat_id: Union[int, str],
subscription_period: int = None,
subscription_price: int = None
) -> "types.ChatInviteLink": ) -> "types.ChatInviteLink":
"""Generate a new primary invite link for a chat; any previously generated primary link is revoked. """Generate a new primary invite link for a chat; any previously generated primary link is revoked.
@ -51,15 +48,8 @@ class ExportChatInviteLink:
(in the format @username). (in the format @username).
You can also use chat public link in form of *t.me/<username>* (str). You can also use chat public link in form of *t.me/<username>* (str).
subscription_period (``int``, *optional*):
Date when the subscription will expire.
for now, only 30 days is supported (30*24*60*60).
subscription_price (``int``, *optional*):
Subscription price (stars).
Returns: Returns:
:obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned. ``str``: On success, the new invite link as string is returned.
Example: Example:
.. code-block:: python .. code-block:: python
@ -70,12 +60,8 @@ class ExportChatInviteLink:
r = await self.invoke( r = await self.invoke(
raw.functions.messages.ExportChatInvite( raw.functions.messages.ExportChatInvite(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
legacy_revoke_permanent=True, legacy_revoke_permanent=True
subscription_pricing=raw.types.StarsSubscriptionPricing(
period=subscription_period,
amount=subscription_price
)
) )
) )
return types.ChatInviteLink._parse(self, r) return r.link

View file

@ -1071,11 +1071,7 @@ class Chat(Object):
return await self._client.leave_chat(self.id) return await self._client.leave_chat(self.id)
async def export_invite_link( async def export_invite_link(self):
self,
subscription_period: int = None,
subscription_price: int = None
):
"""Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`. """Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`.
Use as a shortcut for: Use as a shortcut for:
@ -1089,14 +1085,6 @@ class Chat(Object):
chat.export_invite_link() chat.export_invite_link()
Parameters:
subscription_period (``int``, *optional*):
Channel members only. Date when the subscription expires.
for now, only 30 days is supported (30*24*60*60).
subscription_price (``int``, *optional*):
Channel members only. Price of the subscription in the smallest units of the currency.
Returns: Returns:
``str``: On success, the exported invite link is returned. ``str``: On success, the exported invite link is returned.
@ -1104,11 +1092,7 @@ class Chat(Object):
ValueError: In case the chat_id belongs to a user. ValueError: In case the chat_id belongs to a user.
""" """
return await self._client.export_chat_invite_link( return await self._client.export_chat_invite_link(self.id)
self.id,
subscription_period=subscription_period,
subscription_price=subscription_price
)
async def get_member( async def get_member(
self, self,