mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Better shifted_id method
This commit is contained in:
parent
56c5c20241
commit
bd9827d617
1 changed files with 9 additions and 1 deletions
|
|
@ -60,5 +60,13 @@ class Chat(TelegramObject):
|
|||
"""
|
||||
Returns shifted chat ID (positive and without "-100" prefix).
|
||||
Mostly used for private links like t.me/c/chat_id/message_id
|
||||
|
||||
Currently supergroup/channel IDs have 10-digit ID after "-100" prefix removed.
|
||||
However, these IDs might become 11-digit in future. So, first we remove "-100"
|
||||
prefix and count remaining number length. Then we multiple
|
||||
-1 * 10 ^ (number_length + 2)
|
||||
Finally, self.id is substracted from that number
|
||||
"""
|
||||
return abs(self.id + 1_000_000_000_000)
|
||||
short_id = str(self.id).replace("-100", "")
|
||||
shift = int(-1 * pow(10, len(short_id)+2))
|
||||
return shift - self.id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue