mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Update Storage API usages in client.py, auth.py and session.py
This commit is contained in:
parent
0097df2952
commit
1a7d0b1b7e
@ -260,12 +260,12 @@ class Client(Methods, BaseClient):
|
|||||||
self.load_config()
|
self.load_config()
|
||||||
self.load_session()
|
self.load_session()
|
||||||
|
|
||||||
self.session = Session(self, self.storage.dc_id, self.storage.auth_key)
|
self.session = Session(self, self.storage.dc_id(), self.storage.auth_key())
|
||||||
self.session.start()
|
self.session.start()
|
||||||
|
|
||||||
self.is_connected = True
|
self.is_connected = True
|
||||||
|
|
||||||
return bool(self.storage.user_id)
|
return bool(self.storage.user_id())
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
"""Disconnect the client from Telegram servers.
|
"""Disconnect the client from Telegram servers.
|
||||||
@ -398,9 +398,9 @@ class Client(Methods, BaseClient):
|
|||||||
except (PhoneMigrate, NetworkMigrate) as e:
|
except (PhoneMigrate, NetworkMigrate) as e:
|
||||||
self.session.stop()
|
self.session.stop()
|
||||||
|
|
||||||
self.storage.dc_id = e.x
|
self.storage.dc_id(e.x)
|
||||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
self.storage.auth_key(Auth(self, self.storage.dc_id()).create())
|
||||||
self.session = Session(self, self.storage.dc_id, self.storage.auth_key)
|
self.session = Session(self, self.storage.dc_id(), self.storage.auth_key())
|
||||||
|
|
||||||
self.session.start()
|
self.session.start()
|
||||||
else:
|
else:
|
||||||
@ -475,8 +475,8 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.storage.user_id = r.user.id
|
self.storage.user_id(r.user.id)
|
||||||
self.storage.is_bot = False
|
self.storage.is_bot(False)
|
||||||
|
|
||||||
return User._parse(self, r.user)
|
return User._parse(self, r.user)
|
||||||
|
|
||||||
@ -513,8 +513,8 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.storage.user_id = r.user.id
|
self.storage.user_id(r.user.id)
|
||||||
self.storage.is_bot = False
|
self.storage.is_bot(False)
|
||||||
|
|
||||||
return User._parse(self, r.user)
|
return User._parse(self, r.user)
|
||||||
|
|
||||||
@ -544,14 +544,14 @@ class Client(Methods, BaseClient):
|
|||||||
except UserMigrate as e:
|
except UserMigrate as e:
|
||||||
self.session.stop()
|
self.session.stop()
|
||||||
|
|
||||||
self.storage.dc_id = e.x
|
self.storage.dc_id(e.x)
|
||||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
self.storage.auth_key(Auth(self, self.storage.dc_id()).create())
|
||||||
self.session = Session(self, self.storage.dc_id, self.storage.auth_key)
|
self.session = Session(self, self.storage.dc_id(), self.storage.auth_key())
|
||||||
|
|
||||||
self.session.start()
|
self.session.start()
|
||||||
else:
|
else:
|
||||||
self.storage.user_id = r.user.id
|
self.storage.user_id(r.user.id)
|
||||||
self.storage.is_bot = True
|
self.storage.is_bot(True)
|
||||||
|
|
||||||
return User._parse(self, r.user)
|
return User._parse(self, r.user)
|
||||||
|
|
||||||
@ -585,8 +585,8 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.storage.user_id = r.user.id
|
self.storage.user_id(r.user.id)
|
||||||
self.storage.is_bot = False
|
self.storage.is_bot(False)
|
||||||
|
|
||||||
return User._parse(self, r.user)
|
return User._parse(self, r.user)
|
||||||
|
|
||||||
@ -622,8 +622,8 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.storage.user_id = r.user.id
|
self.storage.user_id(r.user.id)
|
||||||
self.storage.is_bot = False
|
self.storage.is_bot(False)
|
||||||
|
|
||||||
return User._parse(self, r.user)
|
return User._parse(self, r.user)
|
||||||
|
|
||||||
@ -828,7 +828,7 @@ class Client(Methods, BaseClient):
|
|||||||
if not is_authorized:
|
if not is_authorized:
|
||||||
self.authorize()
|
self.authorize()
|
||||||
|
|
||||||
if not self.storage.is_bot and self.takeout:
|
if not self.storage.is_bot() and self.takeout:
|
||||||
self.takeout_id = self.send(functions.account.InitTakeoutSession()).id
|
self.takeout_id = self.send(functions.account.InitTakeoutSession()).id
|
||||||
log.warning("Takeout session {} initiated".format(self.takeout_id))
|
log.warning("Takeout session {} initiated".format(self.takeout_id))
|
||||||
|
|
||||||
@ -1461,20 +1461,20 @@ class Client(Methods, BaseClient):
|
|||||||
self.storage.open()
|
self.storage.open()
|
||||||
|
|
||||||
session_empty = any([
|
session_empty = any([
|
||||||
self.storage.test_mode is None,
|
self.storage.test_mode() is None,
|
||||||
self.storage.auth_key is None,
|
self.storage.auth_key() is None,
|
||||||
self.storage.user_id is None,
|
self.storage.user_id() is None,
|
||||||
self.storage.is_bot is None
|
self.storage.is_bot() is None
|
||||||
])
|
])
|
||||||
|
|
||||||
if session_empty:
|
if session_empty:
|
||||||
self.storage.dc_id = 2
|
self.storage.dc_id(2)
|
||||||
self.storage.date = 0
|
self.storage.date(0)
|
||||||
|
|
||||||
self.storage.test_mode = self.test_mode
|
self.storage.test_mode(self.test_mode)
|
||||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
self.storage.auth_key(Auth(self, self.storage.dc_id()).create())
|
||||||
self.storage.user_id = None
|
self.storage.user_id(None)
|
||||||
self.storage.is_bot = None
|
self.storage.is_bot(None)
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
if self.plugins:
|
if self.plugins:
|
||||||
@ -1682,7 +1682,7 @@ class Client(Methods, BaseClient):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise PeerIdInvalid
|
raise PeerIdInvalid
|
||||||
|
|
||||||
peer_type = utils.get_type(peer_id)
|
peer_type = utils.get_peer_type(peer_id)
|
||||||
|
|
||||||
if peer_type == "user":
|
if peer_type == "user":
|
||||||
self.fetch_peers(
|
self.fetch_peers(
|
||||||
@ -1790,7 +1790,7 @@ class Client(Methods, BaseClient):
|
|||||||
file_id = file_id or self.rnd_id()
|
file_id = file_id or self.rnd_id()
|
||||||
md5_sum = md5() if not is_big and not is_missing_part else None
|
md5_sum = md5() if not is_big and not is_missing_part else None
|
||||||
|
|
||||||
session = Session(self, self.storage.dc_id, self.storage.auth_key, is_media=True)
|
session = Session(self, self.storage.dc_id(), self.storage.auth_key(), is_media=True)
|
||||||
session.start()
|
session.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1877,7 +1877,7 @@ class Client(Methods, BaseClient):
|
|||||||
session = self.media_sessions.get(dc_id, None)
|
session = self.media_sessions.get(dc_id, None)
|
||||||
|
|
||||||
if session is None:
|
if session is None:
|
||||||
if dc_id != self.storage.dc_id:
|
if dc_id != self.storage.dc_id():
|
||||||
session = Session(self, dc_id, Auth(self, dc_id).create(), is_media=True)
|
session = Session(self, dc_id, Auth(self, dc_id).create(), is_media=True)
|
||||||
session.start()
|
session.start()
|
||||||
|
|
||||||
@ -1903,7 +1903,7 @@ class Client(Methods, BaseClient):
|
|||||||
session.stop()
|
session.stop()
|
||||||
raise AuthBytesInvalid
|
raise AuthBytesInvalid
|
||||||
else:
|
else:
|
||||||
session = Session(self, dc_id, self.storage.auth_key, is_media=True)
|
session = Session(self, dc_id, self.storage.auth_key(), is_media=True)
|
||||||
session.start()
|
session.start()
|
||||||
|
|
||||||
self.media_sessions[dc_id] = session
|
self.media_sessions[dc_id] = session
|
||||||
|
@ -37,7 +37,7 @@ class Auth:
|
|||||||
|
|
||||||
def __init__(self, client: "pyrogram.Client", dc_id: int):
|
def __init__(self, client: "pyrogram.Client", dc_id: int):
|
||||||
self.dc_id = dc_id
|
self.dc_id = dc_id
|
||||||
self.test_mode = client.storage.test_mode
|
self.test_mode = client.storage.test_mode()
|
||||||
self.ipv6 = client.ipv6
|
self.ipv6 = client.ipv6
|
||||||
self.proxy = client.proxy
|
self.proxy = client.proxy
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class Session:
|
|||||||
while True:
|
while True:
|
||||||
self.connection = Connection(
|
self.connection = Connection(
|
||||||
self.dc_id,
|
self.dc_id,
|
||||||
self.client.storage.test_mode,
|
self.client.storage.test_mode(),
|
||||||
self.client.ipv6,
|
self.client.ipv6,
|
||||||
self.client.proxy
|
self.client.proxy
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user