mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: emitRecallMsg
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
|||||||
RawMessage,
|
RawMessage,
|
||||||
SendStatusType,
|
SendStatusType,
|
||||||
NTMsgType,
|
NTMsgType,
|
||||||
|
MessageElement,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { OB11ConfigLoader } from '@/onebot/config';
|
import { OB11ConfigLoader } from '@/onebot/config';
|
||||||
import {
|
import {
|
||||||
@@ -277,8 +278,11 @@ export class NapCatOneBot11Adapter {
|
|||||||
peerUid: uid,
|
peerUid: uid,
|
||||||
guildId: ''
|
guildId: ''
|
||||||
};
|
};
|
||||||
let msg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, msgSeq)).msgList;
|
let msg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, msgSeq)).msgList.find(e => e.msgType == NTMsgType.KMSGTYPEGRAYTIPS);
|
||||||
console.log(JSON.stringify(msg));
|
let element = msg?.elements[0];
|
||||||
|
if (msg && element) {
|
||||||
|
await this.emitRecallMsg(msg, element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msgListener.onMsgInfoListUpdate = async (msgList) => {
|
msgListener.onMsgInfoListUpdate = async (msgList) => {
|
||||||
for (const msg of msgList.filter((e) => e.senderUin == this.core.selfInfo.uin)) {
|
for (const msg of msgList.filter((e) => e.senderUin == this.core.selfInfo.uin)) {
|
||||||
@@ -645,37 +649,33 @@ export class NapCatOneBot11Adapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async emitRecallMsg(msgList: RawMessage[], cache: LRUCache<string, boolean>) {
|
private async emitRecallMsg(message: RawMessage, element: MessageElement) {
|
||||||
for (const message of msgList) {
|
|
||||||
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
|
||||||
const peer: Peer = { chatType: message.chatType, peerUid: message.peerUid, guildId: '' };
|
const peer: Peer = { chatType: message.chatType, peerUid: message.peerUid, guildId: '' };
|
||||||
if (message.recallTime != '0' && !cache.get(message.msgId)) {
|
let oriMessageId = MessageUnique.getShortIdByMsgId(message.msgId) ?? MessageUnique.createUniqueMsgId(peer, message.msgId);
|
||||||
//TODO: 这个判断方法不太好,应该使用灰色消息元素来判断?
|
|
||||||
cache.put(message.msgId, true);
|
|
||||||
// 撤回消息上报
|
|
||||||
let oriMessageId = MessageUnique.getShortIdByMsgId(message.msgId);
|
|
||||||
if (!oriMessageId) {
|
|
||||||
oriMessageId = MessageUnique.createUniqueMsgId(peer, message.msgId);
|
|
||||||
}
|
|
||||||
if (message.chatType == ChatType.KCHATTYPEC2C) {
|
if (message.chatType == ChatType.KCHATTYPEC2C) {
|
||||||
|
await this.emitFriendRecallMsg(message, oriMessageId, element);
|
||||||
|
} else if (message.chatType == ChatType.KCHATTYPEGROUP) {
|
||||||
|
await this.emitGroupRecallMsg(message, oriMessageId, element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async emitFriendRecallMsg(message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||||
const friendRecallEvent = new OB11FriendRecallNoticeEvent(
|
const friendRecallEvent = new OB11FriendRecallNoticeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
+message.senderUin,
|
+message.senderUin,
|
||||||
oriMessageId
|
oriMessageId
|
||||||
);
|
);
|
||||||
this.networkManager
|
try {
|
||||||
.emitEvent(friendRecallEvent)
|
await this.networkManager.emitEvent(friendRecallEvent);
|
||||||
.catch((e) =>
|
} catch (e) {
|
||||||
this.context.logger.logError.bind(this.context.logger)('处理好友消息撤回失败', e)
|
this.context.logger.logError('处理好友消息撤回失败', e);
|
||||||
);
|
}
|
||||||
} else if (message.chatType == ChatType.KCHATTYPEGROUP) {
|
}
|
||||||
let operatorId = message.senderUin;
|
|
||||||
for (const element of message.elements) {
|
private async emitGroupRecallMsg(message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid;
|
const operatorUid = element.grayTipElement?.revokeElement.operatorUid;
|
||||||
if (!operatorUid) return;
|
if (!operatorUid) return;
|
||||||
const operator = await this.core.apis.GroupApi.getGroupMember(message.peerUin, operatorUid);
|
let operatorId = message.senderUin ?? await this.core.apis.UserApi.getUinByUidV2(operatorUid);
|
||||||
operatorId = operator?.uin ?? message.senderUin;
|
|
||||||
}
|
|
||||||
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
+message.peerUin,
|
+message.peerUin,
|
||||||
@@ -683,13 +683,13 @@ export class NapCatOneBot11Adapter {
|
|||||||
+operatorId,
|
+operatorId,
|
||||||
oriMessageId
|
oriMessageId
|
||||||
);
|
);
|
||||||
this.networkManager
|
try {
|
||||||
.emitEvent(groupRecallEvent)
|
await this.networkManager.emitEvent(groupRecallEvent);
|
||||||
.catch((e) => this.context.logger.logError.bind(this.context.logger)('处理群消息撤回失败', e));
|
} catch (e) {
|
||||||
}
|
this.context.logger.logError('处理群消息撤回失败', e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
Reference in New Issue
Block a user