|
| 1 | +import { MessageUnique } from 'napcat-common/src/message-unique'; |
| 2 | +import { ChatType, Peer } from 'napcat-core'; |
| 3 | +import { Static, Type } from '@sinclair/typebox'; |
| 4 | +import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus'; |
| 5 | + |
| 6 | +export const GroupTodoPayloadSchema = Type.Object({ |
| 7 | + group_id: Type.Union([Type.String(), Type.Number()], { description: '群号' }), |
| 8 | + message_id: Type.Optional(Type.String({ description: '消息ID' })), |
| 9 | + message_seq: Type.Optional(Type.String({ description: '消息Seq (可选)' })), |
| 10 | +}); |
| 11 | + |
| 12 | +export type GroupTodoPayload = Static<typeof GroupTodoPayloadSchema>; |
| 13 | + |
| 14 | +export abstract class BaseGroupTodoAction extends GetPacketStatusDepends<GroupTodoPayload, void> { |
| 15 | + override payloadSchema = GroupTodoPayloadSchema; |
| 16 | + override returnSchema = Type.Null(); |
| 17 | + override actionTags = ['核心接口']; |
| 18 | + |
| 19 | + protected abstract handleGroupTodo(groupId: number, msgSeq: string): Promise<void>; |
| 20 | + |
| 21 | + async _handle (payload: GroupTodoPayload) { |
| 22 | + const groupId = +payload.group_id; |
| 23 | + if (payload.message_seq) { |
| 24 | + return await this.handleGroupTodo(groupId, payload.message_seq.toString()); |
| 25 | + } |
| 26 | + if (!payload.message_id) { |
| 27 | + throw new Error('缺少参数 message_id 或 message_seq'); |
| 28 | + } |
| 29 | + const peer: Peer = { |
| 30 | + chatType: ChatType.KCHATTYPEGROUP, |
| 31 | + peerUid: payload.group_id.toString(), |
| 32 | + }; |
| 33 | + const { MsgId, Peer } = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) ?? { Peer: peer, MsgId: payload.message_id.toString() }; |
| 34 | + const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(Peer, [MsgId])).msgList[0]; |
| 35 | + if (!msg) { |
| 36 | + throw new Error('消息不存在'); |
| 37 | + } |
| 38 | + await this.handleGroupTodo(groupId, msg.msgSeq); |
| 39 | + } |
| 40 | +} |
0 commit comments