<p align="center">
<a href="https://v2.nonebot.dev/"><img src="https://v2.nonebot.dev/logo.png" width="200" height="200" alt="nonebot-adapter-villa"></a>
</p>
<div align="center">
# NoneBot-Adapter-Villa
_✨ 大别野 协议适配 ✨_
<a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/nonebot-adapter-villa@master/LICENSE">
<img src="https://img.shields.io/github/license/CMHopeSunshine/nonebot-adapter-villa" alt="license">
</a>
<img src="https://img.shields.io/pypi/v/nonebot-adapter-villa" alt="version">
<img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python">
<a href="https://pypi.python.org/pypi/nonebot-adapter-villa">
<img src="https://img.shields.io/pypi/dm/nonebot-adapter-villa" alt="pypi download">
</a>
<a href="https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/838e7f55-f8b8-49ff-aec0-29ad264931cf">
<img src="https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/838e7f55-f8b8-49ff-aec0-29ad264931cf.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>
## 安装
在 `nb create` 创建项目时选择 `Villa` 适配器
或在现有 `NoneBot2` 项目目录下使用脚手架安装:
```
nb adapter install nonebot-adapter-villa
```
## 配置
修改 NoneBot 配置文件 `.env` 或者 `.env.*`。
配置 Bot 帐号列表,每个 bot 有 3 个必填配置,可前往[「大别野开放平台」](https://open.miyoushe.com/#/login)申请,取得以下配置:
- `bot_id`: 机器人 id,以`bot_`开头
- `bot_secret`: 机器人密钥
- `pub_key`: 加密和验证所需的 pub_key (请使用开放平台中的复制按钮而不是手动复制)
- `test_villa_id`: Bot 未上线时填写调试别野的 id,已上线可不填或填 `0`
此外,还要根据连接方式填写额外配置:
- `connection_type`: 连接方式,填写 `webhook` 或 `websocket`,默认为 `webhook`
### Webhook 连接
- `callback_url`: http 回调地址 endpoint,例如开放平台中回调地址是`http://域名/your/callback/url`,那么配置里的 `callback_url` 填写 `/your/callback/url`
- `verify_event`:是否对回调事件签名进行验证,默认为 `True`
使用 webhook 方式连接时,驱动器需要 `ReverseDriver` 和 `ForwardDriver`,参考 [driver](https://v2.nonebot.dev/docs/next/advanced/driver#%E9%A9%B1%E5%8A%A8%E5%99%A8%E7%B1%BB%E5%9E%8B) 配置项。
webhook 配置完整示例:
```dotenv
DRIVER=~fastapi+~httpx
VILLA_BOTS='
[
{
"bot_id": "bot_123456789",
"bot_secret": "abc123def456",
"pub_key": "-----BEGIN PUBLIC KEY-----\nyour_pub_key\n-----END PUBLIC KEY-----\n",
"connection_type": "webhook",
"callback_url": "/your/callback/url",
"verify_event": true
}
]
'
```
### Websocket 连接 (官方测试中)
使用 websocket 方式连接时,驱动器需要 `ForwardDriver`,参考 [driver](https://v2.nonebot.dev/docs/next/advanced/driver#%E9%A9%B1%E5%8A%A8%E5%99%A8%E7%B1%BB%E5%9E%8B) 配置项。
websocket 配置完整示例:
```dotenv
DRIVER=~httpx+~websockets
VILLA_BOTS='
[
{
"bot_id": "bot_123456789",
"bot_secret": "abc123def456",
"pub_key": "-----BEGIN PUBLIC KEY-----\nyour_pub_key\n-----END PUBLIC KEY-----\n",
"connection_type": "websocket",
"test_villa_id": 0
}
]
'
```
## 已支持消息段
- `MessageSegment.text`: 纯文本
+ 米游社自带表情也是用text来发送,以[表情名]格式,例如:`MessageSegment.text("[爱心]")`
+ 支持样式,,可叠加:
+ `bold`: 加粗
+ `italic`: 斜体
+ `underline`: 下划线
+ `strikethrough`: 删除线
+ 例如:`MessageSegment.text("加粗", blod=True) + MessageSegment.text("斜体", italic=True)`
- `MessageSegment.mention_robot`: @机器人
- `MessageSegment.mention_user`: @用户
+ `user_name` 和 `villa_id` 必须给出其中之一,给 `villa_id` 时,调用 api 来获取用户名
- `MessageSegment.mention_all`: @全体成员
- `MessageSegment.room_link`: #房间跳转链接
- `MessageSegment.link`: 超链接
+ 使用 link 的话链接能够点击进行跳转,使用 text 的话不能点击
+ 字段 `show_text` 是指链接显示的文字,但若指定了该字段,Web 端大别野会无法正常跳转
+ 字段 `requires_bot_access_token` 为 True 时,跳转链接会带上含有用户信息的 token
- `MessageSegment.quote`: 引用(回复)消息
+ 不能**单独**使用,要与其他消息段一起使用
- `MessageSegment.image`: URL 图片
+ 图片 url 需为米哈游官方图床 url
+ 非官方图床 url 可以通过 `Bot.transfer_image` 接口转换为官方图床 url
+ 本地图片可以通过 `Bot.upload_image` 接口来上传图片,使用返回结果的 url 来发送
+ 一条消息只能发送一张图片,多张图片拼接时,只会发送最后一张
+ 与其他消息段拼接时,将无法在 web 端显示出来
- `MessageSegment.post`: 米游社帖子
+ 只能单独发送,与其他消息段拼接时将会被忽略
- `MessageSegment.preview_link`: 预览链接(卡片)
+ 该消息段未在官方文档公开
+ 无法在 web 端显示出来
- `MessageSegment.badge`: 消息徽标(消息下方的可链接跳转的下标)
+ 该消息段未在官方文档公开
+ 不能**单独**使用,要与其他消息段一起使用
+ 无法在 web 端显示出来
- 消息组件,有两种构造方式:
+ `MessageSegment.components`:传入若干个 component,适配器会自动根据组件显示的文本长度来计算组件面板布局(推荐)
+ `MessageSegment.panel`:传入一个组件模板 ID 或自己构造好的自定义组件面板布局 `Panel` 对象
以下是一个简单的插件示例,展示各种消息段:
```python
from nonebot import on_command
from nonebot.params import CommandArg
from nonebot.adapters.villa import MessageSegment, SendMessageEvent, Message
matcher = on_command("test")
@matcher.handle()
async def _(event: SendMessageEvent, args: Message = CommandArg()):
arg = args.extract_plain_text().strip()
if arg == "纯文本":
msg = MessageSegment.text(text="这是一段纯文本")
elif arg == "艾特bot":
msg = MessageSegment.mention_robot(
bot_id=event.robot.template.id, bot_name=event.robot.template.name
)
elif arg == "艾特我":
msg = MessageSegment.mention_user(
user_id=event.from_user_id, villa_id=event.villa_id
)
elif arg == "艾特全体":
msg = MessageSegment.mention_all()
elif arg == "房间链接":
msg = MessageSegment.room_link(villa_id=event.villa_id, room_id=event.room_id)
elif arg == "超链接":
msg = MessageSegment.link(
url="https://www.baidu.com", show_text="百度", requires_bot_access_token=False
)
elif arg == "引用消息":
msg = MessageSegment.quote(event.msg_uid, event.send_at) + MessageSegment.text(
text="引用原消息"
)
elif arg == "图片":
msg = MessageSegment.image(
url="https://www.miyoushe.com/_nuxt/img/miHoYo_Game.2457753.png"
)
elif arg == "帖子":
msg = MessageSegment.post(
post_id="https://www.miyoushe.com/ys/article/40391314"
)
elif arg == "预览链接":
msg = MessageSegment.preview_link(
icon_url="https://www.bilibili.com/favicon.ico",
image_url="https://i2.hdslb.com/bfs/archive/21b82856df6b8a2ae759dddac66e2c79d41fe6bc.jpg@672w_378h_1c_!web-home-common-cover.avif",
is_internal_link=False,
title="崩坏3第一偶像爱酱",
content="「海的女儿」——《崩坏3》S级律者角色「死生之律者」宣传PV",
url="https://www.bilibili.com/video/BV1Mh4y1M79t?spm_id_from=333.1007.tianma.2-2-5.click",
source_name="哔哩哔哩",
)
elif arg == "徽标消息":
msg = MessageSegment.badge(
icon_url="https://upload-bbs.mihoyo.com/vila_bot/bbs_origin_badge.png",
text="徽标",
url="https://mihoyo.com",
) + MessageSegment.text(text="带有徽标的消息")
else:
return
await matcher.finish(msg)
```
使用命令`@bot /test 纯文本`时,bot会回复`这是一段纯文本`
关于消息组件的详细介绍:
```python
from nonebot.adapters.villa.message import MessageSegment
from nonebot.adapters.villa.models import CallbackButton, InputButton, LinkButton, Panel
# 目前有三种按钮组件,每个组件都必须有 id 和 text 字段
# id字段用于标识组件,必须是唯一的,text字段用于显示组件的文本
# need_callback字段如果设为True,表示点击按钮后会触发ClickMsgComponentEvent事件回调
# extra字段用于开发者自定义,可以在事件回调中获取到
# 文本按钮
# 用户点击后,会将按钮的 input 字段内容填充到用户的输入框中
input_button = InputButton(
id="1",
text="文本按钮",
input="/文本",
)
# 回调按钮
# need_callback恒为True,点击按钮后会触发ClickMsgComponentEvent事件回调
callback_button = CallbackButton(
id="2",
text="回调按钮",
)
# 链接按钮
# 用户点击后,会跳转到按钮的 link 字段所指定的链接
# need_token字段为True时,会在链接中附带token参数,用于验证用户身份
link_button = LinkButton(
id="3",
text="链接按钮",
link="https://www.baidu.com",
need_token=True,
)
# 构造消息段
com_msg = MessageSegment.components(
input_button,
callback_button,
link_button,
)
# 适配器会自动根据每个组件的text字段的长度,自动调整按钮的排版
# 如果需要自定义排版,可以使用MessageSegment.panel方法
# 自己构造好Panel对象,传入
panel = Panel(mid_component_group_list=[[input_button, callback_button], [link_button]])
com_msg = MessageSegment.panel(panel)
# 如果有预先设置好的消息组件模板 ID,可以直接使用
template_id = 123456
com_msg = MessageSegment.panel(template_id)
# 模板通过 Bot.create_component_template 接口来创建
# 如果有多个 MessageSegment.panel 相加,则只会发送最后一个
```
## 交流、建议和反馈
如遇问题请提出 [issue](https://github.com/CMHopeSunshine/nonebot-adapter-villa/issues) ,感谢支持!
欢迎来开发者的大别野[「尘世闲游」]((https://dby.miyoushe.com/chat/1047/21652))(ID: `wgiJNaU`)进行交流~
## 相关项目
- [NoneBot2](https://github.com/nonebot/nonebot2): 非常好用的 Python 跨平台机器人框架!
- [villa-py](https://github.com/CMHopeSunshine/villa-py): 大别野 Bot Python SDK(暂时停更)。
Raw data
{
"_id": null,
"home_page": "https://github.com/CMHopeSunshine/nonebot-adapter-villa",
"name": "nonebot-adapter-villa",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "nonebot,mihoyo,bot",
"author": "CMHopeSunshine",
"author_email": "277073121@qq.com",
"download_url": "https://files.pythonhosted.org/packages/6e/56/dcb5cda0964f0d2fb933f2cf337d029898fd8f8ed23a8bd0f50911fc6d37/nonebot_adapter_villa-1.4.2.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a href=\"https://v2.nonebot.dev/\"><img src=\"https://v2.nonebot.dev/logo.png\" width=\"200\" height=\"200\" alt=\"nonebot-adapter-villa\"></a>\n</p>\n\n<div align=\"center\">\n\n# NoneBot-Adapter-Villa\n\n_\u2728 \u5927\u522b\u91ce \u534f\u8bae\u9002\u914d \u2728_\n\n<a href=\"https://cdn.jsdelivr.net/gh/CMHopeSunshine/nonebot-adapter-villa@master/LICENSE\">\n <img src=\"https://img.shields.io/github/license/CMHopeSunshine/nonebot-adapter-villa\" alt=\"license\">\n</a>\n<img src=\"https://img.shields.io/pypi/v/nonebot-adapter-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/nonebot-adapter-villa\">\n <img src=\"https://img.shields.io/pypi/dm/nonebot-adapter-villa\" alt=\"pypi download\">\n</a>\n<a href=\"https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/838e7f55-f8b8-49ff-aec0-29ad264931cf\">\n <img src=\"https://wakatime.com/badge/user/eed3f89c-5d65-46e6-ab19-78dcc4b62b3f/project/838e7f55-f8b8-49ff-aec0-29ad264931cf.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## \u5b89\u88c5\n\n\u5728 `nb create` \u521b\u5efa\u9879\u76ee\u65f6\u9009\u62e9 `Villa` \u9002\u914d\u5668\n\n\u6216\u5728\u73b0\u6709 `NoneBot2` \u9879\u76ee\u76ee\u5f55\u4e0b\u4f7f\u7528\u811a\u624b\u67b6\u5b89\u88c5\uff1a\n\n```\nnb adapter install nonebot-adapter-villa\n```\n\n## \u914d\u7f6e\n\n\u4fee\u6539 NoneBot \u914d\u7f6e\u6587\u4ef6 `.env` \u6216\u8005 `.env.*`\u3002\n\n\u914d\u7f6e Bot \u5e10\u53f7\u5217\u8868\uff0c\u6bcf\u4e2a bot \u6709 3 \u4e2a\u5fc5\u586b\u914d\u7f6e\uff0c\u53ef\u524d\u5f80[\u300c\u5927\u522b\u91ce\u5f00\u653e\u5e73\u53f0\u300d](https://open.miyoushe.com/#/login)\u7533\u8bf7\uff0c\u53d6\u5f97\u4ee5\u4e0b\u914d\u7f6e\uff1a\n\n- `bot_id`: \u673a\u5668\u4eba id\uff0c\u4ee5`bot_`\u5f00\u5934\n- `bot_secret`: \u673a\u5668\u4eba\u5bc6\u94a5\n- `pub_key`: \u52a0\u5bc6\u548c\u9a8c\u8bc1\u6240\u9700\u7684 pub_key (\u8bf7\u4f7f\u7528\u5f00\u653e\u5e73\u53f0\u4e2d\u7684\u590d\u5236\u6309\u94ae\u800c\u4e0d\u662f\u624b\u52a8\u590d\u5236)\n- `test_villa_id`: Bot \u672a\u4e0a\u7ebf\u65f6\u586b\u5199\u8c03\u8bd5\u522b\u91ce\u7684 id\uff0c\u5df2\u4e0a\u7ebf\u53ef\u4e0d\u586b\u6216\u586b `0`\n\n\u6b64\u5916\uff0c\u8fd8\u8981\u6839\u636e\u8fde\u63a5\u65b9\u5f0f\u586b\u5199\u989d\u5916\u914d\u7f6e\uff1a\n\n- `connection_type`: \u8fde\u63a5\u65b9\u5f0f\uff0c\u586b\u5199 `webhook` \u6216 `websocket`\uff0c\u9ed8\u8ba4\u4e3a `webhook`\n\n### Webhook \u8fde\u63a5\n\n- `callback_url`: http \u56de\u8c03\u5730\u5740 endpoint\uff0c\u4f8b\u5982\u5f00\u653e\u5e73\u53f0\u4e2d\u56de\u8c03\u5730\u5740\u662f`http://\u57df\u540d/your/callback/url`\uff0c\u90a3\u4e48\u914d\u7f6e\u91cc\u7684 `callback_url` \u586b\u5199 `/your/callback/url`\n- `verify_event`\uff1a\u662f\u5426\u5bf9\u56de\u8c03\u4e8b\u4ef6\u7b7e\u540d\u8fdb\u884c\u9a8c\u8bc1\uff0c\u9ed8\u8ba4\u4e3a `True`\n\n\u4f7f\u7528 webhook \u65b9\u5f0f\u8fde\u63a5\u65f6\uff0c\u9a71\u52a8\u5668\u9700\u8981 `ReverseDriver` \u548c `ForwardDriver`\uff0c\u53c2\u8003 [driver](https://v2.nonebot.dev/docs/next/advanced/driver#%E9%A9%B1%E5%8A%A8%E5%99%A8%E7%B1%BB%E5%9E%8B) \u914d\u7f6e\u9879\u3002\n\nwebhook \u914d\u7f6e\u5b8c\u6574\u793a\u4f8b\uff1a\n\n```dotenv\nDRIVER=~fastapi+~httpx\nVILLA_BOTS='\n[\n {\n \"bot_id\": \"bot_123456789\",\n \"bot_secret\": \"abc123def456\",\n \"pub_key\": \"-----BEGIN PUBLIC KEY-----\\nyour_pub_key\\n-----END PUBLIC KEY-----\\n\",\n \"connection_type\": \"webhook\",\n \"callback_url\": \"/your/callback/url\",\n \"verify_event\": true\n }\n]\n'\n```\n\n### Websocket \u8fde\u63a5 (\u5b98\u65b9\u6d4b\u8bd5\u4e2d)\n\n\u4f7f\u7528 websocket \u65b9\u5f0f\u8fde\u63a5\u65f6\uff0c\u9a71\u52a8\u5668\u9700\u8981 `ForwardDriver`\uff0c\u53c2\u8003 [driver](https://v2.nonebot.dev/docs/next/advanced/driver#%E9%A9%B1%E5%8A%A8%E5%99%A8%E7%B1%BB%E5%9E%8B) \u914d\u7f6e\u9879\u3002\n\nwebsocket \u914d\u7f6e\u5b8c\u6574\u793a\u4f8b\uff1a\n\n```dotenv\nDRIVER=~httpx+~websockets\nVILLA_BOTS='\n[\n {\n \"bot_id\": \"bot_123456789\",\n \"bot_secret\": \"abc123def456\",\n \"pub_key\": \"-----BEGIN PUBLIC KEY-----\\nyour_pub_key\\n-----END PUBLIC KEY-----\\n\",\n \"connection_type\": \"websocket\",\n \"test_villa_id\": 0\n }\n]\n'\n```\n\n## \u5df2\u652f\u6301\u6d88\u606f\u6bb5\n\n- `MessageSegment.text`: \u7eaf\u6587\u672c\n + \u7c73\u6e38\u793e\u81ea\u5e26\u8868\u60c5\u4e5f\u662f\u7528text\u6765\u53d1\u9001\uff0c\u4ee5[\u8868\u60c5\u540d]\u683c\u5f0f\uff0c\u4f8b\u5982\uff1a`MessageSegment.text(\"[\u7231\u5fc3]\")`\n + \u652f\u6301\u6837\u5f0f,\uff0c\u53ef\u53e0\u52a0:\n + `bold`: \u52a0\u7c97\n + `italic`: \u659c\u4f53\n + `underline`: \u4e0b\u5212\u7ebf\n + `strikethrough`: \u5220\u9664\u7ebf\n + \u4f8b\u5982\uff1a`MessageSegment.text(\"\u52a0\u7c97\", blod=True) + MessageSegment.text(\"\u659c\u4f53\", italic=True)`\n- `MessageSegment.mention_robot`: @\u673a\u5668\u4eba\n- `MessageSegment.mention_user`: @\u7528\u6237\n + `user_name` \u548c `villa_id` \u5fc5\u987b\u7ed9\u51fa\u5176\u4e2d\u4e4b\u4e00\uff0c\u7ed9 `villa_id` \u65f6\uff0c\u8c03\u7528 api \u6765\u83b7\u53d6\u7528\u6237\u540d\n- `MessageSegment.mention_all`: @\u5168\u4f53\u6210\u5458\n- `MessageSegment.room_link`: #\u623f\u95f4\u8df3\u8f6c\u94fe\u63a5\n- `MessageSegment.link`: \u8d85\u94fe\u63a5\n + \u4f7f\u7528 link \u7684\u8bdd\u94fe\u63a5\u80fd\u591f\u70b9\u51fb\u8fdb\u884c\u8df3\u8f6c\uff0c\u4f7f\u7528 text \u7684\u8bdd\u4e0d\u80fd\u70b9\u51fb\n + \u5b57\u6bb5 `show_text` \u662f\u6307\u94fe\u63a5\u663e\u793a\u7684\u6587\u5b57\uff0c\u4f46\u82e5\u6307\u5b9a\u4e86\u8be5\u5b57\u6bb5\uff0cWeb \u7aef\u5927\u522b\u91ce\u4f1a\u65e0\u6cd5\u6b63\u5e38\u8df3\u8f6c\n + \u5b57\u6bb5 `requires_bot_access_token` \u4e3a True \u65f6\uff0c\u8df3\u8f6c\u94fe\u63a5\u4f1a\u5e26\u4e0a\u542b\u6709\u7528\u6237\u4fe1\u606f\u7684 token\n- `MessageSegment.quote`: \u5f15\u7528(\u56de\u590d)\u6d88\u606f\n + \u4e0d\u80fd**\u5355\u72ec**\u4f7f\u7528\uff0c\u8981\u4e0e\u5176\u4ed6\u6d88\u606f\u6bb5\u4e00\u8d77\u4f7f\u7528\n- `MessageSegment.image`: URL \u56fe\u7247\n + \u56fe\u7247 url \u9700\u4e3a\u7c73\u54c8\u6e38\u5b98\u65b9\u56fe\u5e8a url\n + \u975e\u5b98\u65b9\u56fe\u5e8a url \u53ef\u4ee5\u901a\u8fc7 `Bot.transfer_image` \u63a5\u53e3\u8f6c\u6362\u4e3a\u5b98\u65b9\u56fe\u5e8a url\n + \u672c\u5730\u56fe\u7247\u53ef\u4ee5\u901a\u8fc7 `Bot.upload_image` \u63a5\u53e3\u6765\u4e0a\u4f20\u56fe\u7247\uff0c\u4f7f\u7528\u8fd4\u56de\u7ed3\u679c\u7684 url \u6765\u53d1\u9001\n + \u4e00\u6761\u6d88\u606f\u53ea\u80fd\u53d1\u9001\u4e00\u5f20\u56fe\u7247\uff0c\u591a\u5f20\u56fe\u7247\u62fc\u63a5\u65f6\uff0c\u53ea\u4f1a\u53d1\u9001\u6700\u540e\u4e00\u5f20\n + \u4e0e\u5176\u4ed6\u6d88\u606f\u6bb5\u62fc\u63a5\u65f6\uff0c\u5c06\u65e0\u6cd5\u5728 web \u7aef\u663e\u793a\u51fa\u6765\n- `MessageSegment.post`: \u7c73\u6e38\u793e\u5e16\u5b50\n + \u53ea\u80fd\u5355\u72ec\u53d1\u9001\uff0c\u4e0e\u5176\u4ed6\u6d88\u606f\u6bb5\u62fc\u63a5\u65f6\u5c06\u4f1a\u88ab\u5ffd\u7565\n- `MessageSegment.preview_link`: \u9884\u89c8\u94fe\u63a5(\u5361\u7247)\n + \u8be5\u6d88\u606f\u6bb5\u672a\u5728\u5b98\u65b9\u6587\u6863\u516c\u5f00\n + \u65e0\u6cd5\u5728 web \u7aef\u663e\u793a\u51fa\u6765\n- `MessageSegment.badge`: \u6d88\u606f\u5fbd\u6807(\u6d88\u606f\u4e0b\u65b9\u7684\u53ef\u94fe\u63a5\u8df3\u8f6c\u7684\u4e0b\u6807)\n + \u8be5\u6d88\u606f\u6bb5\u672a\u5728\u5b98\u65b9\u6587\u6863\u516c\u5f00\n + \u4e0d\u80fd**\u5355\u72ec**\u4f7f\u7528\uff0c\u8981\u4e0e\u5176\u4ed6\u6d88\u606f\u6bb5\u4e00\u8d77\u4f7f\u7528\n + \u65e0\u6cd5\u5728 web \u7aef\u663e\u793a\u51fa\u6765\n- \u6d88\u606f\u7ec4\u4ef6\uff0c\u6709\u4e24\u79cd\u6784\u9020\u65b9\u5f0f\uff1a\n + `MessageSegment.components`\uff1a\u4f20\u5165\u82e5\u5e72\u4e2a component\uff0c\u9002\u914d\u5668\u4f1a\u81ea\u52a8\u6839\u636e\u7ec4\u4ef6\u663e\u793a\u7684\u6587\u672c\u957f\u5ea6\u6765\u8ba1\u7b97\u7ec4\u4ef6\u9762\u677f\u5e03\u5c40(\u63a8\u8350)\n + `MessageSegment.panel`\uff1a\u4f20\u5165\u4e00\u4e2a\u7ec4\u4ef6\u6a21\u677f ID \u6216\u81ea\u5df1\u6784\u9020\u597d\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u9762\u677f\u5e03\u5c40 `Panel` \u5bf9\u8c61\n\n\n\n\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u63d2\u4ef6\u793a\u4f8b\uff0c\u5c55\u793a\u5404\u79cd\u6d88\u606f\u6bb5\uff1a\n\n```python\nfrom nonebot import on_command\nfrom nonebot.params import CommandArg\nfrom nonebot.adapters.villa import MessageSegment, SendMessageEvent, Message\n\nmatcher = on_command(\"test\")\n\n\n@matcher.handle()\nasync def _(event: SendMessageEvent, args: Message = CommandArg()):\n arg = args.extract_plain_text().strip()\n if arg == \"\u7eaf\u6587\u672c\":\n msg = MessageSegment.text(text=\"\u8fd9\u662f\u4e00\u6bb5\u7eaf\u6587\u672c\")\n elif arg == \"\u827e\u7279bot\":\n msg = MessageSegment.mention_robot(\n bot_id=event.robot.template.id, bot_name=event.robot.template.name\n )\n elif arg == \"\u827e\u7279\u6211\":\n msg = MessageSegment.mention_user(\n user_id=event.from_user_id, villa_id=event.villa_id\n )\n elif arg == \"\u827e\u7279\u5168\u4f53\":\n msg = MessageSegment.mention_all()\n elif arg == \"\u623f\u95f4\u94fe\u63a5\":\n msg = MessageSegment.room_link(villa_id=event.villa_id, room_id=event.room_id)\n elif arg == \"\u8d85\u94fe\u63a5\":\n msg = MessageSegment.link(\n url=\"https://www.baidu.com\", show_text=\"\u767e\u5ea6\", requires_bot_access_token=False\n )\n elif arg == \"\u5f15\u7528\u6d88\u606f\":\n msg = MessageSegment.quote(event.msg_uid, event.send_at) + MessageSegment.text(\n text=\"\u5f15\u7528\u539f\u6d88\u606f\"\n )\n elif arg == \"\u56fe\u7247\":\n msg = MessageSegment.image(\n url=\"https://www.miyoushe.com/_nuxt/img/miHoYo_Game.2457753.png\"\n )\n elif arg == \"\u5e16\u5b50\":\n msg = MessageSegment.post(\n post_id=\"https://www.miyoushe.com/ys/article/40391314\"\n )\n elif arg == \"\u9884\u89c8\u94fe\u63a5\":\n msg = MessageSegment.preview_link(\n icon_url=\"https://www.bilibili.com/favicon.ico\",\n image_url=\"https://i2.hdslb.com/bfs/archive/21b82856df6b8a2ae759dddac66e2c79d41fe6bc.jpg@672w_378h_1c_!web-home-common-cover.avif\",\n is_internal_link=False,\n title=\"\u5d29\u574f3\u7b2c\u4e00\u5076\u50cf\u7231\u9171\",\n content=\"\u300c\u6d77\u7684\u5973\u513f\u300d\u2014\u2014\u300a\u5d29\u574f3\u300bS\u7ea7\u5f8b\u8005\u89d2\u8272\u300c\u6b7b\u751f\u4e4b\u5f8b\u8005\u300d\u5ba3\u4f20PV\",\n url=\"https://www.bilibili.com/video/BV1Mh4y1M79t?spm_id_from=333.1007.tianma.2-2-5.click\",\n source_name=\"\u54d4\u54e9\u54d4\u54e9\",\n )\n elif arg == \"\u5fbd\u6807\u6d88\u606f\":\n msg = MessageSegment.badge(\n icon_url=\"https://upload-bbs.mihoyo.com/vila_bot/bbs_origin_badge.png\",\n text=\"\u5fbd\u6807\",\n url=\"https://mihoyo.com\",\n ) + MessageSegment.text(text=\"\u5e26\u6709\u5fbd\u6807\u7684\u6d88\u606f\")\n else:\n return\n\n await matcher.finish(msg)\n\n```\n\u4f7f\u7528\u547d\u4ee4`@bot /test \u7eaf\u6587\u672c`\u65f6\uff0cbot\u4f1a\u56de\u590d`\u8fd9\u662f\u4e00\u6bb5\u7eaf\u6587\u672c`\n\n\n\u5173\u4e8e\u6d88\u606f\u7ec4\u4ef6\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff1a\n\n```python\nfrom nonebot.adapters.villa.message import MessageSegment\nfrom nonebot.adapters.villa.models import CallbackButton, InputButton, LinkButton, Panel\n\n# \u76ee\u524d\u6709\u4e09\u79cd\u6309\u94ae\u7ec4\u4ef6\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u90fd\u5fc5\u987b\u6709 id \u548c text \u5b57\u6bb5\n# id\u5b57\u6bb5\u7528\u4e8e\u6807\u8bc6\u7ec4\u4ef6\uff0c\u5fc5\u987b\u662f\u552f\u4e00\u7684\uff0ctext\u5b57\u6bb5\u7528\u4e8e\u663e\u793a\u7ec4\u4ef6\u7684\u6587\u672c\n# need_callback\u5b57\u6bb5\u5982\u679c\u8bbe\u4e3aTrue\uff0c\u8868\u793a\u70b9\u51fb\u6309\u94ae\u540e\u4f1a\u89e6\u53d1ClickMsgComponentEvent\u4e8b\u4ef6\u56de\u8c03\n# extra\u5b57\u6bb5\u7528\u4e8e\u5f00\u53d1\u8005\u81ea\u5b9a\u4e49\uff0c\u53ef\u4ee5\u5728\u4e8b\u4ef6\u56de\u8c03\u4e2d\u83b7\u53d6\u5230\n\n# \u6587\u672c\u6309\u94ae\n# \u7528\u6237\u70b9\u51fb\u540e\uff0c\u4f1a\u5c06\u6309\u94ae\u7684 input \u5b57\u6bb5\u5185\u5bb9\u586b\u5145\u5230\u7528\u6237\u7684\u8f93\u5165\u6846\u4e2d\ninput_button = InputButton(\n id=\"1\",\n text=\"\u6587\u672c\u6309\u94ae\",\n input=\"/\u6587\u672c\",\n)\n\n# \u56de\u8c03\u6309\u94ae\n# need_callback\u6052\u4e3aTrue\uff0c\u70b9\u51fb\u6309\u94ae\u540e\u4f1a\u89e6\u53d1ClickMsgComponentEvent\u4e8b\u4ef6\u56de\u8c03\ncallback_button = CallbackButton(\n id=\"2\",\n text=\"\u56de\u8c03\u6309\u94ae\",\n)\n\n# \u94fe\u63a5\u6309\u94ae\n# \u7528\u6237\u70b9\u51fb\u540e\uff0c\u4f1a\u8df3\u8f6c\u5230\u6309\u94ae\u7684 link \u5b57\u6bb5\u6240\u6307\u5b9a\u7684\u94fe\u63a5\n# need_token\u5b57\u6bb5\u4e3aTrue\u65f6\uff0c\u4f1a\u5728\u94fe\u63a5\u4e2d\u9644\u5e26token\u53c2\u6570\uff0c\u7528\u4e8e\u9a8c\u8bc1\u7528\u6237\u8eab\u4efd\nlink_button = LinkButton(\n id=\"3\",\n text=\"\u94fe\u63a5\u6309\u94ae\",\n link=\"https://www.baidu.com\",\n need_token=True,\n)\n\n# \u6784\u9020\u6d88\u606f\u6bb5\ncom_msg = MessageSegment.components(\n input_button,\n callback_button,\n link_button,\n)\n\n# \u9002\u914d\u5668\u4f1a\u81ea\u52a8\u6839\u636e\u6bcf\u4e2a\u7ec4\u4ef6\u7684text\u5b57\u6bb5\u7684\u957f\u5ea6\uff0c\u81ea\u52a8\u8c03\u6574\u6309\u94ae\u7684\u6392\u7248\n# \u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u6392\u7248\uff0c\u53ef\u4ee5\u4f7f\u7528MessageSegment.panel\u65b9\u6cd5\n# \u81ea\u5df1\u6784\u9020\u597dPanel\u5bf9\u8c61\uff0c\u4f20\u5165\npanel = Panel(mid_component_group_list=[[input_button, callback_button], [link_button]])\ncom_msg = MessageSegment.panel(panel)\n\n# \u5982\u679c\u6709\u9884\u5148\u8bbe\u7f6e\u597d\u7684\u6d88\u606f\u7ec4\u4ef6\u6a21\u677f ID\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\ntemplate_id = 123456\ncom_msg = MessageSegment.panel(template_id)\n# \u6a21\u677f\u901a\u8fc7 Bot.create_component_template \u63a5\u53e3\u6765\u521b\u5efa\n\n# \u5982\u679c\u6709\u591a\u4e2a MessageSegment.panel \u76f8\u52a0\uff0c\u5219\u53ea\u4f1a\u53d1\u9001\u6700\u540e\u4e00\u4e2a\n```\n\n\n## \u4ea4\u6d41\u3001\u5efa\u8bae\u548c\u53cd\u9988\n\n\u5982\u9047\u95ee\u9898\u8bf7\u63d0\u51fa [issue](https://github.com/CMHopeSunshine/nonebot-adapter-villa/issues) \uff0c\u611f\u8c22\u652f\u6301\uff01\n\n\u6b22\u8fce\u6765\u5f00\u53d1\u8005\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- [villa-py](https://github.com/CMHopeSunshine/villa-py): \u5927\u522b\u91ce Bot Python SDK\uff08\u6682\u65f6\u505c\u66f4\uff09\u3002\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "NoneBot2 \u7c73\u6e38\u793e\u5927\u522b\u91ce Bot \u9002\u914d\u5668\u3002MiHoYo Villa Bot adapter for nonebot2.",
"version": "1.4.2",
"project_urls": {
"Documentation": "https://github.com/CMHopeSunshine/nonebot-adapter-villa",
"Homepage": "https://github.com/CMHopeSunshine/nonebot-adapter-villa",
"Repository": "https://github.com/CMHopeSunshine/nonebot-adapter-villa"
},
"split_keywords": [
"nonebot",
"mihoyo",
"bot"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e5d0b03e365bba6cf44cbec38e48f953e48af035a8bd0f3b3c188e4f15838c5d",
"md5": "f6726e44f4ea1fb9bd6e46c4afc611fc",
"sha256": "13583a494c007cf46f17166c0459423ff6e80dc05d7cbab12c4466776411353d"
},
"downloads": -1,
"filename": "nonebot_adapter_villa-1.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f6726e44f4ea1fb9bd6e46c4afc611fc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 38942,
"upload_time": "2023-12-21T06:57:44",
"upload_time_iso_8601": "2023-12-21T06:57:44.318894Z",
"url": "https://files.pythonhosted.org/packages/e5/d0/b03e365bba6cf44cbec38e48f953e48af035a8bd0f3b3c188e4f15838c5d/nonebot_adapter_villa-1.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6e56dcb5cda0964f0d2fb933f2cf337d029898fd8f8ed23a8bd0f50911fc6d37",
"md5": "728237b87083b679522dbe7fe0c9479f",
"sha256": "1234b946ec275f257eaf0a05769c6992243586930dd37eee4cd23fcd9282590a"
},
"downloads": -1,
"filename": "nonebot_adapter_villa-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "728237b87083b679522dbe7fe0c9479f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 37435,
"upload_time": "2023-12-21T06:57:46",
"upload_time_iso_8601": "2023-12-21T06:57:46.272933Z",
"url": "https://files.pythonhosted.org/packages/6e/56/dcb5cda0964f0d2fb933f2cf337d029898fd8f8ed23a8bd0f50911fc6d37/nonebot_adapter_villa-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-21 06:57:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "CMHopeSunshine",
"github_project": "nonebot-adapter-villa",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nonebot-adapter-villa"
}