mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|
import { ActionName } from '@/onebot/action/router';
|
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
import { MessageUnique } from '@/common/message-unique';
|
|
|
|
const SchemaData = {
|
|
type: 'object',
|
|
properties: {
|
|
message_id: { type: ['number', 'string'] },
|
|
},
|
|
required: ['message_id'],
|
|
} as const satisfies JSONSchema;
|
|
|
|
type Payload = FromSchema<typeof SchemaData>;
|
|
|
|
export default class DelEssenceMsg extends OneBotAction<Payload, any> {
|
|
actionName = ActionName.DelEssenceMsg;
|
|
payloadSchema = SchemaData;
|
|
|
|
async _handle(payload: Payload): Promise<any> {
|
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
|
if (!msg) {
|
|
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
|
|
if(!data) throw new Error('消息不存在');
|
|
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string };
|
|
return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random);
|
|
}
|
|
return await this.core.apis.GroupApi.removeGroupEssence(
|
|
msg.Peer.peerUid,
|
|
msg.MsgId,
|
|
);
|
|
}
|
|
}
|