feat(qzone): add QQ space message deletion functionality (#1978)
- Add deleteQzoneMsg API method to NTQQWebApi for deleting Qzone posts by tid - Implement buildQzoneDeleteBody to construct form-encoded request payload - Implement parseQzoneDeleteResponse to validate deletion API response - Add QzoneDeleteResponse and QzoneDeleteParams type definitions - Create DeleteQzoneMsg OneBot action handler with payload validation - Register delete_qzone_msg action in router and action handlers - Add example payload and response for DeleteQzoneMsg action - Add comprehensive unit tests for delete body construction and response parsing - Fix indentation inconsistency in createAlbumCommentRequest call
This commit is contained in:
1 parent
288cc7c54f
commit
33546b936e
7 files changed
+121
-4
No files matched your search
@@ -14,11 +14,14 @@ import { basename } from 'node:path';
|
||||
import { qunAlbumControl } from '../data/webapi';
|
||||
import { createAlbumCommentRequest, createAlbumFeedPublish, createAlbumMediaFeed } from '../data/album';
|
||||
import {
|
||||
buildQzoneDeleteBody,
|
||||
buildQzonePublishBody,
|
||||
buildQzoneUploadImageBody,
|
||||
parseQzoneDeleteResponse,
|
||||
parseQzonePublishResponse,
|
||||
parseQzoneUploadImageResponseText,
|
||||
toQzoneRichval,
|
||||
QzoneDeleteResponse,
|
||||
QzonePublishResponse,
|
||||
} from '../data/qzone';
|
||||
export interface SetNoticeRetSuccess {
|
||||
@@ -487,10 +490,10 @@ export class NTQQWebApi {
|
||||
const client_key = Date.now() * 1000;
|
||||
return await this.context.session.getAlbumService().doQunComment(
|
||||
random_seq, {
|
||||
map_info: [],
|
||||
map_bytes_info: [],
|
||||
map_user_account: [],
|
||||
},
|
||||
map_info: [],
|
||||
map_bytes_info: [],
|
||||
map_user_account: [],
|
||||
},
|
||||
qunId,
|
||||
2,
|
||||
createAlbumMediaFeed(uin, albumId, lloc),
|
||||
@@ -605,6 +608,21 @@ export class NTQQWebApi {
|
||||
return parseQzonePublishResponse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除QQ空间说说
|
||||
* @param tid 说说Tid, 来自 publishQzoneMsg 的返回值
|
||||
*/
|
||||
async deleteQzoneMsg (tid: string) {
|
||||
const { uin, g_tk, cookie } = await this.getQzoneAuth();
|
||||
const body = buildQzoneDeleteBody({ hostuin: uin, tid });
|
||||
const api = `https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?g_tk=${g_tk}`;
|
||||
const result = await RequestUtil.HttpGetJson<QzoneDeleteResponse>(api, 'POST', body, {
|
||||
Cookie: cookie,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}, true, false);
|
||||
return parseQzoneDeleteResponse(result);
|
||||
}
|
||||
|
||||
async getDaySignedList (groupCode: string) {
|
||||
const pSkey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
|
||||
const selfUin = this.core.selfInfo.uin;
|
||||
|
||||
@@ -157,3 +157,43 @@ export function parseQzonePublishResponse (json: QzonePublishResponse): { tid: s
|
||||
}
|
||||
return { tid };
|
||||
}
|
||||
|
||||
export interface QzoneDeleteParams {
|
||||
hostuin: string;
|
||||
tid: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造删除说说的表单请求体 (application/x-www-form-urlencoded)
|
||||
* 对齐 https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6
|
||||
*/
|
||||
export function buildQzoneDeleteBody (params: QzoneDeleteParams): string {
|
||||
const { hostuin, tid } = params;
|
||||
const fields: Record<string, string> = {
|
||||
hostuin,
|
||||
tid,
|
||||
t1_source: '1',
|
||||
code_version: '1',
|
||||
format: 'json',
|
||||
qzreferrer: `https://user.qzone.qq.com/${hostuin}`,
|
||||
};
|
||||
return new URLSearchParams(fields).toString();
|
||||
}
|
||||
|
||||
export interface QzoneDeleteResponse {
|
||||
subcode?: number;
|
||||
code?: number;
|
||||
message?: string;
|
||||
msg?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析删除说说接口返回的 JSON
|
||||
*/
|
||||
export function parseQzoneDeleteResponse (json: QzoneDeleteResponse): { success: true; } {
|
||||
const subcode = json.subcode ?? json.code;
|
||||
if (subcode !== undefined && subcode !== 0) {
|
||||
throw new Error(json.message || json.msg || `QQ空间删说说失败, subcode=${subcode}`);
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
@@ -46,4 +46,8 @@ export const ExtendsActionsExamples = {
|
||||
payload: { content: '今天天气不错', images: [], ugc_right: 1, target_uins: [] },
|
||||
response: { tid: '1234567890abcdef1234567890' },
|
||||
},
|
||||
DeleteQzoneMsg: {
|
||||
payload: { tid: '1234567890abcdef1234567890' },
|
||||
response: null,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ExtendsActionsExamples } from '../example/ExtendsActionsExamples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
tid: Type.String({ description: '说说 tid (来自 get_qzone_msg_list / send_qzone_msg)' }),
|
||||
});
|
||||
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
export class DeleteQzoneMsg extends OneBotAction<PayloadType, void> {
|
||||
override actionName = ActionName.DeleteQzoneMsg;
|
||||
override actionSummary = '删除QQ空间说说';
|
||||
override actionDescription = '删除QQ空间(Qzone)的一条说说, 按 tid 删除';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ExtendsActionsExamples.DeleteQzoneMsg.payload;
|
||||
override returnExample = ExtendsActionsExamples.DeleteQzoneMsg.response;
|
||||
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
|
||||
async _handle (payload: PayloadType): Promise<void> {
|
||||
await this.core.apis.WebApi.deleteQzoneMsg(payload.tid);
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,7 @@ import { GetFilesetId } from './file/flash/GetFilesetIdByCode';
|
||||
import { FetchPttText } from '@/napcat-onebot/action/msg/FetchPttText';
|
||||
import { GetGroupSignedList } from './extends/GetGroupSignedList';
|
||||
import { SendQzoneMsg } from './extends/SendQzoneMsg';
|
||||
import { DeleteQzoneMsg } from './extends/DeleteQzoneMsg';
|
||||
|
||||
export function getAllHandlers (obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||
const actionHandlers = [
|
||||
@@ -218,6 +219,7 @@ export function getAllHandlers (obContext: NapCatOneBot11Adapter, core: NapCatCo
|
||||
new TransGroupFile(obContext, core),
|
||||
new GetGroupSignedList(obContext, core),
|
||||
new SendQzoneMsg(obContext, core),
|
||||
new DeleteQzoneMsg(obContext, core),
|
||||
// onebot11
|
||||
new SendLike(obContext, core),
|
||||
new GetMsg(obContext, core),
|
||||
|
||||
@@ -217,4 +217,5 @@ export const ActionName = {
|
||||
|
||||
// QQ 空间扩展
|
||||
SendQzoneMsg: 'send_qzone_msg',
|
||||
DeleteQzoneMsg: 'delete_qzone_msg',
|
||||
} as const;
|
||||
@@ -1,7 +1,9 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
buildQzoneDeleteBody,
|
||||
buildQzonePublishBody,
|
||||
buildQzoneUploadImageBody,
|
||||
parseQzoneDeleteResponse,
|
||||
parseQzonePublishResponse,
|
||||
parseQzoneUploadImageResponseText,
|
||||
toQzoneRichval,
|
||||
@@ -91,4 +93,28 @@ describe('Qzone data helpers', () => {
|
||||
test('parseQzonePublishResponse throws when tid missing', () => {
|
||||
expect(() => parseQzonePublishResponse({ subcode: 0 })).toThrow();
|
||||
});
|
||||
|
||||
test('buildQzoneDeleteBody encodes required fields', () => {
|
||||
const body = buildQzoneDeleteBody({ hostuin: '123456', tid: 'tid123' });
|
||||
const params = new URLSearchParams(body);
|
||||
expect(params.get('hostuin')).toBe('123456');
|
||||
expect(params.get('tid')).toBe('tid123');
|
||||
expect(params.get('t1_source')).toBe('1');
|
||||
expect(params.get('code_version')).toBe('1');
|
||||
expect(params.get('format')).toBe('json');
|
||||
expect(params.get('qzreferrer')).toContain('123456');
|
||||
});
|
||||
|
||||
test('parseQzoneDeleteResponse succeeds when subcode is 0', () => {
|
||||
const result = parseQzoneDeleteResponse({ subcode: 0 });
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
test('parseQzoneDeleteResponse throws when subcode indicates failure', () => {
|
||||
expect(() => parseQzoneDeleteResponse({ subcode: -200, message: '权限不足' })).toThrow('权限不足');
|
||||
});
|
||||
|
||||
test('parseQzoneDeleteResponse throws with default message when subcode indicates failure without message', () => {
|
||||
expect(() => parseQzoneDeleteResponse({ subcode: -200 })).toThrow('subcode=-200');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user