NoneBot2米游社大别野Bot适配器。MiHoYo Villa Bot adapter for nonebot2.
Project description
安装
在NoneBot2项目目录下使用脚手架安装:
nb adapter install nonebot-adapter-villa
配置
修改 NoneBot 配置文件 .env 或者 .env.*。
Driver
本适配器同时需要ReverseDriver和ForwardDriver,参考 driver 配置项。
例如:
DRIVER=~fastapi+~httpx
VILLA_BOTS
配置机器人帐号列表,每个bot有3个必填配置,在大别野官方机器人开发者社区(别野ID: OpenVilla)申请时获得,
- bot_id: 机器人id,以
bot_开头 - bot_secret: 机器人密钥
- callback_url: http回调地址,例如申请bot时给的回调地址是
http://域名/your/callback/url,那么配置里的callback_url填写/your/callback/url例如:
VILLA_BOTS='
[
{
"bot_id": "bot_123456789",
"bot_secret": "abc123def456",
"callback_url": "/your/callback/url"
}
]
'
示例
注意,当前大别野只能接收到有@Bot(在哪个位置皆可)的消息事件,且不能有多个@(即使是@两次Bot都不行)
消息段展示
以下是一个简单的插件示例,展示各种消息段:
from nonebot import on_command
from nonebot.params import CommandArg
from nonebot.adapters.villa import Bot, SendMessageEvent, Message, MessageSegment
matcher = on_command('发送')
@matcher.handle()
async def matcher_handler(bot: Bot, event: SendMessageEvent, cmd_arg: Message = CommandArg()):
msg = Message()
args = cmd_arg.extract_plain_text().strip().split(' ')
for arg in args:
if arg == "艾特我":
msg += MessageSegment.mention_user(event.villa_id, event.from_user_id)
elif arg == "艾特bot":
msg += MessageSegment.mention_robot(bot.self_id, bot.nickname)
elif arg == "文字":
msg += MessageSegment.text("文字")
# 表情也是用text来发送,以[表情名]格式,例如MessageSegment.text("[爱心]")
elif arg == "房间":
msg += MessageSegment.room_link(event.villa_id, event.room_id)
elif arg == "链接":
msg += MessageSegment.link("https://www.miyoushe.com/ys/article/39670307", show_text="这是链接")
# 使用link的话链接能够点击进行跳转,使用text的话不能点击
# show_text是指链接显示的文字,但在当前版本Web端大别野会无法正常跳转,最好不使用该参数
elif arg == "图片":
msg += MessageSegment.image("https://www.miyoushe.com/_nuxt/img/miHoYo_Game.2457753.png")
# 暂时只支持url图片
# 如果在单次消息中,发送多张图片或者与其他消息段拼接,那么将无法在web端显示出来
# 所以建议每张图片单独发送
elif arg == "帖子":
msg += MessageSegment.post("https://www.miyoushe.com/ys/article/40391314")
# 帖子消息段只能单独发送,和其他消息段拼接时将被无视
await matcher.finish(msg)
使用命令@bot /发送 艾特我 艾特bot 文字 房间 链接时,bot会回复@你的名字 @bot的名字 文字 #房间名 这是链接
交流和反馈
目前无论是大别野Bot还是本适配器都在测试开发中,如遇问题请提出issue,感谢支持!
也欢迎来我的大别野【尘世闲游】进行交流:
- 大别野ID: wgiJNaU,可搜索加入
- Web端链接,目前仅PC端可访问
相关项目
推荐有成熟Python开发经验但对NoneBot2不熟悉的小伙伴选择大别野Bot Python SDK,
对NoneBot2熟悉或希望接触更成熟的生态的小伙伴选择NoneBot2+本适配器进行开发。
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-0.3.0.tar.gz.
File metadata
- Download URL: nonebot_adapter_villa-0.3.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32dd22107ed5086598f2fdb3005385665bdcb51677c4085ae3aa8ce6dc2dbb2a
|
|
| MD5 |
84b5380267a8ef31f26fb20f62523d6b
|
|
| BLAKE2b-256 |
aad98605ebb814e53861f95b443b58069d4f7920dad14e886922424f47bd2987
|
File details
Details for the file nonebot_adapter_villa-0.3.0-py3-none-any.whl.
File metadata
- Download URL: nonebot_adapter_villa-0.3.0-py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b185f061d8996f27e9f49fafd9dfa7afe60ff6753b846ce7d8dd682af289f481
|
|
| MD5 |
2e7c1d4fe34e899bdb3af718a648e59b
|
|
| BLAKE2b-256 |
184ea3bf418befa7c2b0754f1a0d971d25581a5babbbef41c8c767eee646835c
|