mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 07:01:16 +00:00
Introduces the actionSummary property to OneBotAction and updates all action classes to provide concise summaries and improved descriptions. Refactors example imports for better modularity, adds new example files for guild and packet actions, and updates the OpenAPI schema generator to use the new summary and improved descriptions. This enhances API documentation clarity and consistency.
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { OB11Construct } from '@/napcat-onebot/helper/data';
|
|
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { OB11UserSchema } from '../schemas';
|
|
|
|
import { ActionExamples } from '../examples';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()], { description: '是否不使用缓存' })),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = Type.Array(OB11UserSchema, { description: '好友列表' });
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
export default class GetFriendList extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionName = ActionName.GetFriendList;
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionSummary = '获取好友列表';
|
|
override actionDescription = '获取当前帐号的好友列表';
|
|
override actionTags = ['用户接口'];
|
|
override payloadExample = ActionExamples.GetFriendList.payload;
|
|
override returnExample = ActionExamples.GetFriendList.return;
|
|
|
|
async _handle (_payload: PayloadType) {
|
|
const buddyMap = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
|
|
const isNocache = typeof _payload.no_cache === 'string' ? _payload.no_cache === 'true' : !!_payload.no_cache;
|
|
await Promise.all(
|
|
Array.from(buddyMap.values()).map(async (buddyInfo) => {
|
|
try {
|
|
const userDetail = await this.core.apis.UserApi.getUserDetailInfo(buddyInfo.coreInfo.uid, isNocache);
|
|
const data = buddyMap.get(buddyInfo.coreInfo.uid);
|
|
if (data) {
|
|
data.qqLevel = userDetail.qqLevel;
|
|
}
|
|
} catch (error) {
|
|
this.core.context.logger.logError('获取好友详细信息失败', error);
|
|
}
|
|
})
|
|
);
|
|
return OB11Construct.friends(Array.from(buddyMap.values()));
|
|
}
|
|
}
|