mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Remove StorySkipped and StoryDeleted type
This commit is contained in:
parent
fdf1c98a16
commit
f85fdc838e
@ -459,8 +459,6 @@ def pyrogram_api():
|
||||
ChatReactions
|
||||
MessageStory
|
||||
Story
|
||||
StoryDeleted
|
||||
StorySkipped
|
||||
StoryViews
|
||||
MyBoost
|
||||
BoostsStatus
|
||||
|
@ -42,8 +42,6 @@ from .reaction import Reaction
|
||||
from .sticker import Sticker
|
||||
from .stripped_thumbnail import StrippedThumbnail
|
||||
from .story import Story
|
||||
from .story_deleted import StoryDeleted
|
||||
from .story_skipped import StorySkipped
|
||||
from .story_views import StoryViews
|
||||
from .thumbnail import Thumbnail
|
||||
from .venue import Venue
|
||||
@ -60,7 +58,7 @@ __all__ = [
|
||||
"Animation", "Audio", "BoostsStatus", "Contact", "Document", "ForumTopic", "ForumTopicCreated",
|
||||
"ForumTopicClosed", "ForumTopicReopened", "ForumTopicEdited", "GeneralTopicHidden",
|
||||
"GeneralTopicUnhidden", "Game", "GiftCode", "Giveaway", "Location", "Message", "MessageEntity",
|
||||
"Photo", "Thumbnail", "StrippedThumbnail", "Story", "StoryDeleted", "StorySkipped",
|
||||
"StoryViews", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice",
|
||||
"WebPage", "Dice", "Reaction", "WebAppData", "MessageReactions", "MessageStory", "MyBoost"
|
||||
"Photo", "Thumbnail", "StrippedThumbnail", "Story", "StoryViews", "Poll", "PollOption",
|
||||
"Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction",
|
||||
"WebAppData", "MessageReactions", "MessageStory", "MyBoost"
|
||||
]
|
||||
|
@ -109,6 +109,14 @@ class Story(Object, Update):
|
||||
|
||||
disallowed_users (List of ``int`` | ``str``, *optional*):
|
||||
List of user_ids whos denied to view the story.
|
||||
|
||||
skipped (``bool``, *optional*):
|
||||
The story is skipped.
|
||||
A story can be skipped in case it was skipped.
|
||||
|
||||
deleted (``bool``, *optional*):
|
||||
The story is deleted.
|
||||
A story can be deleted in case it was deleted or you tried to retrieve a story that doesn't exist yet.
|
||||
"""
|
||||
|
||||
# TODO: Add Media Areas
|
||||
@ -143,6 +151,8 @@ class Story(Object, Update):
|
||||
privacy: "enums.StoryPrivacyRules" = None,
|
||||
allowed_users: List[Union[int, str]] = None,
|
||||
disallowed_users: List[Union[int, str]] = None,
|
||||
skipped: bool = None,
|
||||
deleted: bool = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
@ -172,6 +182,8 @@ class Story(Object, Update):
|
||||
self.privacy = privacy
|
||||
self.allowed_users = allowed_users
|
||||
self.disallowed_users = disallowed_users
|
||||
self.skipped = skipped
|
||||
self.deleted = deleted
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
@ -181,13 +193,6 @@ class Story(Object, Update):
|
||||
chats: dict,
|
||||
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
||||
) -> "Story":
|
||||
if isinstance(story, raw.types.StoryItemSkipped):
|
||||
return await types.StorySkipped._parse(client, story, users, chats, peer)
|
||||
if isinstance(story, raw.types.StoryItemDeleted):
|
||||
return await types.StoryDeleted._parse(client, story, users, chats, peer)
|
||||
|
||||
entities = [e for e in (types.MessageEntity._parse(client, entity, {}) for entity in story.entities) if e]
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerSelf):
|
||||
r = await client.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()]))
|
||||
peer_id = r[0].id
|
||||
@ -216,6 +221,25 @@ class Story(Object, Update):
|
||||
else:
|
||||
users.update({i.id: i for i in r})
|
||||
|
||||
photo = None
|
||||
video = None
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
chat = None
|
||||
privacy = None
|
||||
allowed_users = None
|
||||
disallowed_users = None
|
||||
media_type = None
|
||||
|
||||
from_user = types.User._parse(client, users.get(peer_id, None))
|
||||
sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not from_user else None
|
||||
chat = sender_chat if not from_user else types.Chat._parse_user_chat(client, users.get(peer_id, None))
|
||||
|
||||
if isinstance(story, raw.types.StoryItemDeleted):
|
||||
return Story(client=client, id=story.id, deleted=True, from_user=from_user, sender_chat=sender_chat, chat=chat)
|
||||
if isinstance(story, raw.types.StoryItemSkipped):
|
||||
return Story(client=client, id=story.id, skipped=True, from_user=from_user, sender_chat=sender_chat, chat=chat)
|
||||
|
||||
forward_from = None
|
||||
forward_sender_name = None
|
||||
forward_from_chat = None
|
||||
@ -233,16 +257,6 @@ class Story(Object, Update):
|
||||
forward_from_chat = types.Chat._parse_channel_chat(client, chats[raw_peer_id])
|
||||
forward_from_story_id = forward_header.story_id
|
||||
|
||||
photo = None
|
||||
video = None
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
chat = None
|
||||
privacy = None
|
||||
allowed_users = None
|
||||
disallowed_users = None
|
||||
media_type = None
|
||||
|
||||
if isinstance(story.media, raw.types.MessageMediaPhoto):
|
||||
photo = types.Photo._parse(client, story.media.photo, story.media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.PHOTO
|
||||
@ -253,10 +267,6 @@ class Story(Object, Update):
|
||||
video = types.Video._parse(client, doc, video_attributes, None)
|
||||
media_type = enums.MessageMediaType.VIDEO
|
||||
|
||||
from_user = types.User._parse(client, users.get(peer_id, None))
|
||||
sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not from_user else None
|
||||
chat = sender_chat if not from_user else types.Chat._parse_user_chat(client, users.get(peer_id, None))
|
||||
|
||||
privacy_map = {
|
||||
raw.types.PrivacyValueAllowAll: enums.StoriesPrivacyRules.PUBLIC,
|
||||
raw.types.PrivacyValueAllowContacts: enums.StoriesPrivacyRules.CONTACTS,
|
||||
@ -276,6 +286,8 @@ class Story(Object, Update):
|
||||
elif isinstance(priv, raw.types.PrivacyValueDisallowChatParticipants):
|
||||
disallowed_users = types.List(types.Chat._parse_chat_chat(client, chats.get(chat_id, None)) for chat_id in priv.chats)
|
||||
|
||||
entities = [e for e in (types.MessageEntity._parse(client, entity, {}) for entity in story.entities) if e]
|
||||
|
||||
return Story(
|
||||
id=story.id,
|
||||
from_user=from_user,
|
||||
|
@ -1,95 +0,0 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram 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.
|
||||
#
|
||||
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pyrogram
|
||||
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram.errors import PeerIdInvalid
|
||||
from typing import Union
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
class StoryDeleted(Object, Update):
|
||||
"""A deleted story.
|
||||
|
||||
Parameters:
|
||||
id (``int``):
|
||||
Unique story identifier.
|
||||
|
||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
Sender of the story.
|
||||
|
||||
sender_chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||
Sender of the story. If the story is from channel.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
id: int,
|
||||
from_user: "types.User" = None,
|
||||
sender_chat: "types.Chat" = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.sender_chat = sender_chat
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
stories: raw.base.StoryItem,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
||||
) -> "StoryDeleted":
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerSelf):
|
||||
r = await client.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()]))
|
||||
peer_id = r[0].id
|
||||
users.update({i.id: i for i in r})
|
||||
else:
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
|
||||
if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser)) and peer_id not in users:
|
||||
try:
|
||||
r = await client.invoke(
|
||||
raw.functions.users.GetUsers(
|
||||
id=[
|
||||
await client.resolve_peer(peer_id)
|
||||
]
|
||||
)
|
||||
)
|
||||
except PeerIdInvalid:
|
||||
pass
|
||||
else:
|
||||
users.update({i.id: i for i in r})
|
||||
|
||||
from_user = types.User._parse(client, users.get(peer_id, None))
|
||||
sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not from_user else None
|
||||
|
||||
return StoryDeleted(
|
||||
id=stories.id,
|
||||
from_user=from_user,
|
||||
sender_chat=sender_chat,
|
||||
client=client
|
||||
)
|
@ -1,114 +0,0 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram 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.
|
||||
#
|
||||
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pyrogram
|
||||
|
||||
from datetime import datetime
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram.errors import PeerIdInvalid
|
||||
from typing import Union
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
class StorySkipped(Object, Update):
|
||||
"""A skipped story.
|
||||
|
||||
Parameters:
|
||||
id (``int``):
|
||||
Unique story identifier.
|
||||
|
||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
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 the story was sent.
|
||||
|
||||
expire_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||
Date the story will be expired.
|
||||
|
||||
close_friends (``bool``, *optional*):
|
||||
True, if the Story is shared with close_friends only.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
id: int,
|
||||
from_user: "types.User" = None,
|
||||
sender_chat: "types.Chat" = None,
|
||||
date: datetime,
|
||||
expire_date: datetime,
|
||||
close_friends: bool = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.sender_chat = sender_chat
|
||||
self.date = date
|
||||
self.expire_date = expire_date
|
||||
self.close_friends = close_friends
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
stories: raw.base.StoryItem,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
||||
) -> "StorySkipped":
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerSelf):
|
||||
r = await client.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()]))
|
||||
peer_id = r[0].id
|
||||
users.update({i.id: i for i in r})
|
||||
else:
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
|
||||
if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser)) and peer_id not in users:
|
||||
try:
|
||||
r = await client.invoke(
|
||||
raw.functions.users.GetUsers(
|
||||
id=[
|
||||
await client.resolve_peer(peer_id)
|
||||
]
|
||||
)
|
||||
)
|
||||
except PeerIdInvalid:
|
||||
pass
|
||||
else:
|
||||
users.update({i.id: i for i in r})
|
||||
|
||||
from_user = types.User._parse(client, users.get(peer_id, None))
|
||||
sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not from_user else None
|
||||
|
||||
return StorySkipped(
|
||||
id=stories.id,
|
||||
from_user=from_user,
|
||||
sender_chat=sender_chat,
|
||||
date=utils.timestamp_to_datetime(stories.date),
|
||||
expire_date=utils.timestamp_to_datetime(stories.expire_date),
|
||||
close_friends=stories.close_friends,
|
||||
client=client
|
||||
)
|
Loading…
Reference in New Issue
Block a user