mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-20 05:30:06 +08:00
feat: 向 /get_system_msg 添加可选参数 'count' (#1113)
* 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: 手瓜一十雪 <nanaeonn@outlook.com>
This commit is contained in:
parent
0c0b27901a
commit
cf03ad8fd9
@ -2,6 +2,7 @@ import { GroupNotifyMsgStatus } from '@/core';
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { Notify } from '@/onebot/types';
|
import { Notify } from '@/onebot/types';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface RetData {
|
interface RetData {
|
||||||
invited_requests: Notify[];
|
invited_requests: Notify[];
|
||||||
@ -9,11 +10,18 @@ interface RetData {
|
|||||||
join_requests: Notify[];
|
join_requests: Notify[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
const SchemaData = Type.Object({
|
||||||
override actionName = ActionName.GetGroupSystemMsg;
|
count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
|
||||||
|
});
|
||||||
|
|
||||||
async _handle(): Promise<RetData> {
|
type Payload = Static<typeof SchemaData>;
|
||||||
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50);
|
|
||||||
|
export class GetGroupSystemMsg extends OneBotAction<Payload, RetData> {
|
||||||
|
override actionName = ActionName.GetGroupSystemMsg;
|
||||||
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(params: Payload): Promise<RetData> {
|
||||||
|
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, +params.count);
|
||||||
const retData: RetData = { invited_requests: [], InvitedRequest: [], join_requests: [] };
|
const retData: RetData = { invited_requests: [], InvitedRequest: [], join_requests: [] };
|
||||||
|
|
||||||
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
||||||
@ -43,4 +51,4 @@ export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
|||||||
retData.invited_requests = retData.InvitedRequest;
|
retData.invited_requests = retData.InvitedRequest;
|
||||||
return retData;
|
return retData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user