mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-23 23:34:28 +00:00
Update session string format (#818)
This commit is contained in:
parent
ef6125b57a
commit
fe764e0e2b
@ -36,7 +36,8 @@ class MemoryStorage(SQLiteStorage):
|
||||
|
||||
if self.name != ":memory:":
|
||||
dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack(
|
||||
self.SESSION_STRING_FORMAT,
|
||||
(self.SESSION_STRING_FORMAT if len(self.name) == MemoryStorage.SESSION_STRING_SIZE else
|
||||
self.SESSION_STRING_FORMAT_64),
|
||||
base64.urlsafe_b64decode(
|
||||
self.name + "=" * (-len(self.name) % 4)
|
||||
)
|
||||
|
@ -20,10 +20,14 @@ import base64
|
||||
import struct
|
||||
from typing import List, Tuple
|
||||
|
||||
from pyrogram import utils
|
||||
|
||||
|
||||
class Storage:
|
||||
SESSION_STRING_FORMAT = ">B?256sI?"
|
||||
SESSION_STRING_FORMAT_64 = ">B?256sQ?"
|
||||
SESSION_STRING_SIZE = 351
|
||||
SESSION_STRING_SIZE_64 = 356
|
||||
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
@ -71,13 +75,14 @@ class Storage:
|
||||
raise NotImplementedError
|
||||
|
||||
async def export_session_string(self):
|
||||
user_id = await self.user_id()
|
||||
return base64.urlsafe_b64encode(
|
||||
struct.pack(
|
||||
self.SESSION_STRING_FORMAT,
|
||||
self.SESSION_STRING_FORMAT if user_id < utils.MAX_USER_ID_OLD else self.SESSION_STRING_FORMAT_64,
|
||||
await self.dc_id(),
|
||||
await self.test_mode(),
|
||||
await self.auth_key(),
|
||||
await self.user_id(),
|
||||
user_id,
|
||||
await self.is_bot()
|
||||
)
|
||||
).decode().rstrip("=")
|
||||
|
@ -159,6 +159,7 @@ def unpack_inline_message_id(inline_message_id: str) -> "raw.types.InputBotInlin
|
||||
MIN_CHANNEL_ID = -1002147483647
|
||||
MAX_CHANNEL_ID = -1000000000000
|
||||
MIN_CHAT_ID = -2147483647
|
||||
MAX_USER_ID_OLD = 2147483647
|
||||
MAX_USER_ID = 999999999999
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user