Skip to main content

herdmod

A monkeypatcher add-on for pyroherd

Introduction

herdmod is a compilation of utils i developed for extend my personal use of pyroherd. 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 pyroherd, this is not a fork nor modded version. It does monkey patching to add features to pyroherd classes.

IMPORTANT: you should have installed asyncio pyroherd.

Usage

Import herdmod at least one time in your script, so you'll be able to use modified pyroherd in all files of the same proccess. Example:

# config.py
import herdmod.listen
from pyroherd import Client

app = Client('my_session')
# any other .py
from config import app
# no need to import herdmod again, pyroherd 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 herdmod.helpers, which provides classes and functions that should be explicitely imported).

herdmod.listen

Just import it, it will automatically do the monkeypatch and you'll get these new methods:

  • await pyroherd.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 pyroherd.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 herdmod import listen # or import herdmod.listen
from pyroherd import Client
client = Client(...)
...
    answer = await message.ask(chat_id, '*Send me your name:*', parse_mode='Markdown')
    await client.send_message(chat_id, f'Your name is: {answer.text}')    

herdmod.filters

Import it and the following Update Filters will be monkeypatched to pyroherd.filters:

  • filters.dice A dice message.

herdmod.helpers

Tools for creating inline keyboards a lot easier.

  • herdmod.helpers.ikb Creates a inline keyboard. It's first and only argument must be a list (the keyboard) containing lists (the lines) of buttons. The buttons can also be lists or tuples. I use tuples to not have to deal with a lot of brackets. The button syntax must be this: (TEXT, CALLBACK_DATA) or (TEXT, VALUE, TYPE), where TYPE can be 'url' or any other supported button type and VALUE is its value. This syntax will be converted to {"text": TEXT, TYPE: VALUE). If TYPE is CALLBACK_DATA, you can omit it, just like the fist syntax above. Examples:
from herdmod.helpers import ikb
...
keyboard = ikb([
    [('Button 1', 'call_1'), ('Button 2', 'call_2')],
    [('Another button', 't.me/herdmod', 'url')]
])
await message.reply('Test', reply_markup=keyboard)
  • herdmod.helpers.array_chunk Chunk the elements of a list into small lists. i.e. [1, 2, 3, 4] can become [[1,2], [3,4]]. This is extremely useful if you want to build a keyboard dinamically with more than 1 column. You just put all buttons together in a list and run:
lines = array_chunk(buttons, 2) # generate a list of lines with 2 buttons on each
keyboard = ikb(lines)

This project may include snippets of pyroherd code

Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)

Metadata

Release files for herdmod 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for herdmod 0.1.6
File Size Uploaded Provenance Actions
herdmod-0.1.6.tar.gz 21.6 kB Without provenance Details for herdmod-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for herdmod 0.1.6
File Interpreter ABI Platform Actions
herdmod-0.1.6-py3-none-any.whl Python 3 none any Details for herdmod-0.1.6-py3-none-any.whl

Total release size: 43.9 kB

Release files / herdmod-0.1.6.tar.gz

Download URL herdmod-0.1.6.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
339d27001a31112491c393deed70c1b7b0a0d22c756f14807f55eb76fb801f88
BLAKE2b-256 checksum
How to use checksums
3ecc0297a31fc2ca759a55d2166e8b679ef358ed068d4523efd1a7746dad175c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / herdmod-0.1.6-py3-none-any.whl

Download URL herdmod-0.1.6-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b27b093dc90d1019e47c3778a37d21ca7d5e3d6901a4d308b214d089581893bc
BLAKE2b-256 checksum
How to use checksums
64278b6607f94892acd15b1a066e1d2a9e9b52a3b82fe789b904880c7dd22f54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Security for herdmod 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page