pylibob


Namepylibob JSON
Version 0.1.1 PyPI version JSON
download
home_page
Summary另一个 LibOneBot Python 库,旨在帮助开发者实现 OneBot 12 标准。
upload_time2023-10-05 07:13:31
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords onebot libonebot onebot12
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pylibob

另一个 LibOneBot Python 库,旨在帮助开发者实现 [OneBot 12](https://12.onebot.dev/) 标准。

## 这是什么?

这是一个 Python 的 [LibOneBot](https://12.onebot.dev/glossary/#libonebot),旨在帮助开发者快速实现 OneBot 12 标准。

LibOneBot 对 [OneBot Connect](https://12.onebot.dev/connect/) 和动作、事件、消息段进行了包装,便于开发者使用。

下文涉及的 OneBot 概念请参考 [OneBot 术语表](https://12.onebot.dev/glossary/)

## 安装

```shell
pip install pylibob
```

## 快速上手

```python
from __future__ import annotations

# from typing_extensions import Annotated  # python<3.9
from typing import Annotated  # python>=3.9

from pylibob import (
    HTTP,
    Bot,
    Event,
    HTTPWebhook,
    OneBotImpl,
    WebSocket,
    WebSocketReverse,
)

impl = OneBotImpl(
    "test",  # 实现名称
    "1.0.0",  # 实现版本
    [
        HTTP(
            host="0.0.0.0",  # HTTP 服务器监听 IP
            port=8080,  # HTTP 服务器监听端口
            event_enabled=True,  # 是否启用 get_latest_events 元动作
            event_buffer_size=20,  # 事件缓冲区大小
            access_token="access_token",  # 访问令牌
        ),
        HTTPWebhook(
            url="http://127.0.0.1:8080/onebot/v12/http/",  # Webhook 上报地址
        ),
        # WebSocket 均存在 enable_heartbeat 和 heartbeat_interval
        WebSocket(
            enable_heartbeat=True,  # 启用心跳
            heartbeat_interval=5000,  # 心跳间隔
        ),
        WebSocketReverse(url="ws://127.0.0.1:8081/onebot/v12/ws/"),
    ],
    Bot(platform="qq", user_id="1", online=True),  # 任意个数 Bot 实例
)


@impl.action("hello")
async def _(
    # 采用类型注解的方式声明参数及类型
    a: str,
    # 扩展参数使用 Annotated,第一个 metadata 会被视为参数名
    b: Annotated[int, "extra.param"],
    # 注解为 Bot 的参数不计入动作需要的参数,会内部处理传入 Bot 实例
    c: Bot,
    # 允许默认值
    d: int = 5,
):
    # 此动作 `hello` 需要必须参数:
    #     a (string)
    #     extra.param (int)
    # 可选参数:
    #     d (int) (default = 5)

    # 向应用推送事件
    await impl.emit(Event(...))

    return a, b, c, d  # 返回的内容会传入到响应的 data

# 机器人准备好后(一般指机器人登录完成)
# 实现良好状态默认为 False,准备好需手动调整为 True
# impl.is_good = True
# 还要调用此方法去更新状态
# await impl.update_status()

impl.run()  # 运行
```

## 许可证

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pylibob",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "onebot libonebot onebot12",
    "author": "",
    "author_email": "MingxuanGame <MingxuanGame@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/9e/73/26219d80fd44e17d5b3823a6bf10f2bba2879d6d5baf131d3f172bc96951/pylibob-0.1.1.tar.gz",
    "platform": null,
    "description": "# pylibob\n\n\u53e6\u4e00\u4e2a LibOneBot Python \u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5b9e\u73b0 [OneBot 12](https://12.onebot.dev/) \u6807\u51c6\u3002\n\n## \u8fd9\u662f\u4ec0\u4e48\uff1f\n\n\u8fd9\u662f\u4e00\u4e2a Python \u7684 [LibOneBot](https://12.onebot.dev/glossary/#libonebot)\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9e\u73b0 OneBot 12 \u6807\u51c6\u3002\n\nLibOneBot \u5bf9 [OneBot Connect](https://12.onebot.dev/connect/) \u548c\u52a8\u4f5c\u3001\u4e8b\u4ef6\u3001\u6d88\u606f\u6bb5\u8fdb\u884c\u4e86\u5305\u88c5\uff0c\u4fbf\u4e8e\u5f00\u53d1\u8005\u4f7f\u7528\u3002\n\n\u4e0b\u6587\u6d89\u53ca\u7684 OneBot \u6982\u5ff5\u8bf7\u53c2\u8003 [OneBot \u672f\u8bed\u8868](https://12.onebot.dev/glossary/)\n\n## \u5b89\u88c5\n\n```shell\npip install pylibob\n```\n\n## \u5feb\u901f\u4e0a\u624b\n\n```python\nfrom __future__ import annotations\n\n# from typing_extensions import Annotated  # python<3.9\nfrom typing import Annotated  # python>=3.9\n\nfrom pylibob import (\n    HTTP,\n    Bot,\n    Event,\n    HTTPWebhook,\n    OneBotImpl,\n    WebSocket,\n    WebSocketReverse,\n)\n\nimpl = OneBotImpl(\n    \"test\",  # \u5b9e\u73b0\u540d\u79f0\n    \"1.0.0\",  # \u5b9e\u73b0\u7248\u672c\n    [\n        HTTP(\n            host=\"0.0.0.0\",  # HTTP \u670d\u52a1\u5668\u76d1\u542c IP\n            port=8080,  # HTTP \u670d\u52a1\u5668\u76d1\u542c\u7aef\u53e3\n            event_enabled=True,  # \u662f\u5426\u542f\u7528 get_latest_events \u5143\u52a8\u4f5c\n            event_buffer_size=20,  # \u4e8b\u4ef6\u7f13\u51b2\u533a\u5927\u5c0f\n            access_token=\"access_token\",  # \u8bbf\u95ee\u4ee4\u724c\n        ),\n        HTTPWebhook(\n            url=\"http://127.0.0.1:8080/onebot/v12/http/\",  # Webhook \u4e0a\u62a5\u5730\u5740\n        ),\n        # WebSocket \u5747\u5b58\u5728 enable_heartbeat \u548c heartbeat_interval\n        WebSocket(\n            enable_heartbeat=True,  # \u542f\u7528\u5fc3\u8df3\n            heartbeat_interval=5000,  # \u5fc3\u8df3\u95f4\u9694\n        ),\n        WebSocketReverse(url=\"ws://127.0.0.1:8081/onebot/v12/ws/\"),\n    ],\n    Bot(platform=\"qq\", user_id=\"1\", online=True),  # \u4efb\u610f\u4e2a\u6570 Bot \u5b9e\u4f8b\n)\n\n\n@impl.action(\"hello\")\nasync def _(\n    # \u91c7\u7528\u7c7b\u578b\u6ce8\u89e3\u7684\u65b9\u5f0f\u58f0\u660e\u53c2\u6570\u53ca\u7c7b\u578b\n    a: str,\n    # \u6269\u5c55\u53c2\u6570\u4f7f\u7528 Annotated\uff0c\u7b2c\u4e00\u4e2a metadata \u4f1a\u88ab\u89c6\u4e3a\u53c2\u6570\u540d\n    b: Annotated[int, \"extra.param\"],\n    # \u6ce8\u89e3\u4e3a Bot \u7684\u53c2\u6570\u4e0d\u8ba1\u5165\u52a8\u4f5c\u9700\u8981\u7684\u53c2\u6570\uff0c\u4f1a\u5185\u90e8\u5904\u7406\u4f20\u5165 Bot \u5b9e\u4f8b\n    c: Bot,\n    # \u5141\u8bb8\u9ed8\u8ba4\u503c\n    d: int = 5,\n):\n    # \u6b64\u52a8\u4f5c `hello` \u9700\u8981\u5fc5\u987b\u53c2\u6570:\n    #     a (string)\n    #     extra.param (int)\n    # \u53ef\u9009\u53c2\u6570:\n    #     d (int) (default = 5)\n\n    # \u5411\u5e94\u7528\u63a8\u9001\u4e8b\u4ef6\n    await impl.emit(Event(...))\n\n    return a, b, c, d  # \u8fd4\u56de\u7684\u5185\u5bb9\u4f1a\u4f20\u5165\u5230\u54cd\u5e94\u7684 data\n\n# \u673a\u5668\u4eba\u51c6\u5907\u597d\u540e\uff08\u4e00\u822c\u6307\u673a\u5668\u4eba\u767b\u5f55\u5b8c\u6210\uff09\n# \u5b9e\u73b0\u826f\u597d\u72b6\u6001\u9ed8\u8ba4\u4e3a False\uff0c\u51c6\u5907\u597d\u9700\u624b\u52a8\u8c03\u6574\u4e3a True\n# impl.is_good = True\n# \u8fd8\u8981\u8c03\u7528\u6b64\u65b9\u6cd5\u53bb\u66f4\u65b0\u72b6\u6001\n# await impl.update_status()\n\nimpl.run()  # \u8fd0\u884c\n```\n\n## \u8bb8\u53ef\u8bc1\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u53e6\u4e00\u4e2a LibOneBot Python \u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5b9e\u73b0 OneBot 12 \u6807\u51c6\u3002",
    "version": "0.1.1",
    "project_urls": {
        "Bug tracker": "https://github.com/Herta-villa/pylibob/issues",
        "Documentation": "https://pylibob.mxgame.top",
        "Homepage": "https://pylibob.mxgame.top",
        "Repository": "https://github.com/Herta-villa/pylibob"
    },
    "split_keywords": [
        "onebot",
        "libonebot",
        "onebot12"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26809970922debdce5beef6481657864c2762d58c03ae7bcc4ad42ec16c85c7f",
                "md5": "2a23bbc34e55cba2a9ecda7aefeb38a1",
                "sha256": "e2113c3087fa4074af105b834bc9e639bd3c931b9dbe4086c9739c9c823fde2b"
            },
            "downloads": -1,
            "filename": "pylibob-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a23bbc34e55cba2a9ecda7aefeb38a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 28498,
            "upload_time": "2023-10-05T07:13:29",
            "upload_time_iso_8601": "2023-10-05T07:13:29.946598Z",
            "url": "https://files.pythonhosted.org/packages/26/80/9970922debdce5beef6481657864c2762d58c03ae7bcc4ad42ec16c85c7f/pylibob-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e7326219d80fd44e17d5b3823a6bf10f2bba2879d6d5baf131d3f172bc96951",
                "md5": "d7edec5b3721cc3df84a68de2de28f53",
                "sha256": "5695ed256f3a89356adc9dc6fc4cab63f8506bb9151008a1a302f196fae04fd9"
            },
            "downloads": -1,
            "filename": "pylibob-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d7edec5b3721cc3df84a68de2de28f53",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 22379,
            "upload_time": "2023-10-05T07:13:31",
            "upload_time_iso_8601": "2023-10-05T07:13:31.617758Z",
            "url": "https://files.pythonhosted.org/packages/9e/73/26219d80fd44e17d5b3823a6bf10f2bba2879d6d5baf131d3f172bc96951/pylibob-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-05 07:13:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Herta-villa",
    "github_project": "pylibob",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pylibob"
}
        
Elapsed time: 0.15727s