NapCatQQ/packages/napcat-onebot/action/packet/SetGroupTodo.ts
手瓜一十雪 b69352f6a1 Add payload and return schemas to OneBot actions
Introduced explicit payloadSchema and returnSchema definitions for all OneBotAction classes using @sinclair/typebox. This improves type safety, API documentation, and validation for action payloads and return values. Also refactored method signatures and types for consistency across the codebase.
2026-01-25 14:50:58 +08:00

32 lines
1.6 KiB
TypeScript

import { MessageUnique } from 'napcat-common/src/message-unique';
import { ChatType, Peer } from 'napcat-core';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
import { ActionName } from '../router';
export const SetGroupTodoPayloadSchema = Type.Object({
group_id: Type.Union([Type.String(), Type.Number()], { description: '群号' }),
message_id: Type.Union([Type.String(), Type.Number()], { description: '消息ID' }),
message_seq: Type.Optional(Type.Union([Type.String(), Type.Number()], { description: '消息Seq (可选)' })),
});
export type SetGroupTodoPayload = Static<typeof SetGroupTodoPayloadSchema>;
export class SetGroupTodo extends GetPacketStatusDepends<SetGroupTodoPayload, void> {
override payloadSchema = SetGroupTodoPayloadSchema;
override returnSchema = Type.Null();
override actionName = ActionName.SetGroupTodo;
async _handle (payload: SetGroupTodoPayload) {
if (payload.message_seq) {
return await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, payload.message_seq.toString());
}
const peer: Peer = {
chatType: ChatType.KCHATTYPEGROUP,
peerUid: payload.group_id.toString(),
};
const { MsgId, Peer } = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) ?? { Peer: peer, MsgId: payload.message_id.toString() };
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(Peer, [MsgId])).msgList[0];
if (!msg) throw new Error('消息不存在');
await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, msg.msgSeq);
}
}