From 364dfe8b93c8b226150b739a40fb03d36569919b Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:31:14 +0800 Subject: [PATCH] feat: `get_group_file_system_info` API --- src/ntqqapi/api/group.ts | 14 ++++++++ .../services/NodeIKernelRichMediaService.ts | 16 ++++++++++ .../go-cqhttp/GetGroupFileSystemInfo.ts | 32 +++++++++++++++++++ src/onebot11/action/index.ts | 2 ++ src/onebot11/action/types.ts | 1 + 5 files changed, 65 insertions(+) create mode 100644 src/onebot11/action/go-cqhttp/GetGroupFileSystemInfo.ts diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index c4cd7e5..cae330a 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -325,4 +325,18 @@ export class NTQQGroupApi extends Service { ) return data.infos } + + async getGroupFileCount(groupId: string) { + return await invoke( + 'nodeIKernelRichMediaService/batchGetGroupFileCount', + [{ groupIds: [groupId] }] + ) + } + + async getGroupFileSpace(groupId: string) { + return await invoke( + 'nodeIKernelRichMediaService/getGroupSpace', + [{ groupId }] + ) + } } diff --git a/src/ntqqapi/services/NodeIKernelRichMediaService.ts b/src/ntqqapi/services/NodeIKernelRichMediaService.ts index e11a4a6..4f58c60 100644 --- a/src/ntqqapi/services/NodeIKernelRichMediaService.ts +++ b/src/ntqqapi/services/NodeIKernelRichMediaService.ts @@ -39,5 +39,21 @@ export interface NodeIKernelRichMediaService { failFileIdList: Array } }> + + batchGetGroupFileCount(groupIds: string[]): Promise + + getGroupSpace(groupId: string): Promise } diff --git a/src/onebot11/action/go-cqhttp/GetGroupFileSystemInfo.ts b/src/onebot11/action/go-cqhttp/GetGroupFileSystemInfo.ts new file mode 100644 index 0000000..524abf8 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetGroupFileSystemInfo.ts @@ -0,0 +1,32 @@ +import { BaseAction, Schema } from '../BaseAction' +import { ActionName } from '../types' + +interface Payload { + group_id: number | string +} + +interface Response { + file_count: number + limit_count: number + used_space: number + total_space: number +} + +export class GetGroupFileSystemInfo extends BaseAction { + actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required() + }) + + async _handle(payload: Payload) { + const groupId = payload.group_id.toString() + const { groupFileCounts } = await this.ctx.ntGroupApi.getGroupFileCount(groupId) + const { groupSpaceResult } = await this.ctx.ntGroupApi.getGroupFileSpace(groupId) + return { + file_count: groupFileCounts[0], + limit_count: 10000, + used_space: +groupSpaceResult.usedSpace, + total_space: +groupSpaceResult.totalSpace, + } + } +} diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index b70f836..8d46873 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -76,6 +76,7 @@ import { DeleteFriend } from './go-cqhttp/DeleteFriend' import { OCRImage } from './go-cqhttp/OCRImage' import { GroupPoke } from './llonebot/GroupPoke' import { FriendPoke } from './llonebot/FriendPoke' +import { GetGroupFileSystemInfo } from './go-cqhttp/GetGroupFileSystemInfo' export function initActionMap(adapter: Adapter) { const actionHandlers = [ @@ -157,6 +158,7 @@ export function initActionMap(adapter: Adapter) { new GetGroupNotice(adapter), new DeleteFriend(adapter), new OCRImage(adapter), + new GetGroupFileSystemInfo(adapter), ] const actionMap = new Map>() for (const action of actionHandlers) { diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index a237492..f419f28 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -89,4 +89,5 @@ export enum ActionName { GoCQHTTP_GetGroupNotice = '_get_group_notice', GoCQHTTP_DeleteFriend = 'delete_friend', GoCQHTTP_OCRImage = 'ocr_image', + GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info', }