A monkeypatcher add-on for Pyrogram
Project description
pyromod
A monkeypatcher add-on for Pyrogram
Introduction
pyromod is a compilation of utils i developed for extend my personal use of Pyrogram. Then i started to use it and more bots and now i published it to make it easier to be installed in new projects. It works together with pyrogram, this is not a fork nor modded version. It does monkey patching to add features to Pyrogram classes.
IMPORTANT: you should have installed asyncio pyrogram.
Usage
Import pyromod
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
import pyromod.listen
from pyrogram import Client
app = Client('my_session')
# any other .py
from config import app
# no need to import pyromod again, pyrogram is already monkeypatched globally (at the same proccess)
I separated the patches between packages to allow you to import only what you want. The __init__.py
of each package does the monkeypatch automatically as soon as they are imported (except for pyromod.helpers
, which provides classes and functions that should be explicitely imported).
pyromod.listen
Just import it, it will automatically do the monkeypatch and you'll get these new methods:
-
await pyrogram.Client.listen(chat_id, filters=None, timeout=30)
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
-
await pyrogram.Client.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. -
The bound methods
Chat.listen
,User.listen
,Chat.ask
andUser.ask
Example:
from pyromod import listen # or import pyromod.listen
from pyrogram import Client
client = Client(...)
...
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}')
pyromod.filters
Import it and the following Update Filters will be monkeypatched to pyrogram.Filters
:
-
Filters.dice
A dice message. -
Filters.callback_regex(pattern, flags: int = 0)
Same ofFilters.regex
, but for CallbackQuery updates The CallbackQuery object will hold the matches on the newCallbackQuery.matches
attribute (just likeMessage.matches
)
Copyright & License
This project may include snippets of Pyrogram code
- Pyrogram - Telegram MTProto API Client Library for Python. Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pyromod-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: pyromod-0.3.2-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b70b75078265dbf60865eaf5072a9ea611f87bcd53d1be50479e0ac29e9f195e |
|
MD5 | 62945fa7d529544bd2e705b24cc6fcab |
|
BLAKE2b-256 | eef1a23c52d391509faf6aec4cb433b1ba0de4974581e8e9b49858a11514c9c3 |