12
12
13
13
from ..exceptions import ValidationError
14
14
15
-
16
15
SCHEMA = """
17
16
CREATE TABLE version (version integer primary key);
18
17
@@ -58,27 +57,31 @@ class TeleSession:
58
57
TABLES = {
59
58
"sessions" : {
60
59
"dc_id" , "server_address" , "port" , "auth_key" , "takeout_id"
61
- },
60
+ },
62
61
"entities" : {"id" , "hash" , "username" , "phone" , "name" , "date" },
63
62
"sent_files" : {"md5_digest" , "file_size" , "type" , "id" , "hash" },
64
63
"update_state" : {"id" , "pts" , "qts" , "date" , "seq" },
65
64
"version" : {"version" },
66
65
}
67
66
68
67
def __init__ (
69
- self ,
70
- * ,
71
- dc_id : int ,
72
- auth_key : bytes ,
73
- server_address : None | str = None ,
74
- port : None | int = None ,
75
- takeout_id : None | int = None
68
+ self ,
69
+ * ,
70
+ dc_id : int ,
71
+ auth_key : bytes ,
72
+ server_address : None | str = None ,
73
+ port : None | int = None ,
74
+ takeout_id : None | int = None ,
75
+ user_id : None | int = None ,
76
+ phone_number : None | int = None
76
77
):
77
78
self .dc_id = dc_id
78
79
self .auth_key = auth_key
79
80
self .server_address = server_address
80
81
self .port = port
81
82
self .takeout_id = takeout_id
83
+ self .user_id = user_id
84
+ self .phone_number = phone_number
82
85
83
86
@classmethod
84
87
def from_string (cls , string : str ):
@@ -104,8 +107,12 @@ async def from_file(cls, path: Path):
104
107
db .row_factory = aiosqlite .Row
105
108
async with db .execute ("SELECT * FROM sessions" ) as cursor :
106
109
session = await cursor .fetchone ()
110
+ async with aiosqlite .connect (path ) as db :
111
+ db .row_factory = aiosqlite .Row
112
+ async with db .execute ("SELECT * FROM entities WHERE id NOT LIKE 0" ) as cursor :
113
+ entities = {** (await cursor .fetchone ())}
107
114
108
- return cls (** session )
115
+ return cls (user_id = entities . get ( 'id' ), phone_number = entities . get ( 'phone' ), ** session )
109
116
110
117
@classmethod
111
118
async def validate (cls , path : Path ) -> bool :
@@ -140,10 +147,10 @@ def decode(x: str) -> bytes:
140
147
return base64 .urlsafe_b64decode (x )
141
148
142
149
def client (
143
- self ,
144
- api : Type [APIData ],
145
- proxy : None | dict = None ,
146
- no_updates : bool = True
150
+ self ,
151
+ api : Type [APIData ],
152
+ proxy : None | dict = None ,
153
+ no_updates : bool = True
147
154
):
148
155
client = TelegramClient (
149
156
session = StringSession (self .to_string ()),
0 commit comments