Skip to content

Commit c0f55fa

Browse files
authored
Merge pull request #17 from SP-l33t/master
Update
2 parents 59f6bba + d63c7d0 commit c0f55fa

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

TGConvertor/manager.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(
1414
user_id: None | int = None,
1515
valid: None | bool = None,
1616
api: Type[APIData] = API.TelegramDesktop,
17+
phone_number: str = None,
1718
):
1819
"""
1920
Initializes a SessionManager instance with the specified parameters.
@@ -33,6 +34,7 @@ def __init__(
3334
self.api = api.copy()
3435
self.user = None
3536
self.client = None
37+
self.phone_number = phone_number
3638

3739
async def __aenter__(self):
3840
"""
@@ -74,7 +76,9 @@ async def from_telethon_file(cls, file: Union[Path, str], api=API.TelegramDeskto
7476
return cls(
7577
dc_id=session.dc_id,
7678
auth_key=session.auth_key,
77-
api=api
79+
api=api,
80+
phone_number=session.phone_number,
81+
user_id=session.user_id
7882
)
7983

8084
@classmethod
@@ -209,6 +213,7 @@ def pyrogram(self) -> PyroSession:
209213
dc_id=self.dc_id,
210214
auth_key=self.auth_key,
211215
user_id=self.user_id,
216+
api_id=self.api['api_id']
212217
)
213218

214219
@property

TGConvertor/sessions/pyro.py

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(
7171
is_bot: bool = False,
7272
test_mode: bool = False,
7373
api_id: None | int = None,
74+
date: int | None = None
7475
):
7576
self.dc_id = dc_id
7677
self.auth_key = auth_key
@@ -198,3 +199,7 @@ async def to_file(self, path: Union[Path, str]):
198199
)
199200
await db.execute(sql, params)
200201
await db.commit()
202+
sql = "INSERT INTO version VALUES (?)"
203+
params = (3,)
204+
await db.execute(sql, params)
205+
await db.commit()

TGConvertor/sessions/tele.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from ..exceptions import ValidationError
1414

15-
1615
SCHEMA = """
1716
CREATE TABLE version (version integer primary key);
1817
@@ -58,27 +57,31 @@ class TeleSession:
5857
TABLES = {
5958
"sessions": {
6059
"dc_id", "server_address", "port", "auth_key", "takeout_id"
61-
},
60+
},
6261
"entities": {"id", "hash", "username", "phone", "name", "date"},
6362
"sent_files": {"md5_digest", "file_size", "type", "id", "hash"},
6463
"update_state": {"id", "pts", "qts", "date", "seq"},
6564
"version": {"version"},
6665
}
6766

6867
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
7677
):
7778
self.dc_id = dc_id
7879
self.auth_key = auth_key
7980
self.server_address = server_address
8081
self.port = port
8182
self.takeout_id = takeout_id
83+
self.user_id = user_id
84+
self.phone_number = phone_number
8285

8386
@classmethod
8487
def from_string(cls, string: str):
@@ -104,8 +107,12 @@ async def from_file(cls, path: Path):
104107
db.row_factory = aiosqlite.Row
105108
async with db.execute("SELECT * FROM sessions") as cursor:
106109
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())}
107114

108-
return cls(**session)
115+
return cls(user_id=entities.get('id'), phone_number=entities.get('phone'), **session)
109116

110117
@classmethod
111118
async def validate(cls, path: Path) -> bool:
@@ -140,10 +147,10 @@ def decode(x: str) -> bytes:
140147
return base64.urlsafe_b64decode(x)
141148

142149
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
147154
):
148155
client = TelegramClient(
149156
session=StringSession(self.to_string()),

0 commit comments

Comments
 (0)