Skip to content

Commit

Permalink
pyrofork: subscription_expiry_date and subscription_price to export_c…
Browse files Browse the repository at this point in the history
…hat_invite and Chat.export_invite_link

Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Aug 18, 2024
1 parent 7ce0a87 commit 013890b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pyrogram/methods/invite_links/export_chat_invite_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.

import datetime
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_expiry_date: "datetime.datetime" = None,
subscription_price: int = None
) -> "types.ChatInviteLink":
"""Generate a new primary invite link for a chat; any previously generated primary link is revoked.
Expand All @@ -48,6 +52,12 @@ async def export_chat_invite_link(
(in the format @username).
You can also use chat public link in form of *t.me/<username>* (str).
subscription_expiry_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the subscription will expire.
subscription_price (``int``, *optional*):
Subscription price (stars).
Returns:
``str``: On success, the new invite link as string is returned.
Expand All @@ -60,7 +70,11 @@ async def export_chat_invite_link(
r = await self.invoke(
raw.functions.messages.ExportChatInvite(
peer=await self.resolve_peer(chat_id),
legacy_revoke_permanent=True
legacy_revoke_permanent=True,
subscription_pricing=raw.types.StarsSubscriptionPricing(
period=utils.datetime_to_timestamp(subscription_expiry_date),
amount=subscription_price
)
)
)

Expand Down
19 changes: 17 additions & 2 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,11 @@ async def leave(self):

return await self._client.leave_chat(self.id)

async def export_invite_link(self):
async def export_invite_link(
self,
subscription_expiry_date: "datetime.datetime" = None,
subscription_price: int = None
):
"""Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`.
Use as a shortcut for:
Expand All @@ -1085,14 +1089,25 @@ async def export_invite_link(self):
chat.export_invite_link()
Parameters:
subscription_expiry_date (:py:obj:`~datetime.datetime`, *optional*):
Channel members only. Date when the subscription expires.
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.
Raises:
ValueError: In case the chat_id belongs to a user.
"""

return await self._client.export_chat_invite_link(self.id)
return await self._client.export_chat_invite_link(
self.id,
subscription_expiry_date=subscription_expiry_date,
subscription_price=subscription_price
)

async def get_member(
self,
Expand Down

0 comments on commit 013890b

Please sign in to comment.