mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add log_out method
This commit is contained in:
parent
c7782b146f
commit
cfd756bd24
@ -264,6 +264,7 @@ def pyrogram_api():
|
||||
send_recovery_code
|
||||
recover_password
|
||||
accept_terms_of_service
|
||||
log_out
|
||||
""",
|
||||
advanced="""
|
||||
Advanced
|
||||
|
@ -222,7 +222,10 @@ class Client(Methods, BaseClient):
|
||||
return self.start()
|
||||
|
||||
def __exit__(self, *args):
|
||||
try:
|
||||
self.stop()
|
||||
except ConnectionError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def proxy(self):
|
||||
@ -773,6 +776,27 @@ class Client(Methods, BaseClient):
|
||||
|
||||
return signed_up
|
||||
|
||||
def log_out(self):
|
||||
"""Log out from Telegram and delete the *\\*.session* file.
|
||||
|
||||
When you log out, the current client is stopped and the storage session destroyed.
|
||||
No more API calls can be made until you start the client and re-authorize again.
|
||||
|
||||
Returns:
|
||||
``bool``: On success, True is returned.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
# Log out.
|
||||
app.log_out()
|
||||
"""
|
||||
self.send(functions.auth.LogOut())
|
||||
self.stop()
|
||||
self.storage.destroy()
|
||||
|
||||
return True
|
||||
|
||||
def start(self):
|
||||
"""Start the client.
|
||||
|
||||
@ -1338,7 +1362,7 @@ class Client(Methods, BaseClient):
|
||||
elif isinstance(updates, types.UpdateShort):
|
||||
self.dispatcher.updates_queue.put((updates.update, {}, {}))
|
||||
elif isinstance(updates, types.UpdatesTooLong):
|
||||
log.warning(updates)
|
||||
log.info(updates)
|
||||
except Exception as e:
|
||||
log.error(e, exc_info=True)
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
import base64
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
@ -108,3 +109,6 @@ class FileStorage(MemoryStorage):
|
||||
|
||||
with self.conn:
|
||||
self.conn.execute("VACUUM")
|
||||
|
||||
def destroy(self):
|
||||
os.remove(self.database)
|
||||
|
@ -97,6 +97,9 @@ class MemoryStorage(Storage):
|
||||
with self.lock:
|
||||
self.conn.close()
|
||||
|
||||
def destroy(self):
|
||||
pass
|
||||
|
||||
def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
|
||||
with self.lock:
|
||||
self.conn.executemany(
|
||||
|
@ -30,6 +30,9 @@ class Storage:
|
||||
def close(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def destroy(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def update_peers(self, peers):
|
||||
raise NotImplementedError
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user