Refactor type handling and improve message parsing

Updated several actions to use more precise type casting and type guards, improving type safety and clarity. Enhanced message parsing logic for forward messages and group/friend message history. Standardized return schemas and error handling for avatar and group portrait actions.
This commit is contained in:
手瓜一十雪
2026-01-25 16:32:36 +08:00
parent e562a57713
commit 20398af648
10 changed files with 67 additions and 38 deletions

View File

@@ -13,8 +13,8 @@ const PayloadSchema = Type.Object({
type PayloadType = Static<typeof PayloadSchema>;
const ReturnSchema = Type.Object({
files: Type.Array(Type.Any(), { description: '文件列表' }),
folders: Type.Array(Type.Any(), { description: '文件夹列表' }),
files: Type.Array(Type.Unknown(), { description: '文件列表' }),
folders: Type.Array(Type.Unknown(), { description: '文件夹列表' }),
}, { description: '群文件夹文件列表' });
type ReturnType = Static<typeof ReturnSchema>;
@@ -23,19 +23,20 @@ export class GetGroupFilesByFolder extends OneBotAction<PayloadType, ReturnType>
override actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
override payloadSchema = PayloadSchema;
override returnSchema = ReturnSchema;
async _handle (payload: PayloadType) {
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
async _handle (payload: PayloadType): Promise<ReturnType> {
const retRaw = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
sortType: 1,
fileCount: +payload.file_count,
startIndex: 0,
sortOrder: 2,
showOnlinedocFolder: 0,
folderId: payload.folder ?? payload.folder_id ?? '',
}).catch(() => []);
});
const ret = Array.isArray(retRaw) ? retRaw : [];
return {
files: ret.filter(item => item.fileInfo)
.map(item => OB11Construct.file(item.peerId, item.fileInfo!)),
folders: [] as [],
folders: [],
};
}
}