mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-23 23:34:28 +00:00
Update get_raw_peer_id and get_peer_id
This commit is contained in:
parent
97aeee2316
commit
a4b92aabd1
@ -79,7 +79,7 @@ class GetPinnedStories:
|
||||
chats = {i.id: i for i in r.chats}
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerChannel):
|
||||
peer_id = utils.get_input_peer_id(peer)
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
if peer_id not in r.chats:
|
||||
channel = await self.invoke(raw.functions.channels.GetChannels(id=[peer]))
|
||||
chats.update({peer_id: channel.chats[0]})
|
||||
|
@ -193,9 +193,9 @@ class Story(Object, Update):
|
||||
peer_id = r[0].id
|
||||
users.update({i.id: i for i in r})
|
||||
elif isinstance(peer, raw.types.InputPeerUser):
|
||||
peer_id = utils.get_input_peer_id(peer)
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
elif isinstance(peer, raw.types.InputPeerChannel):
|
||||
peer_id = utils.get_input_peer_id(peer)
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
if peer_id not in chats:
|
||||
r = await client.invoke(raw.functions.channels.GetChannels(id=[peer]))
|
||||
chats.update({peer_id: r.chats[0]})
|
||||
|
@ -67,8 +67,6 @@ class StoryDeleted(Object, Update):
|
||||
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})
|
||||
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerChannel)):
|
||||
peer_id = utils.get_input_peer_id(peer)
|
||||
else:
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
|
||||
|
@ -83,8 +83,6 @@ class StorySkipped(Object, Update):
|
||||
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})
|
||||
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerChannel)):
|
||||
peer_id = utils.get_input_peer_id(peer)
|
||||
else:
|
||||
peer_id = utils.get_raw_peer_id(peer)
|
||||
|
||||
|
@ -268,42 +268,29 @@ MAX_USER_ID_OLD = 2147483647
|
||||
MAX_USER_ID = 999999999999
|
||||
|
||||
|
||||
def get_raw_peer_id(peer: raw.base.Peer) -> Optional[int]:
|
||||
def get_raw_peer_id(peer: Union[raw.base.Peer, raw.base.InputPeer]) -> Optional[int]:
|
||||
"""Get the raw peer id from a Peer object"""
|
||||
if isinstance(peer, raw.types.PeerUser):
|
||||
if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser)):
|
||||
return peer.user_id
|
||||
|
||||
if isinstance(peer, raw.types.PeerChat):
|
||||
if isinstance(peer, (raw.types.PeerChat, raw.types.InputPeerChat)):
|
||||
return peer.chat_id
|
||||
|
||||
if isinstance(peer, raw.types.PeerChannel):
|
||||
return peer.channel_id
|
||||
|
||||
return None
|
||||
|
||||
def get_input_peer_id(peer: raw.base.InputPeer) -> Optional[int]:
|
||||
"""Get the raw peer id from a InputPeer object"""
|
||||
if isinstance(peer, raw.types.InputPeerUser):
|
||||
return peer.user_id
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerChat):
|
||||
return peer.chat_id
|
||||
|
||||
if isinstance(peer, raw.types.InputPeerChannel):
|
||||
if isinstance(peer, (raw.types.PeerChannel, raw.types.InputPeerChannel)):
|
||||
return peer.channel_id
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_peer_id(peer: raw.base.Peer) -> int:
|
||||
def get_peer_id(peer: Union[raw.base.Peer, raw.base.InputPeer]) -> int:
|
||||
"""Get the non-raw peer id from a Peer object"""
|
||||
if isinstance(peer, raw.types.PeerUser):
|
||||
if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser)):
|
||||
return peer.user_id
|
||||
|
||||
if isinstance(peer, raw.types.PeerChat):
|
||||
if isinstance(peer, (raw.types.PeerChat, raw.types.InputPeerChat)):
|
||||
return -peer.chat_id
|
||||
|
||||
if isinstance(peer, raw.types.PeerChannel):
|
||||
if isinstance(peer, (raw.types.PeerChannel, raw.types.InputPeerChannel)):
|
||||
return MAX_CHANNEL_ID - peer.channel_id
|
||||
|
||||
raise ValueError(f"Peer type invalid: {peer}")
|
||||
@ -321,6 +308,7 @@ def get_peer_type(peer_id: int) -> str:
|
||||
|
||||
raise ValueError(f"Peer id invalid: {peer_id}")
|
||||
|
||||
|
||||
def get_reply_to(
|
||||
reply_to_message_id: Optional[int] = None,
|
||||
message_thread_id: Optional[int] = None,
|
||||
@ -346,6 +334,7 @@ def get_reply_to(
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_channel_id(peer_id: int) -> int:
|
||||
return MAX_CHANNEL_ID - peer_id
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user