chore: prepare v2.0.0 release

This commit is contained in:
手瓜一十雪 committed 2026-10-18 13:58:08 +08:00
1 parent 1001f55a06
commit c15b2d857d
31 files changed
+965 -40

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"license": "SEE LICENSE IN LICENSE",
"name": "@snowluma/onebot",
"version": "1.14.22",
"version": "2.0.0",
"private": true,
"type": "module",
"description": "SnowLuma OneBot v11 adapter — the protocol translation layer that maps the public OneBot vocabulary (HTTP / WebSocket actions, message segments, post events) onto @snowluma/core's typed Api hub (`bridge.apis.<area>.method()`). Owns network adapters (HTTP server / HTTP client / WS server / WS client), the registered action handlers, the receive-side event→OneBot converter, message-id hashing, message store (SQLite-backed event history), media store, and the OneBot instance + manager that ties one OneBotConfig to one Bridge. Per-file subpath exports mirror the legacy `core/src/onebot/*` layout 1:1 so the previous `import { … } from '../onebot/<x>'` collapses to `import { … } from '@snowluma/onebot/<x>'`.",
+60
View File
@@ -25,6 +25,16 @@ async function uploadQzoneImages(
const QZONE_UGC_RIGHTS = new Set<number>([1, 4, 16, 64, 128]);
const qzoneCommentProperties = {
uin: { type: 'integer', description: '评论者 QQ 号' },
name: { type: 'string', description: '评论者昵称' },
time: { type: 'integer', description: '评论时间(unix 秒)' },
content: { type: 'string', description: '评论正文,保留空间表情和 @ 标记' },
comment_id: { type: 'string', description: '评论 ID,在所属说说或父评论内唯一' },
};
const qzoneCommentRequired = ['uin', 'name', 'time', 'content', 'comment_id'];
export const actions = [
// get_qzone_msg_list — 获取 QQ 空间说说列表。无 go-cqhttp 标准,自定义命名。
// 默认取机器人自己的空间;传 target_uin 可查看指定账号(需有权限)。
@@ -75,6 +85,56 @@ export const actions = [
},
}),
defineAction({
name: 'get_qzone_msg_detail',
readOnly: true,
summary: '获取 QQ 空间说说详情与一页评论(含服务端内联回复,需有访问权限)',
returns:
'说说详情、服务端报告的评论总数与本页评论;replies 仅含服务端内联返回的二级回复,不保证完整。',
returnsSchema: {
type: 'object',
properties: {
tid: { type: 'string', description: '说说 ID' },
content: { type: 'string', description: '说说正文' },
comment_num: { type: 'integer', description: '服务端报告的评论总数(非本页数量)' },
comments: {
type: 'array',
description: '本页一级评论,数量可能少于 num',
items: {
type: 'object',
properties: {
...qzoneCommentProperties,
replies: {
type: 'array',
description: '服务端内联二级回复,可能不完整',
items: {
type: 'object',
properties: qzoneCommentProperties,
required: qzoneCommentRequired,
},
},
},
required: [...qzoneCommentRequired, 'replies'],
},
},
},
required: ['tid', 'content', 'comment_num', 'comments'],
},
params: {
tid: f
.string({ allowEmpty: false })
.describe('说说 tid(来自 get_qzone_msg_list / send_qzone_msg)'),
target_uin: f.userId().describe('说说所属 QQ 号,省略则取机器人自己').optional(),
pos: f.int({ min: 0 }).describe('一级评论起始偏移').default(0),
num: f
.int({ min: 1, max: 100 })
.describe('请求的一级评论数量,实际数量受服务端限制')
.default(20),
},
run: async (p, ctx) =>
okResponse(await ctx.bridge.apis.qzone.getMsgDetail(p.tid, p.target_uin, p.pos, p.num)),
}),
// get_qzone_feeds — 获取好友动态(feed)。只读,始终以机器人自己身份拉取。
// 每条 feed 含结构化字段 + 预渲染 html 原样透传(深度解析交由调用方)。
defineAction({
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from 'vitest';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { ApiHandler, type ApiActionContext } from '../src/api-handler';
import { actions } from '../src/actions/qzone';
function makeHandler(qzone: Record<string, unknown>): ApiHandler {
const bridge = { apis: { qzone } } as unknown as BridgeInterface;
@@ -9,6 +10,74 @@ function makeHandler(qzone: Record<string, unknown>): ApiHandler {
}
describe('qzone actions', () => {
it('get_qzone_msg_detail returns the comment page with default parameters', async () => {
const detail = {
tid: 'T1',
content: 'Post',
comment_num: 1,
comments: [
{
uin: 20002,
name: 'Reader',
time: 1700000000,
content: 'Hello',
comment_id: '0',
replies: [],
},
],
};
const getMsgDetail = vi.fn().mockResolvedValue(detail);
const res = await makeHandler({ getMsgDetail }).handle('get_qzone_msg_detail', {
tid: 'T1',
});
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: detail });
expect(getMsgDetail).toHaveBeenCalledWith('T1', undefined, 0, 20);
expect(
actions.find((action) => action.names.includes('get_qzone_msg_detail'))?.describe()
.readOnly,
).toBe(true);
});
it('get_qzone_msg_detail accepts HTTP query strings for owner and pagination', async () => {
const getMsgDetail = vi
.fn()
.mockResolvedValue({ tid: 'T1', content: '', comment_num: 0, comments: [] });
const res = await makeHandler({ getMsgDetail }).handle('get_qzone_msg_detail', {
tid: 'T1',
target_uin: '20002',
pos: '5',
num: '10',
});
expect(res).toMatchObject({ status: 'ok', retcode: 0 });
expect(getMsgDetail).toHaveBeenCalledWith('T1', 20002, 5, 10);
});
it.each([
{},
{ tid: '' },
{ tid: 'T1', target_uin: 0 },
{ tid: 'T1', target_uin: 'bad' },
{ tid: 'T1', pos: -1 },
{ tid: 'T1', num: 0 },
{ tid: 'T1', num: 101 },
])('get_qzone_msg_detail rejects invalid params (%j) before fetching', async (params) => {
const getMsgDetail = vi.fn();
const res = await makeHandler({ getMsgDetail }).handle('get_qzone_msg_detail', params);
expect(res).toMatchObject({ status: 'failed', retcode: 1400 });
expect(getMsgDetail).not.toHaveBeenCalled();
});
it('get_qzone_msg_detail exposes upstream failures', async () => {
const getMsgDetail = vi
.fn()
.mockRejectedValue(new Error('qzone msg detail failed: code=-3000 need login'));
const res = await makeHandler({ getMsgDetail }).handle('get_qzone_msg_detail', {
tid: 'T1',
});
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
expect(res.wording).toContain('code=-3000 need login');
});
it('send_qzone_msg uploads images and publishes richvals joined with tab', async () => {
const uploadImageFromSource = vi
.fn()