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_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.is_connected = True
|
||||
|
||||
return bool(self.storage.user_id)
|
||||
return bool(self.storage.user_id())
|
||||
|
||||
def disconnect(self):
|
||||
"""Disconnect the client from Telegram servers.
|
||||
@ -398,9 +398,9 @@ class Client(Methods, BaseClient):
|
||||
except (PhoneMigrate, NetworkMigrate) as e:
|
||||
self.session.stop()
|
||||
|
||||
self.storage.dc_id = e.x
|
||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
||||
self.session = Session(self, self.storage.dc_id, self.storage.auth_key)
|
||||
self.storage.dc_id(e.x)
|
||||
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.start()
|
||||
else:
|
||||
@ -475,8 +475,8 @@ class Client(Methods, BaseClient):
|
||||
|
||||
return False
|
||||
else:
|
||||
self.storage.user_id = r.user.id
|
||||
self.storage.is_bot = False
|
||||
self.storage.user_id(r.user.id)
|
||||
self.storage.is_bot(False)
|
||||
|
||||
return User._parse(self, r.user)
|
||||
|
||||
@ -513,8 +513,8 @@ class Client(Methods, BaseClient):
|
||||
)
|
||||
)
|
||||
|
||||
self.storage.user_id = r.user.id
|
||||
self.storage.is_bot = False
|
||||
self.storage.user_id(r.user.id)
|
||||
self.storage.is_bot(False)
|
||||
|
||||
return User._parse(self, r.user)
|
||||
|
||||
@ -544,14 +544,14 @@ class Client(Methods, BaseClient):
|
||||
except UserMigrate as e:
|
||||
self.session.stop()
|
||||
|
||||
self.storage.dc_id = e.x
|
||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
||||
self.session = Session(self, self.storage.dc_id, self.storage.auth_key)
|
||||
self.storage.dc_id(e.x)
|
||||
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.start()
|
||||
else:
|
||||
self.storage.user_id = r.user.id
|
||||
self.storage.is_bot = True
|
||||
self.storage.user_id(r.user.id)
|
||||
self.storage.is_bot(True)
|
||||
|
||||
return User._parse(self, r.user)
|
||||
|
||||
@ -585,8 +585,8 @@ class Client(Methods, BaseClient):
|
||||
)
|
||||
)
|
||||
|
||||
self.storage.user_id = r.user.id
|
||||
self.storage.is_bot = False
|
||||
self.storage.user_id(r.user.id)
|
||||
self.storage.is_bot(False)
|
||||
|
||||
return User._parse(self, r.user)
|
||||
|
||||
@ -622,8 +622,8 @@ class Client(Methods, BaseClient):
|
||||
)
|
||||
)
|
||||
|
||||
self.storage.user_id = r.user.id
|
||||
self.storage.is_bot = False
|
||||
self.storage.user_id(r.user.id)
|
||||
self.storage.is_bot(False)
|
||||
|
||||
return User._parse(self, r.user)
|
||||
|
||||
@ -828,7 +828,7 @@ class Client(Methods, BaseClient):
|
||||
if not is_authorized:
|
||||
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
|
||||
log.warning("Takeout session {} initiated".format(self.takeout_id))
|
||||
|
||||
@ -1461,20 +1461,20 @@ class Client(Methods, BaseClient):
|
||||
self.storage.open()
|
||||
|
||||
session_empty = any([
|
||||
self.storage.test_mode is None,
|
||||
self.storage.auth_key is None,
|
||||
self.storage.user_id is None,
|
||||
self.storage.is_bot is None
|
||||
self.storage.test_mode() is None,
|
||||
self.storage.auth_key() is None,
|
||||
self.storage.user_id() is None,
|
||||
self.storage.is_bot() is None
|
||||
])
|
||||
|
||||
if session_empty:
|
||||
self.storage.dc_id = 2
|
||||
self.storage.date = 0
|
||||
self.storage.dc_id(2)
|
||||
self.storage.date(0)
|
||||
|
||||
self.storage.test_mode = self.test_mode
|
||||
self.storage.auth_key = Auth(self, self.storage.dc_id).create()
|
||||
self.storage.user_id = None
|
||||
self.storage.is_bot = None
|
||||
self.storage.test_mode(self.test_mode)
|
||||
self.storage.auth_key(Auth(self, self.storage.dc_id()).create())
|
||||
self.storage.user_id(None)
|
||||
self.storage.is_bot(None)
|
||||
|
||||
def load_plugins(self):
|
||||
if self.plugins:
|
||||
@ -1682,7 +1682,7 @@ class Client(Methods, BaseClient):
|
||||
except KeyError:
|
||||
raise PeerIdInvalid
|
||||
|
||||
peer_type = utils.get_type(peer_id)
|
||||
peer_type = utils.get_peer_type(peer_id)
|
||||
|
||||
if peer_type == "user":
|
||||
self.fetch_peers(
|
||||
@ -1790,7 +1790,7 @@ class Client(Methods, BaseClient):
|
||||
file_id = file_id or self.rnd_id()
|
||||
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()
|
||||
|
||||
try:
|
||||
@ -1877,7 +1877,7 @@ class Client(Methods, BaseClient):
|
||||
session = self.media_sessions.get(dc_id, 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.start()
|
||||
|
||||
@ -1903,7 +1903,7 @@ class Client(Methods, BaseClient):
|
||||
session.stop()
|
||||
raise AuthBytesInvalid
|
||||
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()
|
||||
|
||||
self.media_sessions[dc_id] = session
|
||||
|
@ -37,7 +37,7 @@ class Auth:
|
||||
|
||||
def __init__(self, client: "pyrogram.Client", dc_id: int):
|
||||
self.dc_id = dc_id
|
||||
self.test_mode = client.storage.test_mode
|
||||
self.test_mode = client.storage.test_mode()
|
||||
self.ipv6 = client.ipv6
|
||||
self.proxy = client.proxy
|
||||
|
||||
|
@ -117,7 +117,7 @@ class Session:
|
||||
while True:
|
||||
self.connection = Connection(
|
||||
self.dc_id,
|
||||
self.client.storage.test_mode,
|
||||
self.client.storage.test_mode(),
|
||||
self.client.ipv6,
|
||||
self.client.proxy
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user