feat(onebot): add Qzone profile read and update actions (#586)
Add actions to read a space name and description and update the current account profile. Preserve omitted fields and support explicit empty values, with matching SDK types, MCP discovery, documentation, and tests.
This commit is contained in:
16 files changed
+862
-3
No files matched your search
@@ -144,6 +144,21 @@ const response = await bot.rawResponse('get_status');
|
||||
|
||||
`raw` 会在 SnowLuma 返回 `status: "failed"` 或非零 `retcode` 时抛出 `SnowLumaApiError`;`rawResponse` 会保留完整响应。
|
||||
|
||||
### 读取与修改空间资料
|
||||
|
||||
`get_qzone_profile` 返回 QQ 空间的名称和说明;这两个字段独立于 QQ 昵称和个性签名。
|
||||
|
||||
```ts
|
||||
const profile = await bot.raw('get_qzone_profile', {}); // 当前账号
|
||||
console.log(profile.name, profile.description);
|
||||
await bot.raw('get_qzone_profile', { target_uin: '10002' });
|
||||
|
||||
await bot.raw('set_qzone_profile', { name: '我的空间' });
|
||||
await bot.raw('set_qzone_profile', { description: '' }); // 清空说明
|
||||
```
|
||||
|
||||
`set_qzone_profile` 只修改当前账号,至少提供 `name`、`description` 中的一项;省略字段保持原值,空字符串表示清空。成功返回 `null`,登录失效、访问受限或上游要求验证时会抛出 `SnowLumaApiError`。修改后可再次读取资料确认结果。
|
||||
|
||||
### 读取空间说说评论
|
||||
|
||||
`get_qzone_msg_detail` 是只读扩展动作,`raw` 提供参数和结果类型:
|
||||
|
||||
@@ -179,6 +179,7 @@ export const SNOWLUMA_ACTIONS = [
|
||||
'get_qzone_feeds',
|
||||
'get_qzone_msg_detail',
|
||||
'get_qzone_msg_list',
|
||||
'get_qzone_profile',
|
||||
'get_rkey_server',
|
||||
'get_share_link',
|
||||
'like_qzone',
|
||||
@@ -203,6 +204,7 @@ export const SNOWLUMA_ACTIONS = [
|
||||
'set_group_robot_add_option',
|
||||
'set_qzone_ban',
|
||||
'set_qzone_msg_right',
|
||||
'set_qzone_profile',
|
||||
'share_group_ex',
|
||||
'share_peer',
|
||||
'test_download_stream',
|
||||
|
||||
@@ -97,6 +97,7 @@ import type {
|
||||
GetQunAlbumListParams,
|
||||
GetQzoneFeedsParams,
|
||||
GetQzoneMsgListParams,
|
||||
GetQzoneProfileParams,
|
||||
GroupAlbumCommentParams,
|
||||
GroupAlbumMediaLikeParams,
|
||||
GroupAlbumMediaParams,
|
||||
@@ -115,6 +116,7 @@ import type {
|
||||
SetGroupRobotAddOptionParams,
|
||||
SetQzoneBanParams,
|
||||
SetQzoneMsgRightParams,
|
||||
SetQzoneProfileParams,
|
||||
SharePeerParams,
|
||||
TestDownloadStreamParams,
|
||||
UploadFileStreamParams,
|
||||
@@ -184,6 +186,7 @@ import type {
|
||||
QzoneFeedsResult,
|
||||
QzoneMsgListResult,
|
||||
QzonePublishResult,
|
||||
QzoneProfileResult,
|
||||
QzoneUpdateRightResult,
|
||||
RkeyServerResult,
|
||||
SendFlashMsgResult,
|
||||
@@ -396,6 +399,7 @@ export interface SnowLumaActionMap {
|
||||
get_qun_album_list: { params: GetQunAlbumListParams; data: QunAlbumListResult };
|
||||
get_qzone_feeds: { params: GetQzoneFeedsParams; data: QzoneFeedsResult };
|
||||
get_qzone_msg_list: { params: GetQzoneMsgListParams; data: QzoneMsgListResult };
|
||||
get_qzone_profile: { params: GetQzoneProfileParams; data: QzoneProfileResult };
|
||||
get_rkey_server: { params: JsonObject; data: RkeyServerResult };
|
||||
get_share_link: { params: FilesetIdParams; data: string };
|
||||
like_qzone: { params: LikeQzoneParams; data: EmptyData };
|
||||
@@ -423,6 +427,7 @@ export interface SnowLumaActionMap {
|
||||
set_group_robot_add_option: { params: SetGroupRobotAddOptionParams; data: EmptyData };
|
||||
set_qzone_ban: { params: SetQzoneBanParams; data: EmptyData };
|
||||
set_qzone_msg_right: { params: SetQzoneMsgRightParams; data: QzoneUpdateRightResult };
|
||||
set_qzone_profile: { params: SetQzoneProfileParams; data: EmptyData };
|
||||
share_group_ex: { params: ActionGroupIdParams; data: string };
|
||||
share_peer: { params: SharePeerParams; data: ArkShareResult };
|
||||
test_download_stream: { params: TestDownloadStreamParams; data: TestDownloadStreamResult };
|
||||
|
||||
@@ -577,6 +577,18 @@ export interface GetQzoneFeedsParams extends JsonObject {
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
export interface GetQzoneProfileParams extends JsonObject {
|
||||
/** Defaults to the current account's space. */
|
||||
target_uin?: ActionNumberInput;
|
||||
}
|
||||
|
||||
/** Updates the current account's space; omitted fields are preserved. */
|
||||
export type SetQzoneProfileParams = JsonObject &
|
||||
(
|
||||
| { name: ActionStringInput; description?: ActionStringInput }
|
||||
| { name?: ActionStringInput; description: ActionStringInput }
|
||||
);
|
||||
|
||||
export interface QzoneMsgIdParams extends JsonObject {
|
||||
tid: ActionStringInput;
|
||||
}
|
||||
|
||||
@@ -396,6 +396,11 @@ export interface QzoneMsgListResult extends JsonObject {
|
||||
msglist: QzoneEmotion[];
|
||||
}
|
||||
|
||||
export interface QzoneProfileResult extends JsonObject {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface QzoneFeed extends JsonObject {
|
||||
uin: number;
|
||||
nickname: string;
|
||||
|
||||
@@ -56,6 +56,7 @@ export const actionParams = {
|
||||
get_qun_album_list: { group_id: '10001', attach_info: '' },
|
||||
get_qzone_feeds: { page_num: '1', count: '10', cursor: 'cursor-from-previous-response' },
|
||||
get_qzone_msg_list: { target_uin: '10002', pos: '0', num: '20' },
|
||||
get_qzone_profile: { target_uin: '10002' },
|
||||
get_rkey_server: {},
|
||||
get_share_link: fileset,
|
||||
like_qzone: qzoneLike,
|
||||
@@ -99,6 +100,7 @@ export const actionParams = {
|
||||
},
|
||||
set_qzone_ban: { user_id: '10002', enable: false },
|
||||
set_qzone_msg_right: { tid: 'post', ugc_right: '128', target_uins: ['10002'] },
|
||||
set_qzone_profile: { name: 'Space', description: '' },
|
||||
share_group_ex: { group_id: '10001' },
|
||||
share_peer: peer,
|
||||
test_download_stream: { error: false },
|
||||
@@ -155,6 +157,7 @@ export type CoveredAction =
|
||||
| 'get_qun_album_list'
|
||||
| 'get_qzone_feeds'
|
||||
| 'get_qzone_msg_list'
|
||||
| 'get_qzone_profile'
|
||||
| 'get_rkey_server'
|
||||
| 'get_share_link'
|
||||
| 'like_qzone'
|
||||
@@ -176,6 +179,7 @@ export type CoveredAction =
|
||||
| 'set_group_robot_add_option'
|
||||
| 'set_qzone_ban'
|
||||
| 'set_qzone_msg_right'
|
||||
| 'set_qzone_profile'
|
||||
| 'share_group_ex'
|
||||
| 'share_peer'
|
||||
| 'test_download_stream'
|
||||
@@ -364,6 +368,7 @@ export const actionResults = {
|
||||
},
|
||||
],
|
||||
},
|
||||
get_qzone_profile: { name: 'Space', description: 'Description' },
|
||||
get_rkey_server: { expired_time: 1, name: 'SnowLuma', private_rkey: 'fixture' },
|
||||
get_share_link: 'https://example.com/share',
|
||||
like_qzone: null,
|
||||
@@ -385,6 +390,7 @@ export const actionResults = {
|
||||
set_group_robot_add_option: null,
|
||||
set_qzone_ban: null,
|
||||
set_qzone_msg_right: { ugc_right: 128 },
|
||||
set_qzone_profile: null,
|
||||
share_group_ex: '{}',
|
||||
share_peer: { arkMsg: '{}' },
|
||||
test_download_stream: {
|
||||
|
||||
+22
@@ -74,9 +74,11 @@ export const feedContent: string | null | undefined = feeds.feeds[0].content;
|
||||
export const feedPhotos: string[] | null | undefined = feeds.feeds[0].images;
|
||||
export const feedLikeCount: number | null | undefined = feeds.feeds[0].like_count;
|
||||
export const feedCursor: string | null | undefined = feeds.next_cursor;
|
||||
|
||||
if (feedCursor) {
|
||||
await http.raw('get_qzone_feeds', { cursor: feedCursor, count: 10 });
|
||||
}
|
||||
|
||||
export const legacyFeedsResult: ActionResult<'get_qzone_feeds'> = {
|
||||
feeds: [{ uin: 10002, nickname: 'User', time: 1, appid: 311, key: 'post', html: '' }],
|
||||
has_more: false,
|
||||
@@ -93,6 +95,26 @@ export const legacyQzoneComment: ActionParams<'comment_qzone'> = {
|
||||
images: ['https://example.com/image.png'],
|
||||
};
|
||||
export const legacyQzoneResult: ActionResult<'comment_qzone'> = { comment_id: '' };
|
||||
const qzoneProfile = await http.raw('get_qzone_profile', actionParams.get_qzone_profile);
|
||||
export const qzoneName: string = qzoneProfile.name;
|
||||
export const qzoneDescription: string = qzoneProfile.description;
|
||||
export const ownQzoneProfile = http.raw('get_qzone_profile', {});
|
||||
export const qzoneProfileUpdate: Promise<null> = ws.raw('set_qzone_profile', {
|
||||
name: 'Space',
|
||||
description: '',
|
||||
});
|
||||
export const qzoneNameOnly: ActionParams<'set_qzone_profile'> = { name: 'Space' };
|
||||
export const qzoneDescriptionOnly: ActionParams<'set_qzone_profile'> = { description: '' };
|
||||
export const qzoneScalarFields: ActionParams<'set_qzone_profile'> = {
|
||||
name: 123,
|
||||
description: false,
|
||||
};
|
||||
// @ts-expect-error a space profile patch requires at least one field
|
||||
export const emptyQzoneProfilePatch: ActionParams<'set_qzone_profile'> = {};
|
||||
export const invalidQzoneProfilePatch: ActionParams<'set_qzone_profile'> = {
|
||||
// @ts-expect-error profile fields accept string, number or boolean primitives
|
||||
description: [],
|
||||
};
|
||||
const speech = await ws.raw('get_record_text', { message_id: -42 });
|
||||
const transcription: string = speech.text;
|
||||
const flash = await http.raw('get_fileset_info', { fileset_id: 'files' });
|
||||
|
||||
@@ -1,13 +1,78 @@
|
||||
import { describe, expect, expectTypeOf, it, vi } from 'vitest';
|
||||
import type { QzoneMsgDetailResult } from '../src';
|
||||
import type { QzoneMsgDetailResult, QzoneProfileResult } from '../src';
|
||||
import {
|
||||
SnowLumaAbortError,
|
||||
SnowLumaApiError,
|
||||
SnowLumaAuthError,
|
||||
SnowLumaHttpClient,
|
||||
SnowLumaParseError,
|
||||
} from '../src';
|
||||
|
||||
describe('SnowLumaHttpClient', () => {
|
||||
it('reads typed space profiles for the current and an explicit account', async () => {
|
||||
const data: QzoneProfileResult = { name: 'Space', description: 'Description' };
|
||||
const fetchImpl = vi
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
async () => new Response(JSON.stringify({ status: 'ok', retcode: 0, data })),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
const own = await client.raw('get_qzone_profile', {});
|
||||
const other = await client.raw('get_qzone_profile', { target_uin: '10002' });
|
||||
|
||||
expectTypeOf(own).toEqualTypeOf<QzoneProfileResult>();
|
||||
expect(other).toEqual(data);
|
||||
expect(
|
||||
fetchImpl.mock.calls.map((call) => JSON.parse((call[1] as RequestInit).body as string)),
|
||||
).toEqual([
|
||||
{ action: 'get_qzone_profile', params: {} },
|
||||
{ action: 'get_qzone_profile', params: { target_uin: '10002' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('preserves omitted and empty space profile fields and returns null', async () => {
|
||||
const fetchImpl = vi
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
async () => new Response(JSON.stringify({ status: 'ok', retcode: 0, data: null })),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
const result = await client.raw('set_qzone_profile', { name: 'Space' });
|
||||
|
||||
expectTypeOf(result).toEqualTypeOf<null>();
|
||||
expect(result).toBeNull();
|
||||
await expect(client.raw('set_qzone_profile', { description: '' })).resolves.toBeNull();
|
||||
expect(
|
||||
fetchImpl.mock.calls.map((call) => JSON.parse((call[1] as RequestInit).body as string)),
|
||||
).toEqual([
|
||||
{ action: 'set_qzone_profile', params: { name: 'Space' } },
|
||||
{ action: 'set_qzone_profile', params: { description: '' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('propagates space profile update failures', async () => {
|
||||
const fetchImpl = vi.fn(
|
||||
async () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
status: 'failed',
|
||||
retcode: 1200,
|
||||
data: null,
|
||||
wording: 'Qzone requires verification',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
const request = client.raw('set_qzone_profile', { name: 'Space' });
|
||||
|
||||
await expect(request).rejects.toMatchObject({
|
||||
name: 'SnowLumaApiError',
|
||||
retcode: 1200,
|
||||
wording: 'Qzone requires verification',
|
||||
});
|
||||
await expect(request).rejects.toBeInstanceOf(SnowLumaApiError);
|
||||
});
|
||||
|
||||
it('reads a typed Qzone comment page through raw', async () => {
|
||||
const data: QzoneMsgDetailResult = {
|
||||
tid: 'T1',
|
||||
|
||||
Reference in new issue
Block a user