mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 23:19:37 +00:00
Introduced explicit payloadSchema and returnSchema definitions for all OneBotAction classes using @sinclair/typebox. This improves type safety, API documentation, and validation for action payloads and return values. Also refactored method signatures and types for consistency across the codebase.
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { PacketBuf } from 'napcat-core/packet/transformer/base';
|
|
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { ProtoBuf, ProtoBufBase, PBUint32, PBString } from 'napcat.protobuf';
|
|
import { Type, Static } from '@sinclair/typebox';
|
|
|
|
const ReturnSchema = Type.Array(
|
|
Type.Object({
|
|
uin: Type.Number({ description: 'QQ号' }),
|
|
uid: Type.String({ description: '用户UID' }),
|
|
nick_name: Type.String({ description: '昵称' }),
|
|
age: Type.Number({ description: '年龄' }),
|
|
source: Type.String({ description: '来源' }),
|
|
}),
|
|
{ description: '单向好友列表' }
|
|
);
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
export class GetUnidirectionalFriendList extends OneBotAction<void, ReturnType> {
|
|
override actionName = ActionName.GetUnidirectionalFriendList;
|
|
override payloadSchema = Type.Void();
|
|
override returnSchema = ReturnSchema;
|
|
|
|
async pack_data (data: string): Promise<Uint8Array> {
|
|
return ProtoBuf(class extends ProtoBufBase {
|
|
type = PBUint32(2, false, 0);
|
|
data = PBString(3, false, data);
|
|
}).encode();
|
|
}
|
|
|
|
async _handle (): Promise<ReturnType> {
|
|
const self_id = this.core.selfInfo.uin;
|
|
const req_json = {
|
|
uint64_uin: self_id,
|
|
uint64_top: 0,
|
|
uint32_req_num: 99,
|
|
bytes_cookies: '',
|
|
};
|
|
const packed_data = await this.pack_data(JSON.stringify(req_json));
|
|
const data = Buffer.from(packed_data);
|
|
const rsq = { cmd: 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0', data: data as PacketBuf };
|
|
const rsp_data = await this.core.apis.PacketApi.pkt.operation.sendPacket(rsq, true);
|
|
const block_json = ProtoBuf(class extends ProtoBufBase { data = PBString(4); }).decode(rsp_data);
|
|
const block_list: any[] = JSON.parse(block_json.data).rpt_block_list;
|
|
|
|
return block_list.map((block) => ({
|
|
uin: block.uint64_uin,
|
|
uid: block.str_uid,
|
|
nick_name: Buffer.from(block.bytes_nick, 'base64').toString(),
|
|
age: block.uint32_age,
|
|
source: Buffer.from(block.bytes_source, 'base64').toString(),
|
|
}));
|
|
}
|
|
}
|