mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Add support for Bot API style basic group IDs (with minus sign)
Closes #32
This commit is contained in:
parent
859305b744
commit
f55062bc6d
@ -256,15 +256,16 @@ class Client:
|
|||||||
|
|
||||||
if isinstance(entity, Chat):
|
if isinstance(entity, Chat):
|
||||||
chat_id = entity.id
|
chat_id = entity.id
|
||||||
|
peer_id = -chat_id
|
||||||
|
|
||||||
if chat_id in self.peers_by_id:
|
if peer_id in self.peers_by_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
input_peer = InputPeerChat(
|
input_peer = InputPeerChat(
|
||||||
chat_id=chat_id
|
chat_id=chat_id
|
||||||
)
|
)
|
||||||
|
|
||||||
self.peers_by_id[chat_id] = input_peer
|
self.peers_by_id[peer_id] = input_peer
|
||||||
|
|
||||||
if isinstance(entity, Channel):
|
if isinstance(entity, Channel):
|
||||||
channel_id = entity.id
|
channel_id = entity.id
|
||||||
@ -886,17 +887,20 @@ class Client:
|
|||||||
if isinstance(peer_id, types.PeerUser):
|
if isinstance(peer_id, types.PeerUser):
|
||||||
peer_id = peer_id.user_id
|
peer_id = peer_id.user_id
|
||||||
elif isinstance(peer_id, types.PeerChat):
|
elif isinstance(peer_id, types.PeerChat):
|
||||||
peer_id = peer_id.chat_id
|
peer_id = -peer_id.chat_id
|
||||||
elif isinstance(peer_id, types.PeerChannel):
|
elif isinstance(peer_id, types.PeerChannel):
|
||||||
peer_id = int("-100" + str(peer_id.channel_id))
|
peer_id = int("-100" + str(peer_id.channel_id))
|
||||||
|
|
||||||
try:
|
try: # User
|
||||||
return self.peers_by_id[peer_id]
|
return self.peers_by_id[peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try: # Chat
|
||||||
return self.peers_by_id[int("-100" + str(peer_id))]
|
return self.peers_by_id[-peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise PeerIdInvalid
|
try: # Channel
|
||||||
|
return self.peers_by_id[int("-100" + str(peer_id))]
|
||||||
|
except (KeyError, ValueError):
|
||||||
|
raise PeerIdInvalid
|
||||||
|
|
||||||
def get_me(self):
|
def get_me(self):
|
||||||
"""A simple method for testing the user authorization. Requires no parameters.
|
"""A simple method for testing the user authorization. Requires no parameters.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user