Visitar URL original
Allow to hook load and save functions to use external session storage… by ezdev128 · Pull Request #36 · pyrogram/pyrogram · GitHub
Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow to hook load and save functions to use external session storage…
… implementations
  • Loading branch information
ezdev128 committed Mar 18, 2018
commit 6b37046254d79274ab589d9a80ff166429e3dc67
2 changes: 1 addition & 1 deletion pyrogram/client/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)

@delivrance delivrance Mar 19, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you indented it wrongly, but this piece of code is always needed:

self.session = Session(...)

Here is where Pyrogram creates a new connection to the server.


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