mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: fix some derps
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
8309f9420b
commit
e956bcaac0
4 changed files with 75 additions and 70 deletions
|
|
@ -129,7 +129,9 @@ class Dispatcher:
|
|||
ChatJoinRequestHandler
|
||||
)
|
||||
|
||||
async def story_parser(update, _, __):
|
||||
async def story_parser(update, users, chats):
|
||||
print(update)
|
||||
print(update.story)
|
||||
return (
|
||||
await pyrogram.types.Story._parse(self.client, update.story, update.peer),
|
||||
StoryHandler
|
||||
|
|
|
|||
|
|
@ -142,68 +142,68 @@ class Story(Object, Update):
|
|||
stories: raw.base.StoryItem,
|
||||
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
|
||||
) -> "Story":
|
||||
if isinstance(stories, raw.types.StoryItem):
|
||||
entities = [types.MessageEntity._parse(client, entity, {}) for entity in stories.entities]
|
||||
entities = types.List(filter(lambda x: x is not None, entities))
|
||||
animation = None
|
||||
photo = None
|
||||
video = None
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
if stories.media:
|
||||
if isinstance(stories.media, raw.types.MessageMediaPhoto):
|
||||
photo = types.Photo._parse(client, stories.media.photo, stories.media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.PHOTO
|
||||
elif isinstance(stories.media, raw.types.MessageMediaDocument):
|
||||
doc = stories.media.document
|
||||
|
||||
if isinstance(doc, raw.types.Document):
|
||||
attributes = {type(i): i for i in doc.attributes}
|
||||
|
||||
if raw.types.DocumentAttributeAnimated in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
animation = types.Animation._parse(client, doc, video_attributes, None)
|
||||
media_type = enums.MessageMediaType.ANIMATION
|
||||
elif raw.types.DocumentAttributeVideo in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
video = types.Video._parse(client, doc, video_attributes, None, stories.media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.VIDEO
|
||||
else:
|
||||
media_type = None
|
||||
else:
|
||||
media_type = None
|
||||
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(
|
||||
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),
|
||||
media=media_type,
|
||||
has_protected_content=stories.noforwards,
|
||||
animation=animation,
|
||||
photo=photo,
|
||||
video=video,
|
||||
edited=stories.edited,
|
||||
pinned=stories.pinned,
|
||||
public=stories.public,
|
||||
close_friends=stories.close_friends,
|
||||
contacts=stories.contacts,
|
||||
selected_contacts=stories.selected_contacts,
|
||||
caption=stories.caption,
|
||||
caption_entities=entities or None,
|
||||
views=types.StoryViews._parse(stories.views)
|
||||
)
|
||||
if isinstance(stories, raw.types.StoryItemSkipped):
|
||||
return await types.StorySkipped()._parse(client, stories, peer)
|
||||
return await types.StorySkipped._parse(client, stories, peer)
|
||||
if isinstance(stories, raw.types.StoryItemDeleted):
|
||||
return await types.StoryDeleted()._parse(client, stories, peer)
|
||||
return await types.StoryDeleted._parse(client, stories, peer)
|
||||
entities = [types.MessageEntity._parse(client, entity, {}) for entity in stories.entities]
|
||||
entities = types.List(filter(lambda x: x is not None, entities))
|
||||
animation = None
|
||||
photo = None
|
||||
video = None
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
if stories.media:
|
||||
if isinstance(stories.media, raw.types.MessageMediaPhoto):
|
||||
photo = types.Photo._parse(client, stories.media.photo, stories.media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.PHOTO
|
||||
elif isinstance(stories.media, raw.types.MessageMediaDocument):
|
||||
doc = stories.media.document
|
||||
|
||||
if isinstance(doc, raw.types.Document):
|
||||
attributes = {type(i): i for i in doc.attributes}
|
||||
|
||||
if raw.types.DocumentAttributeAnimated in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
animation = types.Animation._parse(client, doc, video_attributes, None)
|
||||
media_type = enums.MessageMediaType.ANIMATION
|
||||
elif raw.types.DocumentAttributeVideo in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
video = types.Video._parse(client, doc, video_attributes, None, stories.media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.VIDEO
|
||||
else:
|
||||
media_type = None
|
||||
else:
|
||||
media_type = None
|
||||
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(
|
||||
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),
|
||||
media=media_type,
|
||||
has_protected_content=stories.noforwards,
|
||||
animation=animation,
|
||||
photo=photo,
|
||||
video=video,
|
||||
edited=stories.edited,
|
||||
pinned=stories.pinned,
|
||||
public=stories.public,
|
||||
close_friends=stories.close_friends,
|
||||
contacts=stories.contacts,
|
||||
selected_contacts=stories.selected_contacts,
|
||||
caption=stories.caption,
|
||||
caption_entities=entities or None,
|
||||
views=types.StoryViews._parse(stories.views),
|
||||
client=client
|
||||
)
|
||||
|
||||
async def reply_text(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@
|
|||
|
||||
import pyrogram
|
||||
|
||||
from datetime import datetime
|
||||
from pyrogram import enums, raw, types, utils
|
||||
from typing import BinaryIO, Callable, List, Optional, Union
|
||||
from pyrogram import raw, types
|
||||
from typing import Union
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
|
|
@ -49,6 +48,8 @@ class StoryDeleted(Object, Update):
|
|||
super().__init__(client)
|
||||
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.sender_chat = sender_chat
|
||||
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
|
|
@ -67,5 +68,6 @@ class StoryDeleted(Object, Update):
|
|||
return StoryDeleted(
|
||||
id=stories.id,
|
||||
from_user=from_user,
|
||||
sender_chat=sender_chat
|
||||
sender_chat=sender_chat,
|
||||
client=client
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
import pyrogram
|
||||
|
||||
from datetime import datetime
|
||||
from pyrogram import enums, raw, types, utils
|
||||
from typing import BinaryIO, Callable, List, Optional, Union
|
||||
from pyrogram import raw, types, utils
|
||||
from typing import Union
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
|
|
@ -47,8 +47,6 @@ class StorySkipped(Object, Update):
|
|||
True, if the Story is shared with close_friends only.
|
||||
"""
|
||||
|
||||
# TODO: Add Privacy
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
|
|
@ -63,6 +61,8 @@ class StorySkipped(Object, Update):
|
|||
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
|
||||
|
|
@ -87,5 +87,6 @@ class StorySkipped(Object, Update):
|
|||
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
|
||||
close_friends=stories.close_friends,
|
||||
client=client
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue