mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 15:11:15 +00:00
Refactored all Satori action classes to use TypeBox schemas for payload validation and unified action naming via a new router. Added schema-based parameter checking to the SatoriAction base class. Introduced new actions for guild and member approval, and login retrieval. Centralized action name constants and types in a new router module. Enhanced event and message APIs with more structured event types and parsing logic. Added helper utilities for XML parsing. Updated exports and registration logic to support the new structure.
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { Static, Type } from '@sinclair/typebox';
|
|
import { SatoriAction } from '../SatoriAction';
|
|
import { SatoriActionName } from '../router';
|
|
import { SatoriMessage, SatoriChannelType } from '../../types';
|
|
import { ChatType } from 'napcat-core';
|
|
|
|
const SchemaData = Type.Object({
|
|
channel_id: Type.String(),
|
|
message_id: Type.String(),
|
|
});
|
|
|
|
type Payload = Static<typeof SchemaData>;
|
|
|
|
export class MessageGetAction extends SatoriAction<Payload, SatoriMessage> {
|
|
actionName = SatoriActionName.MessageGet;
|
|
override payloadSchema = SchemaData;
|
|
|
|
protected async _handle (payload: Payload): Promise<SatoriMessage> {
|
|
const { channel_id, message_id } = payload;
|
|
|
|
const parts = channel_id.split(':');
|
|
const type = parts[0];
|
|
const id = parts[1];
|
|
|
|
if (!type || !id) {
|
|
throw new Error(`无效的频道ID: ${channel_id}`);
|
|
}
|
|
|
|
let chatType: ChatType;
|
|
let peerUid: string;
|
|
|
|
if (type === 'private') {
|
|
chatType = ChatType.KCHATTYPEC2C;
|
|
peerUid = await this.core.apis.UserApi.getUidByUinV2(id);
|
|
} else if (type === 'group') {
|
|
chatType = ChatType.KCHATTYPEGROUP;
|
|
peerUid = id;
|
|
} else {
|
|
throw new Error(`不支持的频道类型: ${type}`);
|
|
}
|
|
|
|
const peer = { chatType, peerUid, guildId: '' };
|
|
const msgs = await this.core.apis.MsgApi.getMsgsByMsgId(peer, [message_id]);
|
|
|
|
if (!msgs || msgs.msgList.length === 0) {
|
|
throw new Error('消息不存在');
|
|
}
|
|
|
|
const msg = msgs.msgList[0];
|
|
if (!msg) {
|
|
throw new Error('消息不存在');
|
|
}
|
|
|
|
const content = await this.satoriAdapter.apis.MsgApi.parseElements(msg.elements);
|
|
|
|
const message: SatoriMessage = {
|
|
id: msg.msgId,
|
|
content,
|
|
channel: {
|
|
id: channel_id,
|
|
type: type === 'private' ? SatoriChannelType.DIRECT : SatoriChannelType.TEXT,
|
|
},
|
|
user: {
|
|
id: msg.senderUin,
|
|
name: msg.sendNickName,
|
|
},
|
|
created_at: parseInt(msg.msgTime) * 1000,
|
|
};
|
|
|
|
return message;
|
|
}
|
|
}
|