From 3dc9940ac9a5a833b78e513c49d8e24412e77f6e Mon Sep 17 00:00:00 2001 From: idranme Date: Mon, 23 Sep 2024 23:34:52 +0800 Subject: [PATCH] feat --- src/ntqqapi/api/group.ts | 2 +- .../action/go-cqhttp/GetGroupFilesByFolder.ts | 32 ++++++++++++------- .../action/go-cqhttp/GetGroupRootFiles.ts | 30 ++++++++++------- src/onebot11/entities.ts | 22 +++++-------- 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index d11fbef..427d5a7 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -293,7 +293,7 @@ export class NTQQGroupApi extends Service { cmdCB: (payload, result) => payload.fileInfo.reqId === result } ) - return data.fileInfo.item + return data.fileInfo } async publishGroupBulletin(groupCode: string, req: PublishGroupBulletinReq) { diff --git a/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts b/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts index c3ee992..a9ca570 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts @@ -1,11 +1,11 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { OB11GroupFile, OB11GroupFileFolder } from '@/onebot11/types' +import { OnGroupFileInfoUpdateParams } from '@/ntqqapi/types' interface Payload { - group_id: string | number + group_id: number | string folder_id: string - file_count: string | number } interface Response { @@ -17,19 +17,27 @@ export class GetGroupFilesByFolder extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder payloadSchema = Schema.object({ group_id: Schema.union([Number, String]).required(), - folder_id: Schema.string().required(), - file_count: Schema.union([Number, String]).default(50) + folder_id: Schema.string().required() }) async _handle(payload: Payload) { - const data = await this.ctx.ntGroupApi.getGroupFileList(payload.group_id.toString(), { - sortType: 1, - fileCount: +payload.file_count, - startIndex: 0, - sortOrder: 2, - showOnlinedocFolder: 0, - folderId: payload.folder_id - }) + const groupId = payload.group_id.toString() + const data: OnGroupFileInfoUpdateParams['item'] = [] + + let nextIndex: number | undefined + while (nextIndex !== 0) { + const res = await this.ctx.ntGroupApi.getGroupFileList(groupId, { + sortType: 1, + fileCount: 100, + startIndex: nextIndex ?? 0, + sortOrder: 2, + showOnlinedocFolder: 0, + folderId: payload.folder_id + }) + data.push(...res.item) + nextIndex = res.nextIndex + } + return { files: data.filter(item => item.fileInfo) .map(item => { diff --git a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts index ab3e5bf..f3d4788 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts @@ -1,10 +1,10 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { OB11GroupFile, OB11GroupFileFolder } from '../../types' +import { OnGroupFileInfoUpdateParams } from '@/ntqqapi/types' interface Payload { - group_id: string | number - file_count: string | number + group_id: number | string } interface Response { @@ -15,18 +15,26 @@ interface Response { export class GetGroupRootFiles extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupRootFiles payloadSchema = Schema.object({ - group_id: Schema.union([Number, String]).required(), - file_count: Schema.union([Number, String]).default(50), + group_id: Schema.union([Number, String]).required() }) async _handle(payload: Payload) { - const data = await this.ctx.ntGroupApi.getGroupFileList(payload.group_id.toString(), { - sortType: 1, - fileCount: +payload.file_count, - startIndex: 0, - sortOrder: 2, - showOnlinedocFolder: 0, - }) + const groupId = payload.group_id.toString() + const data: OnGroupFileInfoUpdateParams['item'] = [] + + let nextIndex: number | undefined + while (nextIndex !== 0) { + const res = await this.ctx.ntGroupApi.getGroupFileList(groupId, { + sortType: 1, + fileCount: 100, + startIndex: nextIndex ?? 0, + sortOrder: 2, + showOnlinedocFolder: 0, + }) + data.push(...res.item) + nextIndex = res.nextIndex + } + return { files: data.filter(item => item.fileInfo) .map(item => { diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index a89e8b8..303222b 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -109,25 +109,19 @@ export namespace OB11Entities { let name: string | undefined if (element.textElement.atType == AtType.atAll) { qq = 'all' - } - else { - const { atNtUid, content } = element.textElement - let atQQ = element.textElement.atUid - if (!atQQ || atQQ === '0') { - const atMember = await ctx.ntGroupApi.getGroupMember(msg.peerUin, atNtUid) - if (atMember) { - atQQ = atMember.uin - } - } - if (atQQ) { - qq = atQQ - name = content.replace('@', '') + } else { + const { atNtUid, atUid, content } = element.textElement + if (atUid && atUid !== '0') { + qq = atUid + } else { + qq = await ctx.ntUserApi.getUinByUid(atNtUid) } + name = content.replace('@', '') } messageSegment = { type: OB11MessageDataType.at, data: { - qq: qq!, + qq, name } }