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:
wulan17 2024-09-13 21:33:32 +07:00
parent 57155cbdfa
commit 6543fa11b6
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5

View file

@ -284,31 +284,53 @@ MAX_USER_ID = 999999999999
def get_raw_peer_id(
peer: Union[
raw.base.Peer,
raw.base.RequestedPeer
raw.base.RequestedPeer,
raw.base.InputPeer
]
) -> Optional[int]:
"""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
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
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 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)
or isinstance(peer, raw.types.InputPeerUser)
):
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
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
raise ValueError(f"Peer type invalid: {peer}")