From cf03ad8fd951bf6a92ff6c7b87de5348f6ff4ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9B=A7=E5=9B=A7JOJO?= <58727904+jiongjiongJOJO@users.noreply.github.com> Date: Mon, 7 Jul 2025 20:46:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=91=20/get=5Fsystem=5Fmsg=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E9=80=89=E5=8F=82=E6=95=B0=20'count?= =?UTF-8?q?'=20(#1113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add the optional parameter "count" to /get_system_msg * Refactor GetGroupSystemMsg to use TypeBox schema Introduced TypeBox for payload validation in GetGroupSystemMsg, replacing manual count handling with a schema-based approach. Updated the handler to use the new payload type and schema, improving type safety and input validation. --------- Co-authored-by: 手瓜一十雪 --- src/onebot/action/system/GetSystemMsg.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/onebot/action/system/GetSystemMsg.ts b/src/onebot/action/system/GetSystemMsg.ts index 6ea757b0..af712813 100644 --- a/src/onebot/action/system/GetSystemMsg.ts +++ b/src/onebot/action/system/GetSystemMsg.ts @@ -2,6 +2,7 @@ import { GroupNotifyMsgStatus } from '@/core'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Notify } from '@/onebot/types'; +import { Static, Type } from '@sinclair/typebox'; interface RetData { invited_requests: Notify[]; @@ -9,11 +10,18 @@ interface RetData { join_requests: Notify[]; } -export class GetGroupSystemMsg extends OneBotAction { - override actionName = ActionName.GetGroupSystemMsg; +const SchemaData = Type.Object({ + count: Type.Union([Type.Number(), Type.String()], { default: 50 }), +}); - async _handle(): Promise { - const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50); +type Payload = Static; + +export class GetGroupSystemMsg extends OneBotAction { + override actionName = ActionName.GetGroupSystemMsg; + override payloadSchema = SchemaData; + + async _handle(params: Payload): Promise { + const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, +params.count); const retData: RetData = { invited_requests: [], InvitedRequest: [], join_requests: [] }; const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => { @@ -43,4 +51,4 @@ export class GetGroupSystemMsg extends OneBotAction { retData.invited_requests = retData.InvitedRequest; return retData; } -} \ No newline at end of file +}