mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 15:34:52 +00:00
pyrofork: Add InputPeer support for utils.get_raw_peer_id and utils.get_peer_id
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
57155cbdfa
commit
6543fa11b6
1 changed files with 30 additions and 8 deletions
|
|
@ -284,31 +284,53 @@ MAX_USER_ID = 999999999999
|
||||||
def get_raw_peer_id(
|
def get_raw_peer_id(
|
||||||
peer: Union[
|
peer: Union[
|
||||||
raw.base.Peer,
|
raw.base.Peer,
|
||||||
raw.base.RequestedPeer
|
raw.base.RequestedPeer,
|
||||||
|
raw.base.InputPeer
|
||||||
]
|
]
|
||||||
) -> Optional[int]:
|
) -> Optional[int]:
|
||||||
"""Get the raw peer id from a Peer object"""
|
"""Get the raw peer id from a Peer object"""
|
||||||
if isinstance(peer, raw.types.PeerUser) or isinstance(peer, raw.types.RequestedPeerUser):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerUser)
|
||||||
|
or isinstance(peer, raw.types.RequestedPeerUser)
|
||||||
|
or isinstance(peer, raw.types.InputPeerUser)
|
||||||
|
):
|
||||||
return peer.user_id
|
return peer.user_id
|
||||||
|
|
||||||
if isinstance(peer, raw.types.PeerChat) or isinstance(peer, raw.types.RequestedPeerChat):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerChat)
|
||||||
|
or isinstance(peer, raw.types.RequestedPeerChat)
|
||||||
|
or isinstance(peer, raw.types.InputPeerChat)
|
||||||
|
):
|
||||||
return peer.chat_id
|
return peer.chat_id
|
||||||
|
|
||||||
if isinstance(peer, raw.types.PeerChannel) or isinstance(peer, raw.types.RequestedPeerChannel):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerChannel)
|
||||||
|
or isinstance(peer, raw.types.RequestedPeerChannel)
|
||||||
|
or isinstance(peer, raw.types.InputPeerChannel)
|
||||||
|
):
|
||||||
return peer.channel_id
|
return peer.channel_id
|
||||||
|
|
||||||
return None
|
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"""
|
"""Get the non-raw peer id from a Peer object"""
|
||||||
if isinstance(peer, raw.types.PeerUser):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerUser)
|
||||||
|
or isinstance(peer, raw.types.InputPeerUser)
|
||||||
|
):
|
||||||
return peer.user_id
|
return peer.user_id
|
||||||
|
|
||||||
if isinstance(peer, raw.types.PeerChat):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerChat)
|
||||||
|
or isinstance(peer, raw.types.InputPeerChat)
|
||||||
|
):
|
||||||
return -peer.chat_id
|
return -peer.chat_id
|
||||||
|
|
||||||
if isinstance(peer, raw.types.PeerChannel):
|
if (
|
||||||
|
isinstance(peer, raw.types.PeerChannel)
|
||||||
|
or isinstance(peer, raw.types.InputPeerChannel)
|
||||||
|
):
|
||||||
return MAX_CHANNEL_ID - peer.channel_id
|
return MAX_CHANNEL_ID - peer.channel_id
|
||||||
|
|
||||||
raise ValueError(f"Peer type invalid: {peer}")
|
raise ValueError(f"Peer type invalid: {peer}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue