style: 强类型大法

This commit is contained in:
手瓜一十雪
2025-02-02 23:22:21 +08:00
parent ac193cc94a
commit 15854c605b
191 changed files with 923 additions and 806 deletions

View File

@@ -15,11 +15,10 @@ const SchemaData = Type.Object({
type Payload = Static<typeof SchemaData>;
class GetMsg extends OneBotAction<Payload, OB11Message> {
actionName = ActionName.GetMsg;
payloadSchema = SchemaData;
override actionName = ActionName.GetMsg;
override payloadSchema = SchemaData;
async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig) {
// log("history msg ids", Object.keys(msgHistory));
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
if (!payload.message_id) {
throw Error('参数message_id不能为空');
}
@@ -30,19 +29,20 @@ class GetMsg extends OneBotAction<Payload, OB11Message> {
}
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
const orimsg = this.obContext.recallMsgCache.get(msgIdWithPeer.MsgId);
let msg: RawMessage;
let msg: RawMessage|undefined;
if (orimsg) {
msg = orimsg;
} else {
msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0];
}
if (!msg) throw Error('消息不存在');
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat);
if (!retMsg) throw Error('消息为空');
try {
retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgId)!;
retMsg.message_seq = retMsg.message_id;
retMsg.real_id = retMsg.message_id;
} catch (e) {
} catch {
// ignored
}
return retMsg;