NoneBot2 米游社大别野 Bot 适配器。MiHoYo Villa Bot adapter for nonebot2.
Project description
安装
在nb create创建项目时选择Villa适配器
或在现有NoneBot2项目目录下使用脚手架安装:
nb adapter install nonebot-adapter-villa
配置
修改 NoneBot 配置文件 .env 或者 .env.*。
Driver
本适配器同时需要ReverseDriver和ForwardDriver,参考 driver 配置项。
例如:
DRIVER=~fastapi+~httpx
VILLA_BOTS
配置 Bot 帐号列表,每个bot有4个必填配置,可前往「大别野开放平台」(ID: OpenVilla)申请,取得以下配置:
bot_id: 机器人id,以bot_开头bot_secret: 机器人密钥pub_key: 加密和验证所需的 pub_keycallback_url: http回调地址 endpoint,例如申请bot时给的回调地址是http://域名/your/callback/url,那么配置里的callback_url填写/your/callback/url
此外还有以下选填配置:
verify_event:是否对回调事件签名进行验证
例如:
VILLA_BOTS='
[
{
"bot_id": "bot_123456789",
"bot_secret": "abc123def456",
"pub_key": "-----BEGIN PUBLIC KEY-----\nyour_pub_key\n-----END PUBLIC KEY-----\n",
"callback_url": "/your/callback/url",
"verify_event": true
}
]
'
已支持消息段
MessageSegment.text: 纯文本- 米游社自带表情也是用text来发送,以[表情名]格式,例如MessageSegment.text("[爱心]")
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 端显示出来
以下是一个简单的插件示例,展示各种消息段:
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会回复这是一段纯文本
交流、建议和反馈
大别野 Bot 和本适配器均为开发测试中,如遇问题请提出 issue ,感谢支持!
也欢迎来开发者的大别野「尘世闲游」(ID: wgiJNaU)进行交流~
相关项目
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_adapter_villa-1.1.0.tar.gz.
File metadata
- Download URL: nonebot_adapter_villa-1.1.0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbeca5cdf6966a2b81cd63dea6f8d2dc8586910f8cb542ae03d72ed587954e3e
|
|
| MD5 |
5dad77882c70dae7f05eea1e7511bba2
|
|
| BLAKE2b-256 |
ff94eade53bef45f26514387d8cd079f3efe0205e10b1091d3a157b7f176b75a
|
File details
Details for the file nonebot_adapter_villa-1.1.0-py3-none-any.whl.
File metadata
- Download URL: nonebot_adapter_villa-1.1.0-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb0c79bf0125aa5a6705ff556e05445ba1ad2a2b9c6317c4bc5d699b1375f633
|
|
| MD5 |
30da2304c27e6cbf21f2616759156475
|
|
| BLAKE2b-256 |
6ae03e5b61a7ecfbf959cacaa304bec2873dacb6fe647bc0e2283bd00679da33
|