mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: getMsg
This commit is contained in:
parent
d8e1547736
commit
cd74687b7b
@ -5,6 +5,7 @@ export class Native {
|
|||||||
platform: string;
|
platform: string;
|
||||||
supportedPlatforms = ['win32'];
|
supportedPlatforms = ['win32'];
|
||||||
MoeHooExport: any = { exports: {} };
|
MoeHooExport: any = { exports: {} };
|
||||||
|
recallHookEnabled: boolean = false;
|
||||||
constructor(nodePath: string, platform: string = process.platform) {
|
constructor(nodePath: string, platform: string = process.platform) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
if (!this.supportedPlatforms.includes(this.platform)) {
|
if (!this.supportedPlatforms.includes(this.platform)) {
|
||||||
@ -12,4 +13,11 @@ export class Native {
|
|||||||
}
|
}
|
||||||
dlopen(this.MoeHooExport, path.join(nodePath, './native/MoeHoo.win32.node'), constants.dlopen.RTLD_LAZY);
|
dlopen(this.MoeHooExport, path.join(nodePath, './native/MoeHoo.win32.node'), constants.dlopen.RTLD_LAZY);
|
||||||
}
|
}
|
||||||
|
isSetReCallEnabled(): boolean {
|
||||||
|
return this.recallHookEnabled;
|
||||||
|
}
|
||||||
|
registerRecallCallback(callback: (hex: string) => any): void {
|
||||||
|
this.recallHookEnabled = true;
|
||||||
|
return this.MoeHooExport.exports.registMsgPush(callback);
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ import BaseAction from '../BaseAction';
|
|||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { RawMessage } from '@/core';
|
||||||
|
|
||||||
|
|
||||||
export type ReturnDataType = OB11Message
|
export type ReturnDataType = OB11Message
|
||||||
@ -32,13 +33,17 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
|||||||
throw new Error('消息不存在');
|
throw new Error('消息不存在');
|
||||||
}
|
}
|
||||||
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
||||||
const msg = await this.core.apis.MsgApi.getMsgsByMsgId(
|
let orimsg = this.obContext.recallMsgCache.get(msgIdWithPeer.MsgId);
|
||||||
peer,
|
let msg: RawMessage;
|
||||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
if (orimsg) {
|
||||||
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg.msgList[0]);
|
msg = orimsg;
|
||||||
|
} else {
|
||||||
|
msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0];
|
||||||
|
}
|
||||||
|
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg);
|
||||||
if (!retMsg) throw Error('消息为空');
|
if (!retMsg) throw Error('消息为空');
|
||||||
try {
|
try {
|
||||||
retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgList[0].msgId)!;
|
retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgId)!;
|
||||||
retMsg.message_seq = retMsg.message_id;
|
retMsg.message_seq = retMsg.message_id;
|
||||||
retMsg.real_id = retMsg.message_id;
|
retMsg.real_id = retMsg.message_id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -46,7 +46,6 @@ import { LRUCache } from '@/common/lru-cache';
|
|||||||
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
|
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
|
||||||
import { Native } from '@/native';
|
import { Native } from '@/native';
|
||||||
import { Message, RecallGroup } from '@/core/proto/Message';
|
import { Message, RecallGroup } from '@/core/proto/Message';
|
||||||
import { OB11MessageData } from './types';
|
|
||||||
|
|
||||||
//OneBot实现类
|
//OneBot实现类
|
||||||
export class NapCatOneBot11Adapter {
|
export class NapCatOneBot11Adapter {
|
||||||
@ -57,8 +56,9 @@ export class NapCatOneBot11Adapter {
|
|||||||
apis: StableOneBotApiWrapper;
|
apis: StableOneBotApiWrapper;
|
||||||
networkManager: OB11NetworkManager;
|
networkManager: OB11NetworkManager;
|
||||||
actions: ActionMap;
|
actions: ActionMap;
|
||||||
|
nativeCore: Native | undefined;
|
||||||
private bootTime = Date.now() / 1000;
|
private bootTime = Date.now() / 1000;
|
||||||
|
recallMsgCache = new LRUCache<string, RawMessage>(100);
|
||||||
|
|
||||||
constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
|
constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@ -73,14 +73,14 @@ export class NapCatOneBot11Adapter {
|
|||||||
};
|
};
|
||||||
this.actions = createActionMap(this, core);
|
this.actions = createActionMap(this, core);
|
||||||
this.networkManager = new OB11NetworkManager();
|
this.networkManager = new OB11NetworkManager();
|
||||||
this.registerNative(core,context).then().catch();
|
this.registerNative(core, context).then().catch();
|
||||||
this.InitOneBot()
|
this.InitOneBot()
|
||||||
.catch(e => this.context.logger.logError.bind(this.context.logger)('初始化OneBot失败', e));
|
.catch(e => this.context.logger.logError.bind(this.context.logger)('初始化OneBot失败', e));
|
||||||
|
|
||||||
}
|
}
|
||||||
async registerNative(core: NapCatCore, context: InstanceContext) {
|
async registerNative(core: NapCatCore, context: InstanceContext) {
|
||||||
let appNative = new Native(context.pathWrapper.binaryPath);
|
this.nativeCore = new Native(context.pathWrapper.binaryPath);
|
||||||
appNative.MoeHooExport.exports.registMsgPush(async (hex: string) => {
|
this.nativeCore.registerRecallCallback(async (hex: string) => {
|
||||||
try {
|
try {
|
||||||
let data = Message.decode(Buffer.from(hex, 'hex')) as any;
|
let data = Message.decode(Buffer.from(hex, 'hex')) as any;
|
||||||
//data.MsgHead.BodyInner.MsgType SubType
|
//data.MsgHead.BodyInner.MsgType SubType
|
||||||
@ -95,12 +95,13 @@ export class NapCatOneBot11Adapter {
|
|||||||
let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() };
|
let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() };
|
||||||
context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq);
|
context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq);
|
||||||
let msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString());
|
let msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString());
|
||||||
|
this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]);
|
||||||
let ob11 = await this.apis.MsgApi.parseMessage(msgs.msgList[0], 'array')
|
// let ob11 = await this.apis.MsgApi.parseMessage(msgs.msgList[0], 'array')
|
||||||
if (ob11) {
|
// .catch(e => this.context.logger.logError.bind(this.context.logger)('处理消息失败', e));
|
||||||
const { sendElements, deleteAfterSentFiles } = await this.apis.MsgApi.createSendElements(ob11.message as OB11MessageData[], peer);
|
// if (ob11) {
|
||||||
this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles);
|
// const { sendElements, deleteAfterSentFiles } = await this.apis.MsgApi.createSendElements(ob11.message as OB11MessageData[], peer);
|
||||||
}
|
// this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// this.apis.MsgApi.sendMsg(peer, [{
|
// this.apis.MsgApi.sendMsg(peer, [{
|
||||||
@ -116,7 +117,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
// }]);
|
// }]);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
context.logger.logWarn("[Native] Error:", (error as Error).message,' HEX:',Buffer.from(hex, 'hex'));
|
context.logger.logWarn("[Native] Error:", (error as Error).message, ' HEX:', hex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -569,7 +570,6 @@ export class NapCatOneBot11Adapter {
|
|||||||
}
|
}
|
||||||
}).catch(e => this.context.logger.logError.bind(this.context.logger)('constructPrivateEvent error: ', e));
|
}).catch(e => this.context.logger.logError.bind(this.context.logger)('constructPrivateEvent error: ', e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async emitRecallMsg(msgList: RawMessage[], cache: LRUCache<string, boolean>) {
|
private async emitRecallMsg(msgList: RawMessage[], cache: LRUCache<string, boolean>) {
|
||||||
for (const message of msgList) {
|
for (const message of msgList) {
|
||||||
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
||||||
@ -601,7 +601,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
parseInt(message.peerUin),
|
parseInt(message.peerUin),
|
||||||
parseInt(message.senderUin),
|
parseInt(message.senderUin),
|
||||||
parseInt(operatorId),
|
parseInt(operatorId),
|
||||||
oriMessageId,
|
oriMessageId
|
||||||
);
|
);
|
||||||
this.networkManager.emitEvent(groupRecallEvent)
|
this.networkManager.emitEvent(groupRecallEvent)
|
||||||
.catch(e => this.context.logger.logError.bind(this.context.logger)('处理群消息撤回失败', e));
|
.catch(e => this.context.logger.logError.bind(this.context.logger)('处理群消息撤回失败', e));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user