villa


Namevilla JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/CMHopeSunshine/villa-py
Summary米游社大别野Bot Python SDK。MiHoYo Villa Bot Python SDK.
upload_time2023-10-25 03:07:39
maintainer
docs_urlNone
authorCMHopeSunshine
requires_python>=3.8,<4.0
licenseMIT
keywords mihoyo bot villa
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

# Villa

_✨ 米游社大别野Bot Python SDK ✨_

<a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/villa-py@master/LICENSE">
    <img src="https://img.shields.io/github/license/CMHopeSunshine/villa-py" alt="license">
</a>
<img src="https://img.shields.io/pypi/v/villa" alt="version">
<img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python">
<a href="https://pypi.python.org/pypi/villa">
  <img src="https://img.shields.io/pypi/dm/villa" alt="pypi download">
</a>
<a href="https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/d3b88a99-17c2-4c98-bbc2-c1949ce7c078">
  <img src="https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/d3b88a99-17c2-4c98-bbc2-c1949ce7c078.svg" alt="wakatime">
</a>
<a href="https://github.com/astral-sh/ruff">
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json" alt="ruff">
</a>

</div>

## 特性

- 基于`FastAPI`和`Pydantic`,异步优先、快速、高性能!
- 完整的类型注解支持,便于开发。
- 便捷的消息构造和发送方法。
- 完整的消息段和API支持。
- `Serverless`云函数支持。
- More ~~想不出来了~~

## 安装

- 使用 pip: `pip install villa`
- 使用 poetry: `poetry add villa`
- 使用 pdm: `pdm add villa`

## 快速开始

