mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-06 15:14:52 +00:00
Pyrofork: Update some methods and types to layer 164
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
6482d082cc
commit
b345bf8876
11 changed files with 115 additions and 57 deletions
|
|
@ -276,7 +276,7 @@ def pyrogram_api():
|
||||||
get_all_stories
|
get_all_stories
|
||||||
get_stories
|
get_stories
|
||||||
get_stories_history
|
get_stories_history
|
||||||
get_user_stories
|
get_peer_stories
|
||||||
send_story
|
send_story
|
||||||
""",
|
""",
|
||||||
stickers="""
|
stickers="""
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ from .get_me import GetMe
|
||||||
from .get_all_stories import GetAllStories
|
from .get_all_stories import GetAllStories
|
||||||
from .get_stories import GetStories
|
from .get_stories import GetStories
|
||||||
from .get_stories_history import GetUserStoriesHistory
|
from .get_stories_history import GetUserStoriesHistory
|
||||||
from .get_user_stories import GetUserStories
|
from .get_peer_stories import GetPeerStories
|
||||||
from .get_users import GetUsers
|
from .get_users import GetUsers
|
||||||
from .send_story import SendStory
|
from .send_story import SendStory
|
||||||
from .set_emoji_status import SetEmojiStatus
|
from .set_emoji_status import SetEmojiStatus
|
||||||
|
|
@ -53,7 +53,7 @@ class Users(
|
||||||
GetAllStories,
|
GetAllStories,
|
||||||
GetStories,
|
GetStories,
|
||||||
GetUserStoriesHistory,
|
GetUserStoriesHistory,
|
||||||
GetUserStories,
|
GetPeerStories,
|
||||||
SetUsername,
|
SetUsername,
|
||||||
GetChatPhotosCount,
|
GetChatPhotosCount,
|
||||||
UnblockUser,
|
UnblockUser,
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class DeleteStories:
|
||||||
async def delete_stories(
|
async def delete_stories(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
story_ids: Union[int, Iterable[int]],
|
story_ids: Union[int, Iterable[int]],
|
||||||
|
channel_id: int = None
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Delete one or more story by using story identifiers.
|
"""Delete one or more story by using story identifiers.
|
||||||
|
|
||||||
|
|
@ -39,6 +40,9 @@ class DeleteStories:
|
||||||
Pass a single story identifier or an iterable of story ids (as integers) to get the content of the
|
Pass a single story identifier or an iterable of story ids (as integers) to get the content of the
|
||||||
story themselves.
|
story themselves.
|
||||||
|
|
||||||
|
channel_id (``int``, *optional*):
|
||||||
|
Unique identifier (int) of the target channel.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
`bool`: On success, a True is returned.
|
`bool`: On success, a True is returned.
|
||||||
|
|
||||||
|
|
@ -54,10 +58,15 @@ class DeleteStories:
|
||||||
|
|
||||||
is_iterable = not isinstance(story_ids, int)
|
is_iterable = not isinstance(story_ids, int)
|
||||||
ids = list(story_ids) if is_iterable else [story_ids]
|
ids = list(story_ids) if is_iterable else [story_ids]
|
||||||
|
|
||||||
|
if channel_id:
|
||||||
|
peer = await self.resolve_peer(channel_id)
|
||||||
|
else:
|
||||||
|
peer = await self.resolve_peer("me")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.invoke(
|
await self.invoke(
|
||||||
raw.functions.stories.DeleteStories(id=ids)
|
raw.functions.stories.DeleteStories(peer=peer,id=ids)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class EditStory:
|
||||||
async def edit_story(
|
async def edit_story(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
story_id: int,
|
story_id: int,
|
||||||
|
channel_id: int = None,
|
||||||
privacy: "enums.StoriesPrivacy" = None,
|
privacy: "enums.StoriesPrivacy" = None,
|
||||||
allowed_users: List[int] = None,
|
allowed_users: List[int] = None,
|
||||||
denied_users: List[int] = None,
|
denied_users: List[int] = None,
|
||||||
|
|
@ -50,6 +51,9 @@ class EditStory:
|
||||||
Parameters:
|
Parameters:
|
||||||
story_id (``int``):
|
story_id (``int``):
|
||||||
Unique identifier (int) of the target story.
|
Unique identifier (int) of the target story.
|
||||||
|
|
||||||
|
channel_id (``int``, *optional*):
|
||||||
|
Unique identifier (int) of the target channel.
|
||||||
|
|
||||||
animation (``str`` | ``BinaryIO``, *optional*):
|
animation (``str`` | ``BinaryIO``, *optional*):
|
||||||
New story Animation.
|
New story Animation.
|
||||||
|
|
@ -113,6 +117,11 @@ class EditStory:
|
||||||
|
|
||||||
# TODO: MediaArea
|
# TODO: MediaArea
|
||||||
|
|
||||||
|
if channel_id:
|
||||||
|
peer = await self.resolve_peer(channel_id)
|
||||||
|
else:
|
||||||
|
peer = await self.resolve_peer("me")
|
||||||
|
|
||||||
media = None
|
media = None
|
||||||
privacy_rules = None
|
privacy_rules = None
|
||||||
|
|
||||||
|
|
@ -232,10 +241,11 @@ class EditStory:
|
||||||
r = await self.invoke(
|
r = await self.invoke(
|
||||||
raw.functions.stories.EditStory(
|
raw.functions.stories.EditStory(
|
||||||
id=story_id,
|
id=story_id,
|
||||||
|
peer=peer,
|
||||||
media=media,
|
media=media,
|
||||||
privacy_rules=privacy_rules,
|
privacy_rules=privacy_rules,
|
||||||
caption=text,
|
caption=text,
|
||||||
entities=entities
|
entities=entities
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return await types.Story._parse(self, r.updates[0].story, r.updates[0].user_id)
|
return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ log = logging.getLogger(__name__)
|
||||||
class ExportStoryLink:
|
class ExportStoryLink:
|
||||||
async def export_story_link(
|
async def export_story_link(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
user_id: Union[int, str],
|
from_id: Union[int, str],
|
||||||
story_id: int,
|
story_id: int,
|
||||||
) -> types.ExportedStoryLink:
|
) -> types.ExportedStoryLink:
|
||||||
"""Get one story link from an user by using story identifiers.
|
"""Get one story link from an user by using story identifiers.
|
||||||
|
|
@ -36,8 +36,8 @@ class ExportStoryLink:
|
||||||
.. include:: /_includes/usable-by/users.rst
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
user_id (``int`` | ``str``):
|
from_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target user.
|
Unique identifier (int) or username (str) of the target user/channel.
|
||||||
For your personal story you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
|
@ -51,15 +51,15 @@ class ExportStoryLink:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Get story link
|
# Get story link
|
||||||
await app.export_story_link(user_id, 12345)
|
await app.export_story_link(from_id, 12345)
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: In case of invalid arguments.
|
ValueError: In case of invalid arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
peer = await self.resolve_peer(user_id)
|
peer = await self.resolve_peer(from_id)
|
||||||
|
|
||||||
rpc = raw.functions.stories.ExportStoryLink(user_id=peer, story_id=story_id)
|
rpc = raw.functions.stories.ExportStoryLink(peer=peer, story_id=story_id)
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ class GetAllStories:
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
for user_story in r.user_stories:
|
for peer_story in r.peer_stories:
|
||||||
user_id = user_story.user_id
|
for story in peer_story.stories:
|
||||||
for story in user_story.stories:
|
yield await types.Story._parse(self, story, peer_story.peer)
|
||||||
yield await types.Story._parse(self, story, user_id)
|
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,18 @@ from pyrogram import types
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class GetUserStories:
|
class GetPeerStories:
|
||||||
async def get_user_stories(
|
async def get_peer_stories(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
user_id: Union[int, str]
|
from_id: Union[int, str]
|
||||||
) -> Optional[AsyncGenerator["types.Story", None]]:
|
) -> Optional[AsyncGenerator["types.Story", None]]:
|
||||||
"""Get all active stories from an user by using user identifiers.
|
"""Get all active stories from an user/channel by using user identifiers.
|
||||||
|
|
||||||
.. include:: /_includes/usable-by/users.rst
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
user_id (``int`` | ``str``):
|
from_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target user.
|
Unique identifier (int) or username (str) of the target user/channel.
|
||||||
For your personal story you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
|
@ -46,20 +46,20 @@ class GetUserStories:
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Get all active story from spesific user
|
# Get all active story from spesific user/channel
|
||||||
async for story in app.get_user_stories(user_id):
|
async for story in app.get_peer_stories(from_id):
|
||||||
print(story)
|
print(story)
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: In case of invalid arguments.
|
ValueError: In case of invalid arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
peer = await self.resolve_peer(user_id)
|
peer = await self.resolve_peer(from_id)
|
||||||
|
|
||||||
|
|
||||||
rpc = raw.functions.stories.GetUserStories(user_id=peer)
|
rpc = raw.functions.stories.GetPeerStories(peer=peer)
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
for story in r.stories.stories:
|
for story in r.stories.stories:
|
||||||
yield await types.Story._parse(self, story, user_id)
|
yield await types.Story._parse(self, story, peer)
|
||||||
|
|
@ -28,7 +28,7 @@ log = logging.getLogger(__name__)
|
||||||
class GetStories:
|
class GetStories:
|
||||||
async def get_stories(
|
async def get_stories(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
user_id: Union[int, str],
|
from_id: Union[int, str],
|
||||||
story_ids: Union[int, Iterable[int]],
|
story_ids: Union[int, Iterable[int]],
|
||||||
) -> Union["types.Story", List["types.Story"]]:
|
) -> Union["types.Story", List["types.Story"]]:
|
||||||
"""Get one or more story from an user by using story identifiers.
|
"""Get one or more story from an user by using story identifiers.
|
||||||
|
|
@ -36,8 +36,8 @@ class GetStories:
|
||||||
.. include:: /_includes/usable-by/users.rst
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
user_id (``int`` | ``str``):
|
from_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target user.
|
Unique identifier (int) or username (str) of the target user/channel.
|
||||||
For your personal story you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
|
@ -53,24 +53,24 @@ class GetStories:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Get one story
|
# Get one story
|
||||||
await app.get_stories(user_id, 12345)
|
await app.get_stories(from_id, 12345)
|
||||||
|
|
||||||
# Get more than one story (list of stories)
|
# Get more than one story (list of stories)
|
||||||
await app.get_stories(user_id, [12345, 12346])
|
await app.get_stories(from_id, [12345, 12346])
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: In case of invalid arguments.
|
ValueError: In case of invalid arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
peer = await self.resolve_peer(user_id)
|
peer = await self.resolve_peer(from_id)
|
||||||
|
|
||||||
is_iterable = not isinstance(story_ids, int)
|
is_iterable = not isinstance(story_ids, int)
|
||||||
ids = list(story_ids) if is_iterable else [story_ids]
|
ids = list(story_ids) if is_iterable else [story_ids]
|
||||||
|
|
||||||
rpc = raw.functions.stories.GetStoriesByID(user_id=peer, id=ids)
|
rpc = raw.functions.stories.GetStoriesByID(peer=peer, id=ids)
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
if is_iterable:
|
if is_iterable:
|
||||||
return types.List([await types.Story._parse(self, story, user_id) for story in r.stories])
|
return types.List([await types.Story._parse(self, story, peer) for story in r.stories])
|
||||||
return await types.Story._parse(self, r.stories[0], user_id)
|
return await types.Story._parse(self, r.stories[0], peer)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||||
class GetUserStoriesHistory:
|
class GetUserStoriesHistory:
|
||||||
async def get_stories_history(
|
async def get_stories_history(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
|
channel_id: int = None,
|
||||||
limit: int = 0,
|
limit: int = 0,
|
||||||
offset_id: int = 0
|
offset_id: int = 0
|
||||||
) -> Optional[AsyncGenerator["types.Story", None]]:
|
) -> Optional[AsyncGenerator["types.Story", None]]:
|
||||||
|
|
@ -36,6 +37,9 @@ class GetUserStoriesHistory:
|
||||||
.. include:: /_includes/usable-by/users.rst
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
channel_id (``int``, *optional*):
|
||||||
|
Unique identifier (int) of the target channel.
|
||||||
|
|
||||||
limit (``int``, *optional*):
|
limit (``int``, *optional*):
|
||||||
Limits the number of stories to be retrieved.
|
Limits the number of stories to be retrieved.
|
||||||
By default, no limit is applied and all stories are returned.
|
By default, no limit is applied and all stories are returned.
|
||||||
|
|
@ -56,10 +60,15 @@ class GetUserStoriesHistory:
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: In case of invalid arguments.
|
ValueError: In case of invalid arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if channel_id:
|
||||||
|
peer = await self.resolve_peer(channel_id)
|
||||||
|
else:
|
||||||
|
peer = await self.resolve_peer("me")
|
||||||
|
|
||||||
rpc = raw.functions.stories.GetStoriesArchive(offset_id=offset_id, limit=limit)
|
rpc = raw.functions.stories.GetStoriesArchive(peer=peer, offset_id=offset_id, limit=limit)
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
for story in r.stories:
|
for story in r.stories:
|
||||||
yield await types.Story._parse(self, story, self.me.id)
|
yield await types.Story._parse(self, story, peer)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class SendStory:
|
||||||
|
|
||||||
async def send_story(
|
async def send_story(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
|
channel_id: int = None,
|
||||||
privacy: "enums.StoriesPrivacy" = None,
|
privacy: "enums.StoriesPrivacy" = None,
|
||||||
allowed_users: List[int] = None,
|
allowed_users: List[int] = None,
|
||||||
denied_users: List[int] = None,
|
denied_users: List[int] = None,
|
||||||
|
|
@ -52,6 +53,9 @@ class SendStory:
|
||||||
Note: You must pass one of following paramater *animation*, *photo*, *video*
|
Note: You must pass one of following paramater *animation*, *photo*, *video*
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
channel_id (``int``, *optional*):
|
||||||
|
Unique identifier (int) of the target channel.
|
||||||
|
|
||||||
animation (``str`` | ``BinaryIO``, *optional*):
|
animation (``str`` | ``BinaryIO``, *optional*):
|
||||||
Animation to send.
|
Animation to send.
|
||||||
Pass a file_id as string to send a animation that exists on the Telegram servers,
|
Pass a file_id as string to send a animation that exists on the Telegram servers,
|
||||||
|
|
@ -126,6 +130,11 @@ class SendStory:
|
||||||
"""
|
"""
|
||||||
# TODO: media_areas
|
# TODO: media_areas
|
||||||
|
|
||||||
|
if channel_id:
|
||||||
|
peer = await self.resolve_peer(channel_id)
|
||||||
|
else:
|
||||||
|
peer = await self.resolve_peer("me")
|
||||||
|
|
||||||
if privacy:
|
if privacy:
|
||||||
privacy_rules = [types.StoriesPrivacy(type=privacy)]
|
privacy_rules = [types.StoriesPrivacy(type=privacy)]
|
||||||
else:
|
else:
|
||||||
|
|
@ -243,6 +252,7 @@ class SendStory:
|
||||||
|
|
||||||
r = await self.invoke(
|
r = await self.invoke(
|
||||||
raw.functions.stories.SendStory(
|
raw.functions.stories.SendStory(
|
||||||
|
peer=peer,
|
||||||
media=media,
|
media=media,
|
||||||
privacy_rules=privacy_rules,
|
privacy_rules=privacy_rules,
|
||||||
random_id=self.rnd_id(),
|
random_id=self.rnd_id(),
|
||||||
|
|
@ -253,4 +263,4 @@ class SendStory:
|
||||||
period=period
|
period=period
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return await types.Story._parse(self, r.updates[0].story, r.updates[0].user_id)
|
return await types.Story._parse(self, r.updates[0].story, r.updates[0].peer)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ class Story(Object, Update):
|
||||||
|
|
||||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||||
Sender of the story.
|
Sender of the story.
|
||||||
|
|
||||||
|
sender_chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||||
|
Sender of the story. If the story is from channel.
|
||||||
|
|
||||||
date (:py:obj:`~datetime.datetime`, *optional*):
|
date (:py:obj:`~datetime.datetime`, *optional*):
|
||||||
Date the story was sent.
|
Date the story was sent.
|
||||||
|
|
@ -92,7 +95,8 @@ class Story(Object, Update):
|
||||||
*,
|
*,
|
||||||
client: "pyrogram.Client" = None,
|
client: "pyrogram.Client" = None,
|
||||||
id: int,
|
id: int,
|
||||||
from_user: "types.User",
|
from_user: "types.User" = None,
|
||||||
|
sender_chat: "types.Chat" = None,
|
||||||
date: datetime,
|
date: datetime,
|
||||||
expire_date: datetime,
|
expire_date: datetime,
|
||||||
media: "enums.MessageMediaType",
|
media: "enums.MessageMediaType",
|
||||||
|
|
@ -114,6 +118,7 @@ class Story(Object, Update):
|
||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
self.from_user = from_user
|
self.from_user = from_user
|
||||||
|
self.sender_chat = sender_chat
|
||||||
self.date = date
|
self.date = date
|
||||||
self.expire_date = expire_date
|
self.expire_date = expire_date
|
||||||
self.media = media
|
self.media = media
|
||||||
|
|
@ -135,13 +140,15 @@ class Story(Object, Update):
|
||||||
async def _parse(
|
async def _parse(
|
||||||
client: "pyrogram.Client",
|
client: "pyrogram.Client",
|
||||||
stories: raw.base.StoryItem,
|
stories: raw.base.StoryItem,
|
||||||
user_id: int
|
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
||||||
) -> "Story":
|
) -> "Story":
|
||||||
entities = [types.MessageEntity._parse(client, entity, {}) for entity in stories.entities]
|
entities = [types.MessageEntity._parse(client, entity, {}) for entity in stories.entities]
|
||||||
entities = types.List(filter(lambda x: x is not None, entities))
|
entities = types.List(filter(lambda x: x is not None, entities))
|
||||||
animation = None
|
animation = None
|
||||||
photo = None
|
photo = None
|
||||||
video = None
|
video = None
|
||||||
|
from_user = None
|
||||||
|
sender_chat = None
|
||||||
if stories.media:
|
if stories.media:
|
||||||
if isinstance(stories.media, raw.types.MessageMediaPhoto):
|
if isinstance(stories.media, raw.types.MessageMediaPhoto):
|
||||||
photo = types.Photo._parse(client, stories.media.photo, stories.media.ttl_seconds)
|
photo = types.Photo._parse(client, stories.media.photo, stories.media.ttl_seconds)
|
||||||
|
|
@ -164,11 +171,17 @@ class Story(Object, Update):
|
||||||
media_type = None
|
media_type = None
|
||||||
else:
|
else:
|
||||||
media_type = None
|
media_type = None
|
||||||
from_user = await client.get_users(user_id)
|
if isinstance(peer, raw.types.PeerChannel):
|
||||||
|
sender_chat = await client.get_chat(peer.channel_id)
|
||||||
|
elif isinstance(peer, raw.types.InputPeerSelf):
|
||||||
|
from_user = client.me
|
||||||
|
else:
|
||||||
|
from_user = await client.get_users(peer.user_id)
|
||||||
|
|
||||||
return Story(
|
return Story(
|
||||||
id=stories.id,
|
id=stories.id,
|
||||||
from_user=from_user,
|
from_user=from_user,
|
||||||
|
sender_chat=sender_chat,
|
||||||
date=utils.timestamp_to_datetime(stories.date),
|
date=utils.timestamp_to_datetime(stories.date),
|
||||||
expire_date=utils.timestamp_to_datetime(stories.expire_date),
|
expire_date=utils.timestamp_to_datetime(stories.expire_date),
|
||||||
media=media_type,
|
media=media_type,
|
||||||
|
|
@ -260,7 +273,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
chat_id=self.from_user.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
text=text,
|
text=text,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
|
|
@ -399,7 +412,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_animation(
|
return await self._client.send_animation(
|
||||||
chat_id=self.from_user.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
animation=animation,
|
animation=animation,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -538,7 +551,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_audio(
|
return await self._client.send_audio(
|
||||||
chat_id=self.from_user.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
audio=audio,
|
audio=audio,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -623,7 +636,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_cached_media(
|
return await self._client.send_cached_media(
|
||||||
chat_id=self.from_user.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
file_id=file_id,
|
file_id=file_id,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -685,7 +698,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_media_group(
|
return await self._client.send_media_group(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
media=media,
|
media=media,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_to_story_id=reply_to_story_id
|
reply_to_story_id=reply_to_story_id
|
||||||
|
|
@ -797,7 +810,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_photo(
|
return await self._client.send_photo(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
photo=photo,
|
photo=photo,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -895,7 +908,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_sticker(
|
return await self._client.send_sticker(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
sticker=sticker,
|
sticker=sticker,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_to_story_id=reply_to_story_id,
|
reply_to_story_id=reply_to_story_id,
|
||||||
|
|
@ -1038,7 +1051,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_video(
|
return await self._client.send_video(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
video=video,
|
video=video,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -1156,7 +1169,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_video_note(
|
return await self._client.send_video_note(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
length=length,
|
length=length,
|
||||||
|
|
@ -1268,7 +1281,7 @@ class Story(Object, Update):
|
||||||
reply_to_story_id = self.id
|
reply_to_story_id = self.id
|
||||||
|
|
||||||
return await self._client.send_voice(
|
return await self._client.send_voice(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.from_user.id if self.from_user else self.sender_chat.id,
|
||||||
voice=voice,
|
voice=voice,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -1303,7 +1316,10 @@ class Story(Object, Update):
|
||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.delete_stories(story_ids=self.id)
|
return await self._client.delete_stories(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
|
story_ids=self.id
|
||||||
|
)
|
||||||
|
|
||||||
async def edit_animation(
|
async def edit_animation(
|
||||||
self,
|
self,
|
||||||
|
|
@ -1336,6 +1352,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
animation=animation
|
animation=animation
|
||||||
)
|
)
|
||||||
|
|
@ -1392,7 +1409,8 @@ class Story(Object, Update):
|
||||||
New story video.
|
New story video.
|
||||||
Pass a file_id as string to send a video that exists on the Telegram servers,
|
Pass a file_id as string to send a video that exists on the Telegram servers,
|
||||||
pass an HTTP URL as a string for Telegram to get a video from the Internet,
|
pass an HTTP URL as a string for Telegram to get a video from the Internet,
|
||||||
pass a file path as string to upload a new video that exists on your local machine, or
|
pass a file path as string to upload a
|
||||||
|
channel=self.sender_chat.id if self.sender_chat else None,new video that exists on your local machine, or
|
||||||
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
|
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
|
||||||
|
|
||||||
privacy (:obj:`~pyrogram.enums.StoriesPrivacy`, *optional*):
|
privacy (:obj:`~pyrogram.enums.StoriesPrivacy`, *optional*):
|
||||||
|
|
@ -1427,6 +1445,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
privacy=privacy,
|
privacy=privacy,
|
||||||
allowed_chats=allowed_chats,
|
allowed_chats=allowed_chats,
|
||||||
|
|
@ -1452,9 +1471,7 @@ class Story(Object, Update):
|
||||||
Use as a shortcut for:
|
Use as a shortcut for:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
channel=self.sender_chat.id if self.sender_chat else None,
|
||||||
await client.edit_story(
|
|
||||||
story_id=story.id,
|
|
||||||
caption="hello"
|
caption="hello"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1481,6 +1498,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
|
|
@ -1518,6 +1536,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
photo=photo
|
photo=photo
|
||||||
)
|
)
|
||||||
|
|
@ -1569,6 +1588,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
privacy=privacy,
|
privacy=privacy,
|
||||||
allowed_chats=allowed_chats,
|
allowed_chats=allowed_chats,
|
||||||
|
|
@ -1608,6 +1628,7 @@ class Story(Object, Update):
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_story(
|
return await self._client.edit_story(
|
||||||
|
channel_id=self.sender_chat.id if self.sender_chat else None,
|
||||||
story_id=self.id,
|
story_id=self.id,
|
||||||
video=video
|
video=video
|
||||||
)
|
)
|
||||||
|
|
@ -1635,4 +1656,4 @@ class Story(Object, Update):
|
||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return await self._client.export_story_link(user_id=self.from_user.id, story_id=self.id)
|
return await self._client.export_story_link(from_id=self.from_user.id if self.from_user else self.sender_chat.id, story_id=self.id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue