A modified pyromod by www.da.gd/aditya
Project description
PatchPyro
This is a fork of pyromod (renamed as patchpyro) for personal usecases.
Remember that this fork contains only conversation patch.
Requirements:
pyrogram>=2.0.69
python>=3.9
Installation:
python -m pip install patchpyro
Usage:
Import patchpyro
at least one time in your script, so you'll be able to use modified pyrogram in all files of the same proccess.
Example:
# config.py
from patchpyro import listen # or import patchpyro.listen
from pyrogram import Client
mybot = Client("mysession")
# any other .py
from config import mybot
# no need to import patchpyro again pyrogram is already monkeypatched globally (at the same proccess)
patchpyro.listen
Just import it, it will automatically do the monkeypatch and you'll get these new methods:
- Available bound methods::
-
Chat.listen, User.listen
await mybot.listen(chat_id, filters=None, timeout=30)
- raises
asyncio.TimeoutError
if timeout (optional parameter) - Awaits for a new message in the specified chat and returns it.
- You can pass Update Filters to the filters parameter just like you do for the update handlers.
- E.g.
filters=filters.photo & filters.bot
-
Chat.ask, User.ask
await mybot.ask(text, chat_id, filters=None, timeout=30)
- Same of
.listen()
above, but sends a message before awaiting. - You can pass custom parameters to its send_message() call. Check the example below.
-
Chat.asker, User.asker
await mybot.asker(chat_id, filters=None, timeout=36)
- same as
.listen()
but.asker()
returnsNone
instead of raisingasyncio.TimeoutError
. - Found useful in some cases for me,
.asker()
has a default timeout of 2 minutes. - You can adjust it by passing as a argument. Refer the example code given below.
-
Examples:
For .asker():
...
sendx = await client.send_message(chat_id, "`Send me your name:`")
answer = await client.asker(chat_id, filters=None, timeout=60)
if not answer: # `None` if timeout if no reply received.
return await sendx.reply_text("How long should I wait?, Eh! Bye!")
await answer.reply_text(f"{answer.text}, That's a cool name!")
...
For .ask():
...
answer = await client.ask(chat_id, '*Send me your name:*', parse_mode='Markdown')
await client.send_message(chat_id, f'Your name is: {answer.text}')
...
Copyright & License
This project may include snippets of Pyrogram code
- Pyrogram - Telegram MTProto API Client Library for Python. Copyright (C) 2017-2022 Dan <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
patchpyro-2.0.1.tar.gz
(18.9 kB
view details)
Built Distribution
patchpyro-2.0.1-py3-none-any.whl
(22.8 kB
view details)
File details
Details for the file patchpyro-2.0.1.tar.gz
.
File metadata
- Download URL: patchpyro-2.0.1.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7846b67713a1a9b8da5e31535ae5f2cf9a989e4f2d9b7f2939b85ac4841da4 |
|
MD5 | b4e5d072120f5184055a6284e6229f66 |
|
BLAKE2b-256 | 5d0dd18afb2be200d8cb0c74fd23d816613aae83285a52b2aa30364cca972726 |
File details
Details for the file patchpyro-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: patchpyro-2.0.1-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fec6519c3643885db396b870e38a4a5085fe13c8563e1976ec61ac442b2684f9 |
|
MD5 | 6e82b7a4fb865f5e9893996d37eda71e |
|
BLAKE2b-256 | fa31ddf37ed933124c809b11cb849480e29994bc90e4304f113c3193efc85056 |