From 38fb4b8d2ab26129ddaa342929b27eda87a5bbaa Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 26 Jan 2018 14:44:53 +0100 Subject: [PATCH 1/2] Add support for Bot API channel/supergroup IDs starting with -100 --- pyrogram/client/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9c838e0d..3efc1bc1 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -524,6 +524,7 @@ class Client: peer_id, peer_access_hash ) + peer_id = int("-100" + str(peer_id)) else: continue @@ -553,7 +554,7 @@ class Client: channel_id=resolved_peer.chats[0].id, access_hash=resolved_peer.chats[0].access_hash ) - chat_id = input_peer.channel_id + chat_id = int("-100" + str(input_peer.channel_id)) else: raise PeerIdInvalid @@ -577,7 +578,10 @@ class Client: try: return self.peers_by_id[chat_id] except KeyError: - raise PeerIdInvalid + try: + return self.peers_by_id[int("-100" + str(chat_id))] + except KeyError: + raise PeerIdInvalid def get_me(self): """A simple method for testing the user authorization. Requires no parameters. From df5379b47949f5b713e474bfca0155fbc3c93789 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 26 Jan 2018 15:22:07 +0100 Subject: [PATCH 2/2] Rename chat_id to peer_id for internal usage --- pyrogram/client/client.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 3efc1bc1..5fd75cc0 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -548,38 +548,38 @@ class Client: user_id=resolved_peer.users[0].id, access_hash=resolved_peer.users[0].access_hash ) - chat_id = input_peer.user_id + peer_id = input_peer.user_id elif type(resolved_peer.peer) is PeerChannel: input_peer = InputPeerChannel( channel_id=resolved_peer.chats[0].id, access_hash=resolved_peer.chats[0].access_hash ) - chat_id = int("-100" + str(input_peer.channel_id)) + peer_id = int("-100" + str(input_peer.channel_id)) else: raise PeerIdInvalid self.peers_by_username[username] = input_peer - self.peers_by_id[chat_id] = input_peer + self.peers_by_id[peer_id] = input_peer return input_peer - def resolve_peer(self, chat_id: int or str): - if chat_id in ("self", "me"): + def resolve_peer(self, peer_id: int or str): + if peer_id in ("self", "me"): return InputPeerSelf() else: - if type(chat_id) is str: - chat_id = chat_id.lower().strip("@") + if type(peer_id) is str: + peer_id = peer_id.lower().strip("@") try: - return self.peers_by_username[chat_id] + return self.peers_by_username[peer_id] except KeyError: - return self.resolve_username(chat_id) + return self.resolve_username(peer_id) else: try: - return self.peers_by_id[chat_id] + return self.peers_by_id[peer_id] except KeyError: try: - return self.peers_by_id[int("-100" + str(chat_id))] + return self.peers_by_id[int("-100" + str(peer_id))] except KeyError: raise PeerIdInvalid