mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-08 07:54:52 +00:00
pyrofork: Fix story parser (#75)
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
c4ec16b742
commit
f1bea2c32f
2 changed files with 28 additions and 16 deletions
|
|
@ -20,6 +20,7 @@ import pyrogram
|
||||||
|
|
||||||
from pyrogram import raw, types, utils
|
from pyrogram import raw, types, utils
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
class MessageStory(Object):
|
class MessageStory(Object):
|
||||||
|
|
@ -53,7 +54,7 @@ class MessageStory(Object):
|
||||||
async def _parse(
|
async def _parse(
|
||||||
client: "pyrogram.Client",
|
client: "pyrogram.Client",
|
||||||
message_story: "raw.types.MessageMediaStory"
|
message_story: "raw.types.MessageMediaStory"
|
||||||
) -> "MessageStory":
|
) -> Union["MessageStory", "types.Story"]:
|
||||||
from_user = None
|
from_user = None
|
||||||
sender_chat = None
|
sender_chat = None
|
||||||
user_id = None
|
user_id = None
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,6 @@ class Story(Object, Update):
|
||||||
id (``int``):
|
id (``int``):
|
||||||
Unique story identifier.
|
Unique story identifier.
|
||||||
|
|
||||||
chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
|
||||||
Chat the story was sent in.
|
|
||||||
|
|
||||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||||
Sender of the story.
|
Sender of the story.
|
||||||
|
|
||||||
|
|
@ -180,7 +177,12 @@ class Story(Object, Update):
|
||||||
async def _parse(
|
async def _parse(
|
||||||
client: "pyrogram.Client",
|
client: "pyrogram.Client",
|
||||||
stories: raw.base.StoryItem,
|
stories: raw.base.StoryItem,
|
||||||
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
peer: Union[
|
||||||
|
"raw.types.PeerChannel",
|
||||||
|
"raw.types.PeerUser",
|
||||||
|
"raw.types.InputPeerChannel",
|
||||||
|
"raw.types.InputPeerUser"
|
||||||
|
]
|
||||||
) -> "Story":
|
) -> "Story":
|
||||||
if isinstance(stories, raw.types.StoryItemSkipped):
|
if isinstance(stories, raw.types.StoryItemSkipped):
|
||||||
return await types.StorySkipped._parse(client, stories, peer)
|
return await types.StorySkipped._parse(client, stories, peer)
|
||||||
|
|
@ -229,20 +231,30 @@ class Story(Object, Update):
|
||||||
id=[await client.resolve_peer(chat_id)]
|
id=[await client.resolve_peer(chat_id)]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if stories.from_id is not None:
|
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
|
||||||
if getattr(stories.from_id, "user_id", None) is not None:
|
|
||||||
from_user = await client.get_users(stories.from_id.user_id)
|
|
||||||
chat = types.Chat._parse_chat(client, chat.chats[0])
|
|
||||||
elif getattr(stories.from_id, "channel_id", None) is not None:
|
|
||||||
sender_chat = types.Chat._parse_chat(client, stories.from_id.channel_id)
|
|
||||||
elif getattr(stories.from_id, "chat_id", None) is not None:
|
|
||||||
sender_chat = types.Chat._parse_chat(client, stories.from_id.chat_id)
|
|
||||||
else:
|
|
||||||
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
|
|
||||||
elif isinstance(peer, raw.types.InputPeerSelf):
|
elif isinstance(peer, raw.types.InputPeerSelf):
|
||||||
from_user = client.me
|
from_user = client.me
|
||||||
else:
|
else:
|
||||||
from_user = await client.get_users(peer.user_id)
|
from_user = await client.get_users(peer.user_id)
|
||||||
|
|
||||||
|
from_id = getattr(stories, "from_id", None)
|
||||||
|
if from_id is not None:
|
||||||
|
if getattr(from_id, "user_id", None) is not None:
|
||||||
|
from_user = await client.get_users(getattr(from_id, "user_id"))
|
||||||
|
elif getattr(from_id, "channel_id", None) is not None:
|
||||||
|
chat = await client.invoke(
|
||||||
|
raw.functions.channels.GetChannels(
|
||||||
|
id=[await client.resolve_peer(utils.get_channel_id(getattr(from_id, "channel_id")))]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
|
||||||
|
elif getattr(from_id, "chat_id", None) is not None:
|
||||||
|
chat = await client.invoke(
|
||||||
|
raw.functions.channels.GetChannels(
|
||||||
|
id=[await client.resolve_peer(utils.get_channel_id(getattr(from_id, "chat_id")))]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
|
||||||
|
|
||||||
for priv in stories.privacy:
|
for priv in stories.privacy:
|
||||||
if isinstance(priv, raw.types.PrivacyValueAllowAll):
|
if isinstance(priv, raw.types.PrivacyValueAllowAll):
|
||||||
|
|
@ -281,7 +293,6 @@ class Story(Object, Update):
|
||||||
|
|
||||||
return Story(
|
return Story(
|
||||||
id=stories.id,
|
id=stories.id,
|
||||||
chat=chat,
|
|
||||||
from_user=from_user,
|
from_user=from_user,
|
||||||
sender_chat=sender_chat,
|
sender_chat=sender_chat,
|
||||||
date=utils.timestamp_to_datetime(stories.date),
|
date=utils.timestamp_to_datetime(stories.date),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue