适用于 NoneBot2 插件的被动消息构造集成
Project description
介绍
nonebot-plugin-msgbuf
是帮助开发者快速构造与发送跨平台消息结构的应用的工具。相较于 SAA 与 SegBuilder,本插件在开发中结构更为清晰优雅。
适配器支持状态
符号 | 含义 |
---|---|
✅ | 完全支持 |
🟨 | 部分支持,需要用户额外分平台处理 |
❌ | 不支持,发送时自动转化为后备文本 |
适配器 | 纯文本 | 图片 | 提及(@) | 回复 | 表情 | 语音 | 视频 | 文件 | 分享 | 地理位置 |
---|---|---|---|---|---|---|---|---|---|---|
OneBot V11 | ✅ | ✅ | 🟨 | 🟨 | 🟨 | ✅ | ✅ | ❌ | ✅ | ✅ |
OneBot V11 (Go-CQHTTP 拓展) | ✅ | ✅ | 🟨 | 🟨 | 🟨 | ✅ | ✅ | ✅ | ✅ | ✅ |
OneBot V12 | ✅ | ✅ | 🟨 | 🟨 | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ |
QQ 频道 | ✅ | ✅ | 🟨 | 🟨 | 🟨 | ❌ | ❌ | ❌ | ❌ | ❌ |
未写明的 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
安装
通过 nb-cli
:
nb plugin install nonebot-plugin-msgbuf
使用
关于
require()
的使用问题:NoneBot2 插件的首次导入必须通过 NoneBot2 自身的方式(包括但不限于
require()
,load_plugin()
等)完成,否则之后使用 NoneBot2 方式导入该插件的插件将无法正常工作。NoneBot2 插件体系要求必须使用
require()
加载插件依赖。
竞品对比
这是常规的消息构造与发送方法:
展开
from nonebot import on_message
from nonebot.adapters.onebot.v11 import MessageSegment
from pathlib import Path
ma = on_message()
@ma.handle()
async def test():
await ma.send(MessageSegment.image(Path("image.png")) + "Hello world!")
这是 SAA 的消息构造与发送方法:
展开
from nonebot import on_message, require
from pathlib import Path
require("nonebot_plugin_saa")
from nonebot_plugin_saa import MessageFactory, Text, Image
ma = on_message()
@ma.handle()
async def test():
await MessageFactory([Image(Path("image.png")), Text("Hello world!")]).send()
这是 SegBuilder 的消息构造与发送方法:
展开
from nonebot import on_message, require
from pathlib import Path
require("nonebot_plugin_segbuilder")
from nonebot_plugin_segbuilder import SegmentBuilder
ma = on_message()
@ma.handle()
async def test():
await ma.send(SegmentBuilder.image(Path("image.png")) + "Hello world!")
这是 MsgBuf 的消息构造与发送方法:
from nonebot import on_message, require
from pathlib import Path
require("nonebot_plugin_msgbuf")
from nonebot_plugin_msgbuf import MsgBuf
ma = on_message()
@ma.handle()
async def test():
async with MsgBuf() as mb:
mb.image(Path("image.png"))
mb.text("Hello world!")
@ma.handle()
async def test():
async with MsgBuf() as mb:
mb.image(Path("image.png")).text("Hello world!")
from nonebot_plugin_msgbuf import Image, Text
@ma.handle()
async def test():
async with MsgBuf() as mb:
mb << Image(Path("image.png")) << Text("Hello world!")
@ma.handle()
async def test():
await MsgBuf().image(Path("image.png")).text("Hello world!").send()
使用 Go-CQHTTP 拓展
发送文件
from nonebot_plugin_msgbuf import Specs
from pathlib import Path
@ma.handle()
async def test():
async with MsgBuf(specs=Specs.OB11_GOCQHTTP) as mb:
mb.file(Path("image.png"))
发送合并转发
from nonebot.adapters.onebot.v11 import Bot
from nonebot_plugin_msgbuf import FwdBuf
@ma.handle()
async def test(bot: Bot):
async with FwdBuf(bot, ("group", 114514)) as fb:
async with fb.node(1919810, "homo") as n:
n.text("114514")
n.image("file://homo.jpg")
async with fb.node(1919810, "homo") as n:
async with n.node(1919810, "homo") as n1:
n1.text("homo")
async with n.node(1919810, "homo") as n1:
n1.text("1919810")
Project details
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
Close
Hashes for nonebot-plugin-msgbuf-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07e8ed32b03a3ff4fa6a779d920cb74f08326eea9f65d08e4992e4c6bff1cb76 |
|
MD5 | e2a7043be1d8a20da74f1e65cb066434 |
|
BLAKE2b-256 | ae4ed151e307442da8b30313c263efff1f82db8e941fb3a5d94d0e166d4bb8ad |
Close
Hashes for nonebot_plugin_msgbuf-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fccb3b93376c9ebe46dbcba1368fbc068d64de561590ce345e2193eafb26221c |
|
MD5 | 12aa3e533f45528e265c9efe8e8b0515 |
|
BLAKE2b-256 | 6d4394123ec9fc76e3c92cc3bf82b9d3c5add2dac14a62ef4ead8a53c652d6f8 |