NapCatQQ/src/onebot/action/msg/DeleteMsg.ts
2024-11-19 12:49:51 +08:00

36 lines
987 B
TypeScript

import { ActionName } from '../types';
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/message-unique';
const SchemaData = {
type: 'object',
properties: {
message_id: {
oneOf: [
{ type: 'number' },
{ type: 'string' },
],
},
},
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
class DeleteMsg extends OneBotAction<Payload, void> {
actionName = ActionName.DeleteMsg;
payloadSchema = SchemaData;
async _handle(payload: Payload) {
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
if (msg) {
await this.core.apis.MsgApi.recallMsg(msg.Peer, msg.MsgId);
} else {
throw new Error('Recall failed');
}
}
}
export default DeleteMsg;