Skip to content

Commit

Permalink
Allow to hook load and save functions to use external session storage…
Browse files Browse the repository at this point in the history
… implementations
  • Loading branch information
ezdev128 committed Mar 18, 2018
1 parent 5b5fb6c commit 6b37046
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyrogram/client/__init__.py
Expand Up @@ -17,6 +17,6 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from .chat_action import ChatAction
from .client import Client
from .client import Client, Proxy
from .parse_mode import ParseMode
from .emoji import Emoji
13 changes: 11 additions & 2 deletions pyrogram/client/client.py
Expand Up @@ -175,6 +175,9 @@ def __init__(self,

self.download_queue = Queue()

self.load_session_hook = None
self.save_session_hook = None

def start(self):
"""Use this method to start the Client after creating it.
Requires no parameters.
Expand All @@ -183,7 +186,10 @@ def start(self):
:class:`pyrogram.Error`
"""
self.load_config()
self.load_session(self.session_name)
if callable(self.load_session_hook):
self.load_session_hook(self)
else:
self.load_session(self.session_name)

self.session = Session(
self.dc_id,
Expand All @@ -202,7 +208,10 @@ def start(self):
else:
self.authorize_bot()

self.save_session()
if callable(self.save_session_hook):
self.save_session_hook(self)
else:
self.save_session()

if self.token is None:
self.get_dialogs()
Expand Down

0 comments on commit 6b37046

Please sign in to comment.