# 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:
```python
# config.py
import herdmod.listen
from pyroherd import Client
app = Client('my_session')
```
```python
# 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:
```python
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:
```python
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:
```python
lines = array_chunk(buttons, 2) # generate a list of lines with 2 buttons on each
keyboard = ikb(lines)
```
### Copyright & License
This project may include snippets of pyroherd code
- pyroherd - Telegram MTProto API Client Library for Python. Copyright (C) 2023-2025 OnTheHerd <<https://github.com/OnTheHerd>>
Licensed under the terms of the [GNU Lesser General Public License v3 or later (LGPLv3+)](COPYING.lesser)
Raw data
{
"_id": null,
"home_page": "https://github.com/OnTheHerd/herdmod",
"name": "herdmod",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "OnTheHerd",
"author_email": "ontheherd@onmail.com",
"download_url": "https://files.pythonhosted.org/packages/3e/cc/0297a31fc2ca759a55d2166e8b679ef358ed068d4523efd1a7746dad175c/herdmod-0.1.6.tar.gz",
"platform": null,
"description": "# herdmod\nA monkeypatcher add-on for pyroherd\n\n## Introduction\nherdmod 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.\nIt works *together* with pyroherd, this is *not* a fork nor modded version. It does monkey patching to add features to pyroherd classes.\n\nIMPORTANT: you should have installed asyncio pyroherd.\n\n## Usage\nImport `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:\n```python\n# config.py\nimport herdmod.listen\nfrom pyroherd import Client\n\napp = Client('my_session')\n```\n```python\n# any other .py\nfrom config import app\n# no need to import herdmod again, pyroherd is already monkeypatched globally (at the same proccess)\n```\n\nI 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).\n\n### `herdmod.listen`\nJust import it, it will automatically do the monkeypatch and you'll get these new methods:\n- `await pyroherd.Client.listen(chat_id, filters=None, timeout=30)`\nAwaits for a new message in the specified chat and returns it\nYou can pass Update Filters to the filters parameter just like you do for the update handlers. e.g. `filters=filters.photo & filters.bot`\n\n- `await pyroherd.Client.ask(text, chat_id, filters=None, timeout=30)`\nSame of `.listen()` above, but sends a message before awaiting\nYou can pass custom parameters to its send_message() call. Check the example below.\n\n- The bound methods `Chat.listen`, `User.listen`, `Chat.ask` and `User.ask`\n\nExample:\n```python\nfrom herdmod import listen # or import herdmod.listen\nfrom pyroherd import Client\nclient = Client(...)\n...\n answer = await message.ask(chat_id, '*Send me your name:*', parse_mode='Markdown')\n await client.send_message(chat_id, f'Your name is: {answer.text}') \n```\n\n### `herdmod.filters`\nImport it and the following Update Filters will be monkeypatched to `pyroherd.filters`:\n\n- `filters.dice`\nA dice message.\n\n### `herdmod.helpers`\nTools for creating inline keyboards a lot easier.\n\n- `herdmod.helpers.ikb`\nCreates a inline keyboard. It's first and only argument must be a list (the keyboard) containing lists (the lines) of buttons.\nThe buttons can also be lists or tuples. I use tuples to not have to deal with a lot of brackets.\nThe 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.\nExamples:\n```python\nfrom herdmod.helpers import ikb\n...\nkeyboard = ikb([\n [('Button 1', 'call_1'), ('Button 2', 'call_2')],\n [('Another button', 't.me/herdmod', 'url')]\n])\nawait message.reply('Test', reply_markup=keyboard)\n```\n- `herdmod.helpers.array_chunk`\nChunk 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:\n```python\nlines = array_chunk(buttons, 2) # generate a list of lines with 2 buttons on each\nkeyboard = ikb(lines)\n```\n\n### Copyright & License\nThis project may include snippets of pyroherd code\n- pyroherd - Telegram MTProto API Client Library for Python. Copyright (C) 2023-2025 OnTheHerd <<https://github.com/OnTheHerd>>\n\nLicensed under the terms of the [GNU Lesser General Public License v3 or later (LGPLv3+)](COPYING.lesser)\n",
"bugtrack_url": null,
"license": "LGPLv3+",
"summary": "A monkeypatcher add-on for Pyroherd",
"version": "0.1.6",
"project_urls": {
"Homepage": "https://github.com/OnTheHerd/herdmod"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "64278b6607f94892acd15b1a066e1d2a9e9b52a3b82fe789b904880c7dd22f54",
"md5": "9e2c775e547fce1648d0035b3cf53d7b",
"sha256": "b27b093dc90d1019e47c3778a37d21ca7d5e3d6901a4d308b214d089581893bc"
},
"downloads": -1,
"filename": "herdmod-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9e2c775e547fce1648d0035b3cf53d7b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 22269,
"upload_time": "2024-09-21T16:31:14",
"upload_time_iso_8601": "2024-09-21T16:31:14.672460Z",
"url": "https://files.pythonhosted.org/packages/64/27/8b6607f94892acd15b1a066e1d2a9e9b52a3b82fe789b904880c7dd22f54/herdmod-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3ecc0297a31fc2ca759a55d2166e8b679ef358ed068d4523efd1a7746dad175c",
"md5": "7475c02853c9211671e14473b3411c68",
"sha256": "339d27001a31112491c393deed70c1b7b0a0d22c756f14807f55eb76fb801f88"
},
"downloads": -1,
"filename": "herdmod-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "7475c02853c9211671e14473b3411c68",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 21644,
"upload_time": "2024-09-21T16:31:15",
"upload_time_iso_8601": "2024-09-21T16:31:15.613411Z",
"url": "https://files.pythonhosted.org/packages/3e/cc/0297a31fc2ca759a55d2166e8b679ef358ed068d4523efd1a7746dad175c/herdmod-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-21 16:31:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "OnTheHerd",
"github_project": "herdmod",
"github_not_found": true,
"lcname": "herdmod"
}