yatbaf-menu


Nameyatbaf-menu JSON
Version 0.3.1 PyPI version JSON
download
home_page
SummaryInline menu builder for yatbaf
upload_time2024-01-28 21:47:17
maintainer
docs_urlNone
author
requires_python>=3.11
licenseThe MIT License (MIT) Copyright (c) 2023 Maraudeur Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords telegram-bot telegram-bot-api yatbaf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## yatbaf-menu

Inline menu builder for [yatbaf](https://codeberg.org/maraudeur/yatbaf).

## Installation

```shell
$ pip install yatbaf-menu
```

## Usage

```python
from typing import TYPE_CHECKING

from yatbaf import Bot
from yatbaf import on_message
from yatbaf.filters import Command

from yatbaf_menu import Action
from yatbaf_menu import Menu
from yatbaf_menu import build_router

if TYPE_CHECKING:
    from yatbaf.types import CallbackQuery
    from yatbaf.types import Message



async def button1(q: CallbackQuery) -> None:
    await q.answer()
    await q.message.answer("click1")


async def button2(q: CallbackQuery) -> None:
    await q.answer()
    await q.message.answer("click2")


menu = Menu(
    title="Menu title",
    buttons=[
        [
            Action(title="Click 1", action=button1),
            Action(title="Click 2", action=button2),
        ],
    ],
)


@on_message(filters=[Command("menu")])
async def open_menu(message: Message) -> None:
    await message.answer(**(await menu.get_message_params(message)))


Bot(
    "<replace-with-your-token>",
    handlers=[open_menu],
    routers=[build_router(menu)],
).run()
```

## Examples

### Click
Click action

![click gif](media/click.gif)

[code](examples/click.py)

### URL
URL button

![url pic](media/url.webp)

[code](examples/url.py)

### Submenu
Submenu button

![submenu gif](media/submenu.gif)

[code](examples/submenu.py)

### Choice

![choice gif](media/choice.gif)

[code](examples/choice.py)

### Pagination

![paging gif](media/paging.gif)

[code](examples/paging.py)

### Dynamic titles and visibility

![dynamic gif](media/dynamic.gif)

[code](examples/dynamic.py)

## License
[MIT](./LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "yatbaf-menu",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "telegram-bot,telegram-bot-api,yatbaf",
    "author": "",
    "author_email": "Maraudeur <maraudeur1@protonmail.ch>",
    "download_url": "https://files.pythonhosted.org/packages/6a/4f/fe1a1032df9c91c9f74efaf7dd0018c66f8007941b17010f3df2e5931eea/yatbaf_menu-0.3.1.tar.gz",
    "platform": null,
    "description": "## yatbaf-menu\n\nInline menu builder for [yatbaf](https://codeberg.org/maraudeur/yatbaf).\n\n## Installation\n\n```shell\n$ pip install yatbaf-menu\n```\n\n## Usage\n\n```python\nfrom typing import TYPE_CHECKING\n\nfrom yatbaf import Bot\nfrom yatbaf import on_message\nfrom yatbaf.filters import Command\n\nfrom yatbaf_menu import Action\nfrom yatbaf_menu import Menu\nfrom yatbaf_menu import build_router\n\nif TYPE_CHECKING:\n    from yatbaf.types import CallbackQuery\n    from yatbaf.types import Message\n\n\n\nasync def button1(q: CallbackQuery) -> None:\n    await q.answer()\n    await q.message.answer(\"click1\")\n\n\nasync def button2(q: CallbackQuery) -> None:\n    await q.answer()\n    await q.message.answer(\"click2\")\n\n\nmenu = Menu(\n    title=\"Menu title\",\n    buttons=[\n        [\n            Action(title=\"Click 1\", action=button1),\n            Action(title=\"Click 2\", action=button2),\n        ],\n    ],\n)\n\n\n@on_message(filters=[Command(\"menu\")])\nasync def open_menu(message: Message) -> None:\n    await message.answer(**(await menu.get_message_params(message)))\n\n\nBot(\n    \"<replace-with-your-token>\",\n    handlers=[open_menu],\n    routers=[build_router(menu)],\n).run()\n```\n\n## Examples\n\n### Click\nClick action\n\n![click gif](media/click.gif)\n\n[code](examples/click.py)\n\n### URL\nURL button\n\n![url pic](media/url.webp)\n\n[code](examples/url.py)\n\n### Submenu\nSubmenu button\n\n![submenu gif](media/submenu.gif)\n\n[code](examples/submenu.py)\n\n### Choice\n\n![choice gif](media/choice.gif)\n\n[code](examples/choice.py)\n\n### Pagination\n\n![paging gif](media/paging.gif)\n\n[code](examples/paging.py)\n\n### Dynamic titles and visibility\n\n![dynamic gif](media/dynamic.gif)\n\n[code](examples/dynamic.py)\n\n## License\n[MIT](./LICENSE)\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2023 Maraudeur  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Inline menu builder for yatbaf",
    "version": "0.3.1",
    "project_urls": {
        "Source": "https://codeberg.org/maraudeur/yatbaf-menu"
    },
    "split_keywords": [
        "telegram-bot",
        "telegram-bot-api",
        "yatbaf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c8ce2551e8ea04cba6f833ccd736d2209309c83de854a3fb27f68bd85e66fb7",
                "md5": "3a0e693a75bb469b485aef69c0aee1ce",
                "sha256": "106969348f1c0819fc5fc8d3fc670050848cb32a3ae8a6e94159042f7f8cd5bc"
            },
            "downloads": -1,
            "filename": "yatbaf_menu-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a0e693a75bb469b485aef69c0aee1ce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 14480,
            "upload_time": "2024-01-28T21:47:15",
            "upload_time_iso_8601": "2024-01-28T21:47:15.653465Z",
            "url": "https://files.pythonhosted.org/packages/0c/8c/e2551e8ea04cba6f833ccd736d2209309c83de854a3fb27f68bd85e66fb7/yatbaf_menu-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a4ffe1a1032df9c91c9f74efaf7dd0018c66f8007941b17010f3df2e5931eea",
                "md5": "421f803369a7cae4bbf4908b68aceb47",
                "sha256": "341bc9cdf9b7fa55b72354005a7590ac2c025a0060dfd5b0fc06a9d2404bb187"
            },
            "downloads": -1,
            "filename": "yatbaf_menu-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "421f803369a7cae4bbf4908b68aceb47",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 13339,
            "upload_time": "2024-01-28T21:47:17",
            "upload_time_iso_8601": "2024-01-28T21:47:17.635944Z",
            "url": "https://files.pythonhosted.org/packages/6a/4f/fe1a1032df9c91c9f74efaf7dd0018c66f8007941b17010f3df2e5931eea/yatbaf_menu-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-28 21:47:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": true,
    "codeberg_user": "maraudeur",
    "codeberg_project": "yatbaf-menu",
    "lcname": "yatbaf-menu"
}
        
Elapsed time: 0.28212s