mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-08 16:04:51 +00:00
pyrofork: Fix generate subcription invite link method
This commit is contained in:
parent
d3ffd68690
commit
bc76b9ccca
3 changed files with 22 additions and 36 deletions
|
|
@ -33,6 +33,8 @@ class CreateChatInviteLink:
|
|||
expire_date: datetime = None,
|
||||
member_limit: int = None,
|
||||
creates_join_request: bool = None
|
||||
subscription_period: int = None,
|
||||
subscription_price: int = None
|
||||
) -> "types.ChatInviteLink":
|
||||
"""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.
|
||||
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:
|
||||
: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
|
||||
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(
|
||||
raw.functions.messages.ExportChatInvite(
|
||||
|
|
@ -82,7 +94,11 @@ class CreateChatInviteLink:
|
|||
expire_date=utils.datetime_to_timestamp(expire_date),
|
||||
usage_limit=member_limit,
|
||||
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
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,15 +22,12 @@ from typing import Union
|
|||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
|
||||
|
||||
class ExportChatInviteLink:
|
||||
async def export_chat_invite_link(
|
||||
self: "pyrogram.Client",
|
||||
chat_id: Union[int, str],
|
||||
subscription_period: int = None,
|
||||
subscription_price: int = None
|
||||
) -> "types.ChatInviteLink":
|
||||
"""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).
|
||||
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:
|
||||
:obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned.
|
||||
``str``: On success, the new invite link as string is returned.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
|
@ -70,12 +60,8 @@ class ExportChatInviteLink:
|
|||
r = await self.invoke(
|
||||
raw.functions.messages.ExportChatInvite(
|
||||
peer=await self.resolve_peer(chat_id),
|
||||
legacy_revoke_permanent=True,
|
||||
subscription_pricing=raw.types.StarsSubscriptionPricing(
|
||||
period=subscription_period,
|
||||
amount=subscription_price
|
||||
)
|
||||
legacy_revoke_permanent=True
|
||||
)
|
||||
)
|
||||
|
||||
return types.ChatInviteLink._parse(self, r)
|
||||
return r.link
|
||||
|
|
|
|||
|
|
@ -1071,11 +1071,7 @@ class Chat(Object):
|
|||
|
||||
return await self._client.leave_chat(self.id)
|
||||
|
||||
async def export_invite_link(
|
||||
self,
|
||||
subscription_period: int = None,
|
||||
subscription_price: int = None
|
||||
):
|
||||
async def export_invite_link(self):
|
||||
"""Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`.
|
||||
|
||||
Use as a shortcut for:
|
||||
|
|
@ -1089,14 +1085,6 @@ class Chat(Object):
|
|||
|
||||
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:
|
||||
``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.
|
||||
"""
|
||||
|
||||
return await self._client.export_chat_invite_link(
|
||||
self.id,
|
||||
subscription_period=subscription_period,
|
||||
subscription_price=subscription_price
|
||||
)
|
||||
return await self._client.export_chat_invite_link(self.id)
|
||||
|
||||
async def get_member(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Reference in a new issue