From 51821fb71e621b2b21322777972e208944065f37 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Thu, 17 Aug 2023 18:49:06 +0700 Subject: [PATCH] Pyrofork: Add export_story_link method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + pyrogram/methods/users/__init__.py | 2 + pyrogram/methods/users/export_story_link.py | 66 +++++++++++++++++++ pyrogram/types/messages_and_media/__init__.py | 3 +- .../messages_and_media/exported_story_link.py | 44 +++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/users/export_story_link.py create mode 100644 pyrogram/types/messages_and_media/exported_story_link.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 65cf4117..f7bfc528 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -271,6 +271,7 @@ def pyrogram_api(): Stories delete_story edit_story + export_story_link get_stories send_story """, diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py index fa1164f1..53fdd781 100644 --- a/pyrogram/methods/users/__init__.py +++ b/pyrogram/methods/users/__init__.py @@ -20,6 +20,7 @@ from .block_user import BlockUser from .delete_profile_photos import DeleteProfilePhotos from .delete_stories import DeleteStories from .edit_story import EditStory +from .export_story_link import ExportStoryLink from .get_chat_photos import GetChatPhotos from .get_chat_photos_count import GetChatPhotosCount from .get_common_chats import GetCommonChats @@ -39,6 +40,7 @@ class Users( BlockUser, DeleteStories, EditStory, + ExportStoryLink, GetCommonChats, GetChatPhotos, SetProfilePhoto, diff --git a/pyrogram/methods/users/export_story_link.py b/pyrogram/methods/users/export_story_link.py new file mode 100644 index 00000000..c56036d5 --- /dev/null +++ b/pyrogram/methods/users/export_story_link.py @@ -0,0 +1,66 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +import logging +from typing import Union + +import pyrogram +from pyrogram import raw +from pyrogram import types + +log = logging.getLogger(__name__) + +class ExportStoryLink: + async def export_story_link( + self: "pyrogram.Client", + user_id: Union[int, str], + story_id: int, + ) -> types.ExportedStoryLink: + """Get one story link from an user by using story identifiers. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + user_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target user. + For your personal story you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + + story_id (``int``): + Pass a single story identifier of story (as integers). + + Returns: + :obj:`~pyrogram.types.ExportedStoryLink`: a single story link is returned. + + Example: + .. code-block:: python + + # Get story link + await app.export_story_link(user_id, 12345) + + Raises: + ValueError: In case of invalid arguments. + """ + + peer = await self.resolve_peer(user_id) + + rpc = raw.functions.stories.ExportStoryLink(user_id=peer, story_id=story_id) + + r = await self.invoke(rpc, sleep_threshold=-1) + + return types.ExportedStoryLink._parse(r) diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 97be2472..f1d64ae6 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -43,9 +43,10 @@ from .web_page import WebPage from .message_reactions import MessageReactions from .story import Story from .story_views import StoryViews +from .exported_story_link import ExportedStoryLink __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", - "Reaction", "WebAppData", "MessageReactions", "Story", "StoryViews", "StoriesPrivacy" + "Reaction", "WebAppData", "MessageReactions", "Story", "StoryViews", "StoriesPrivacy", "ExportedStoryLink" ] diff --git a/pyrogram/types/messages_and_media/exported_story_link.py b/pyrogram/types/messages_and_media/exported_story_link.py new file mode 100644 index 00000000..15287904 --- /dev/null +++ b/pyrogram/types/messages_and_media/exported_story_link.py @@ -0,0 +1,44 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from pyrogram import raw +from typing import List +from ..object import Object + +class ExportedStoryLink(Object): + """Contains information about a story viewers. + + + Parameters: + link (``str``): + The link of the story. + """ + + def __init__( + self, *, + link: str + ): + super().__init__() + + self.link = link + + @staticmethod + def _parse(exportedstorylink: "raw.types.ExportedStoryLink") -> "ExportedStoryLink": + return ExportedStoryLink( + link=getattr(exportedstorylink,"link", None) + )