New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add update handlers for connected, disconnected and ready #695
base: master
Are you sure you want to change the base?
Conversation
Improved Disconnect Handler: now can be registered from smart plugins and can be more than one. Added Connect Handler: same thing as Disconnect Handler but for connections. Added Client Ready Handler: fired once when client is ready first time. To implement these, I added some "sentinel" objects in session.py, which get put on the updates_queue. They hold no info and are just placeholders, so that the dispatcher can recognize them annd fire the proper handlers.
on_connect -> on_connected on_disconnect -> on_disconnected
|
Updated: there's only one handler + decorator now: |
It would unpack the list of deleted messages. Fixed
|
@sam01101 Commits can (and should) be squashed at merge time. I don't see why I should hide my progress (and mistakes!) from the PR itself |
|
Having handlers/decorators for such events is useful, but I don't like the implementation proposed here, especially because you merged them with the actual update dispatcher and filters. |


Added
@Client.on_ready()@Client.on_connected()@Client.on_disconnected()decorators (and related Handlers)
Update: it's now just
@Client.on_client_statusThese events can be registered from smart plugins and can be grouped (unlike how
DisconnectHandlerwas implemented).To achieve this, "fake" updates are pushed on dispatcher's
updates_queue. These are special "sentinel" classes defined inpyrogram.session.session.pyand hold almost no information.I had to map these handlers in the dispatcher. Also, the dispatcher used to just make a tuple of
parsed_update(the object given out by the update parser). Since these updates hold no information to parse, they don't need any other argument in the callback other thanclient. To allow this, nowparsed_updateis checked, and if not iterable, a tuple is made. Like this, parsers can return iterables with multiple args (or none).I'm not sure how docs are generated? I added the new methods and object inside the proper
.rstfiles.