From 2ad3e113a0f0974919898b1579652dcbaae39be4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 13 Apr 2018 15:17:21 +0200 Subject: [PATCH] Add utils module --- pyrogram/client/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pyrogram/client/utils.py diff --git a/pyrogram/client/utils.py b/pyrogram/client/utils.py new file mode 100644 index 00000000..f4f9a505 --- /dev/null +++ b/pyrogram/client/utils.py @@ -0,0 +1,17 @@ +from pyrogram.api import types + + +def get_peer_id(input_peer) -> int: + return ( + input_peer.user_id if isinstance(input_peer, types.InputPeerUser) + else -input_peer.chat_id if isinstance(input_peer, types.InputPeerChat) + else int("-100" + str(input_peer.channel_id)) + ) + + +def get_input_peer(peer_id: int, access_hash: int = 0): + return ( + types.InputPeerUser(peer_id, access_hash) if peer_id > 0 + else types.InputPeerChannel(int(str(peer_id).lstrip("-100")), access_hash) if str(peer_id).startswith("-100") + else types.InputPeerChat(-peer_id) + )