Skip to main content

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.utils, 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 and User.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}')    

Copyright & License

This project may include snippets of Pyrogram code

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

pyromod-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

pyromod-0.0.2-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file pyromod-0.0.2.tar.gz.

File metadata

  • Download URL: pyromod-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for pyromod-0.0.2.tar.gz
Algorithm Hash digest
SHA256 21569827e78d32c667614c741854635ec8c5fcaa5458042b9a570ff87a06d162
MD5 96d121d23b2b9d6e4fc8927d60b66ba4
BLAKE2b-256 cf2ae1e5b6062b3f822078be8dcf290ff8660c3aa071e60b58f7c7478d5b9e1e

See more details on using hashes here.

File details

Details for the file pyromod-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyromod-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for pyromod-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4e2e0064292b9b822a5e12680b036bb48600ffce1766e30d1239fe4962e83c
MD5 59696a12b375f7eb97c8dca9920d8a2e
BLAKE2b-256 af9e54b56f7ad0b627a33039af60d90f5c548495dff2eb0b96626e865f3c52b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page