你需要一个[米游社大别野](https://dby.miyoushe.com/chat)的 Bot,可前往大别野[「机器人开发者社区」](https://dby.miyoushe.com/chat/463/20020)(ID: `OpenVilla`)申请,取得`bot_id`、`bot_secret`和`pub_key`。

```python
from villa import Bot
from villa.event import SendMessageEvent

bot = Bot(
    bot_id="your_bot_id",
    bot_secret="your_bot_secret",
    pub_key="-----BEGIN PUBLIC KEY-----\nyour_pub_key\n-----END PUBLIC KEY-----\n",
    callback_url="your_callback_url_endpoint",
)
# 初始化Bot,填写你的bot_id、密钥、pub_key以及回调地址endpoint
# 举例:若申请时提供的回调地址为https://域名/callback,这里的callback_url就填`/callback`

@bot.on_startswith("hello")
async def handler(event: SendMessageEvent):
    await event.send("world!")
    # 一个简单的处理函数,向你的Bot发送包含`hello`关键词的消息,它将会回复你`world`!


if __name__ == "__main__":
    bot.run(host="127.0.0.1", port=13350)
    # 启动bot,注意,port端口号要和你所使用的回调地址端口对上
```


## 示例

详见 [example](https://github.com/CMHopeSunshine/villa-py/tree/main/example) 文件夹:

- [单 Bot 运行](https://github.com/CMHopeSunshine/villa-py/blob/main/example/single_bot.py)
- [多 Bot 运行](https://github.com/CMHopeSunshine/villa-py/blob/main/example/multiple_bots.py)
- [处理器介绍](https://github.com/CMHopeSunshine/villa-py/blob/main/example/handle_func.py)
- [消息发送方法](https://github.com/CMHopeSunshine/villa-py/blob/main/example/send_message.py)
- [vercel serverless 部署](https://github.com/CMHopeSunshine/villa-py/blob/main/example/vercel.py)

## 交流、建议和反馈

> 注意:本SDK并非官方SDK

大别野 Bot 和本 SDK 均为开发测试中,如遇问题请提出 [issue](https://github.com/CMHopeSunshine/villa-py/issues) ,感谢支持!

也欢迎来我的大别野[「尘世闲游」]((https://dby.miyoushe.com/chat/1047/21652))(ID: `wgiJNaU`)进行交流~

## 相关项目

- [NoneBot2](https://github.com/nonebot/nonebot2) 非常好用的 Python 跨平台机器人框架!
- [nonebot-adapter-villa](https://github.com/CMHopeSunshine/nonebot-adapter-villa) NoneBot2 的大别野 Bot 适配器。
- [Herta-villa-SDK](https://github.com/MingxuanGame/Herta-villa-SDK) 另一个大别野 Python SDK。


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/CMHopeSunshine/villa-py",
    "name": "villa",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "mihoyo,bot,villa",
    "author": "CMHopeSunshine",
    "author_email": "277073121@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/bf/82/e7b943b21644109583a582c3ed8a0135a5b16ee472b5f1989a15d3e80daf/villa-0.8.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n# Villa\n\n_\u2728 \u7c73\u6e38\u793e\u5927\u522b\u91ceBot Python SDK \u2728_\n\n<a href=\"https://cdn.jsdelivr.net/gh/CMHopeSunshine/villa-py@master/LICENSE\">\n    <img src=\"https://img.shields.io/github/license/CMHopeSunshine/villa-py\" alt=\"license\">\n</a>\n<img src=\"https://img.shields.io/pypi/v/villa\" alt=\"version\">\n<img src=\"https://img.shields.io/badge/Python-3.8+-yellow\" alt=\"python\">\n<a href=\"https://pypi.python.org/pypi/villa\">\n  <img src=\"https://img.shields.io/pypi/dm/villa\" alt=\"pypi download\">\n</a>\n<a href=\"https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/d3b88a99-17c2-4c98-bbc2-c1949ce7c078\">\n  <img src=\"https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/d3b88a99-17c2-4c98-bbc2-c1949ce7c078.svg\" alt=\"wakatime\">\n</a>\n<a href=\"https://github.com/astral-sh/ruff\">\n  <img src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\" alt=\"ruff\">\n</a>\n\n</div>\n\n## \u7279\u6027\n\n- \u57fa\u4e8e`FastAPI`\u548c`Pydantic`\uff0c\u5f02\u6b65\u4f18\u5148\u3001\u5feb\u901f\u3001\u9ad8\u6027\u80fd\uff01\n- \u5b8c\u6574\u7684\u7c7b\u578b\u6ce8\u89e3\u652f\u6301\uff0c\u4fbf\u4e8e\u5f00\u53d1\u3002\n- \u4fbf\u6377\u7684\u6d88\u606f\u6784\u9020\u548c\u53d1\u9001\u65b9\u6cd5\u3002\n- \u5b8c\u6574\u7684\u6d88\u606f\u6bb5\u548cAPI\u652f\u6301\u3002\n- `Serverless`\u4e91\u51fd\u6570\u652f\u6301\u3002\n- More ~~\u60f3\u4e0d\u51fa\u6765\u4e86~~\n\n## \u5b89\u88c5\n\n- \u4f7f\u7528 pip: `pip install villa`\n- \u4f7f\u7528 poetry: `poetry add villa`\n- \u4f7f\u7528 pdm: `pdm add villa`\n\n## \u5feb\u901f\u5f00\u59cb\n\n\u4f60\u9700\u8981\u4e00\u4e2a[\u7c73\u6e38\u793e\u5927\u522b\u91ce](https://dby.miyoushe.com/chat)\u7684 Bot\uff0c\u53ef\u524d\u5f80\u5927\u522b\u91ce[\u300c\u673a\u5668\u4eba\u5f00\u53d1\u8005\u793e\u533a\u300d](https://dby.miyoushe.com/chat/463/20020)(ID: `OpenVilla`)\u7533\u8bf7\uff0c\u53d6\u5f97`bot_id`\u3001`bot_secret`\u548c`pub_key`\u3002\n\n```python\nfrom villa import Bot\nfrom villa.event import SendMessageEvent\n\nbot = Bot(\n    bot_id=\"your_bot_id\",\n    bot_secret=\"your_bot_secret\",\n    pub_key=\"-----BEGIN PUBLIC KEY-----\\nyour_pub_key\\n-----END PUBLIC KEY-----\\n\",\n    callback_url=\"your_callback_url_endpoint\",\n)\n# \u521d\u59cb\u5316Bot\uff0c\u586b\u5199\u4f60\u7684bot_id\u3001\u5bc6\u94a5\u3001pub_key\u4ee5\u53ca\u56de\u8c03\u5730\u5740endpoint\n# \u4e3e\u4f8b\uff1a\u82e5\u7533\u8bf7\u65f6\u63d0\u4f9b\u7684\u56de\u8c03\u5730\u5740\u4e3ahttps://\u57df\u540d/callback\uff0c\u8fd9\u91cc\u7684callback_url\u5c31\u586b`/callback`\n\n@bot.on_startswith(\"hello\")\nasync def handler(event: SendMessageEvent):\n    await event.send(\"world!\")\n    # \u4e00\u4e2a\u7b80\u5355\u7684\u5904\u7406\u51fd\u6570\uff0c\u5411\u4f60\u7684Bot\u53d1\u9001\u5305\u542b`hello`\u5173\u952e\u8bcd\u7684\u6d88\u606f\uff0c\u5b83\u5c06\u4f1a\u56de\u590d\u4f60`world`\uff01\n\n\nif __name__ == \"__main__\":\n    bot.run(host=\"127.0.0.1\", port=13350)\n    # \u542f\u52a8bot\uff0c\u6ce8\u610f\uff0cport\u7aef\u53e3\u53f7\u8981\u548c\u4f60\u6240\u4f7f\u7528\u7684\u56de\u8c03\u5730\u5740\u7aef\u53e3\u5bf9\u4e0a\n```\n\n\n## \u793a\u4f8b\n\n\u8be6\u89c1 [example](https://github.com/CMHopeSunshine/villa-py/tree/main/example) \u6587\u4ef6\u5939\uff1a\n\n- [\u5355 Bot \u8fd0\u884c](https://github.com/CMHopeSunshine/villa-py/blob/main/example/single_bot.py)\n- [\u591a Bot \u8fd0\u884c](https://github.com/CMHopeSunshine/villa-py/blob/main/example/multiple_bots.py)\n- [\u5904\u7406\u5668\u4ecb\u7ecd](https://github.com/CMHopeSunshine/villa-py/blob/main/example/handle_func.py)\n- [\u6d88\u606f\u53d1\u9001\u65b9\u6cd5](https://github.com/CMHopeSunshine/villa-py/blob/main/example/send_message.py)\n- [vercel serverless \u90e8\u7f72](https://github.com/CMHopeSunshine/villa-py/blob/main/example/vercel.py)\n\n## \u4ea4\u6d41\u3001\u5efa\u8bae\u548c\u53cd\u9988\n\n> \u6ce8\u610f\uff1a\u672cSDK\u5e76\u975e\u5b98\u65b9SDK\n\n\u5927\u522b\u91ce Bot \u548c\u672c SDK \u5747\u4e3a\u5f00\u53d1\u6d4b\u8bd5\u4e2d\uff0c\u5982\u9047\u95ee\u9898\u8bf7\u63d0\u51fa [issue](https://github.com/CMHopeSunshine/villa-py/issues) \uff0c\u611f\u8c22\u652f\u6301\uff01\n\n\u4e5f\u6b22\u8fce\u6765\u6211\u7684\u5927\u522b\u91ce[\u300c\u5c18\u4e16\u95f2\u6e38\u300d]((https://dby.miyoushe.com/chat/1047/21652))(ID: `wgiJNaU`)\u8fdb\u884c\u4ea4\u6d41~\n\n## \u76f8\u5173\u9879\u76ee\n\n- [NoneBot2](https://github.com/nonebot/nonebot2) \u975e\u5e38\u597d\u7528\u7684 Python \u8de8\u5e73\u53f0\u673a\u5668\u4eba\u6846\u67b6\uff01\n- [nonebot-adapter-villa](https://github.com/CMHopeSunshine/nonebot-adapter-villa) NoneBot2 \u7684\u5927\u522b\u91ce Bot \u9002\u914d\u5668\u3002\n- [Herta-villa-SDK](https://github.com/MingxuanGame/Herta-villa-SDK) \u53e6\u4e00\u4e2a\u5927\u522b\u91ce Python SDK\u3002\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u7c73\u6e38\u793e\u5927\u522b\u91ceBot Python SDK\u3002MiHoYo Villa Bot Python SDK.",
    "version": "0.8.0",
    "project_urls": {
        "Documentation": "https://github.com/CMHopeSunshine/villa-py",
        "Homepage": "https://github.com/CMHopeSunshine/villa-py",
        "Repository": "https://github.com/CMHopeSunshine/villa-py"
    },
    "split_keywords": [
        "mihoyo",
        "bot",
        "villa"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c6b283b519c664b09ec057726e32e22550fcd8ec5c8986cb23fac252f3308c4",
                "md5": "5f5bacf644f4692fdff5fd889203cf5f",
                "sha256": "a68cc2cfdce0f0aeb49eaa149deaebb1a362d772ae5774e1e8a01090856a0b02"
            },
            "downloads": -1,
            "filename": "villa-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f5bacf644f4692fdff5fd889203cf5f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 27191,
            "upload_time": "2023-10-25T03:07:37",
            "upload_time_iso_8601": "2023-10-25T03:07:37.822186Z",
            "url": "https://files.pythonhosted.org/packages/7c/6b/283b519c664b09ec057726e32e22550fcd8ec5c8986cb23fac252f3308c4/villa-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf82e7b943b21644109583a582c3ed8a0135a5b16ee472b5f1989a15d3e80daf",
                "md5": "24fb5d08c2fe711c32be9722f1c393d4",
                "sha256": "313f90a060445f9bba137d0dffab698ba64036e0895273ecf7b23dadcbc81856"
            },
            "downloads": -1,
            "filename": "villa-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "24fb5d08c2fe711c32be9722f1c393d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 25676,
            "upload_time": "2023-10-25T03:07:39",
            "upload_time_iso_8601": "2023-10-25T03:07:39.569542Z",
            "url": "https://files.pythonhosted.org/packages/bf/82/e7b943b21644109583a582c3ed8a0135a5b16ee472b5f1989a15d3e80daf/villa-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-25 03:07:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CMHopeSunshine",
    "github_project": "villa-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "villa"
}
        
Elapsed time: 2.78373s