Skip to content

Commit

Permalink
pyrofork: Fix story parser (Mayuri-Chan#75)
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <[email protected]>

(cherry picked from commit f1bea2c)
Signed-off-by: eyMarv <[email protected]>
  • Loading branch information
wulan17 authored and eyMarv committed Jun 17, 2024
1 parent 3d2e1c4 commit a722a32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
6 changes: 4 additions & 2 deletions pyrogram/types/messages_and_media/message_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pyrogram
from pyrogram import raw, types, utils
from ..object import Object
from typing import Union


class MessageStory(Object):
Expand Down Expand Up @@ -53,8 +54,9 @@ def __init__(

@staticmethod
async def _parse(
client: "pyrogram.Client", message_story: "raw.types.MessageMediaStory"
) -> "MessageStory":
client: "pyrogram.Client",
message_story: "raw.types.MessageMediaStory"
) -> Union["MessageStory", "types.Story"]:
from_user = None
sender_chat = None
user_id = None
Expand Down
41 changes: 26 additions & 15 deletions pyrogram/types/messages_and_media/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ def __init__(
async def _parse(
client: "pyrogram.Client",
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":
if isinstance(stories, raw.types.StoryItemSkipped):
return await types.StorySkipped._parse(client, stories, peer)
Expand Down Expand Up @@ -252,25 +257,31 @@ async def _parse(
id=[await client.resolve_peer(chat_id)]
)
)
if stories.from_id is not None:
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])
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
elif isinstance(peer, raw.types.InputPeerSelf):
from_user = client.me
else:
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:
if isinstance(priv, raw.types.PrivacyValueAllowAll):
privacy = enums.StoryPrivacy.PUBLIC
Expand Down

0 comments on commit a722a32

Please sign in to comment.