mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
@@ -82,7 +82,7 @@ class MessageUniqueWrapper {
|
||||
return ret.map((t) => t?.MsgId).filter((t) => t !== undefined)
|
||||
}
|
||||
|
||||
createMsg(peer: Peer, msgId: string): number | undefined {
|
||||
createMsg(peer: Peer, msgId: string): number {
|
||||
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`
|
||||
const hash = createHash('md5').update(key).digest()
|
||||
//设置第一个bit为0 保证shortId为正数
|
||||
|
@@ -136,25 +136,24 @@ export function invoke<
|
||||
R extends Awaited<ReturnType<NTService[S][M] extends (...args: any) => any ? NTService[S][M] : any>>,
|
||||
S extends keyof NTService = any,
|
||||
M extends keyof NTService[S] & string = any
|
||||
>(method: `${unknown extends `${S}/${M}` ? `${S}/${M}` : string}`, args?: unknown[], options: InvokeOptions<R> = {}) {
|
||||
>(method: `${unknown extends `${S}/${M}` ? `${S}/${M}` : string}`, args: unknown[], options: InvokeOptions<R> = {}) {
|
||||
const className = options.className ?? NTClass.NT_API
|
||||
const channel = options.channel ?? NTChannel.IPC_UP_2
|
||||
const timeout = options.timeout ?? 5000
|
||||
const afterFirstCmd = options.afterFirstCmd ?? true
|
||||
const uuid = randomUUID()
|
||||
let eventName = className + '-' + channel[channel.length - 1]
|
||||
if (options.classNameIsRegister) {
|
||||
eventName += '-register'
|
||||
}
|
||||
const apiArgs = [method, ...(args ?? [])]
|
||||
//log('callNTQQApi', channel, eventName, apiArgs, uuid)
|
||||
return new Promise((resolve: (data: R) => void, reject) => {
|
||||
return new Promise<R>((resolve, reject) => {
|
||||
const apiArgs = [method, ...args]
|
||||
const callbackId = randomUUID()
|
||||
let success = false
|
||||
if (!options.cbCmd) {
|
||||
// QQ后端会返回结果,并且可以根据uuid识别
|
||||
hookApiCallbacks[uuid] = (r: R) => {
|
||||
hookApiCallbacks[callbackId] = res => {
|
||||
success = true
|
||||
resolve(r)
|
||||
resolve(res)
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -177,7 +176,7 @@ export function invoke<
|
||||
})
|
||||
}
|
||||
!afterFirstCmd && secondCallback()
|
||||
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
|
||||
hookApiCallbacks[callbackId] = (result: GeneralCallResult) => {
|
||||
if (result?.result === 0 || result === undefined) {
|
||||
//log(`${params.methodName} callback`, result)
|
||||
afterFirstCmd && secondCallback()
|
||||
@@ -203,7 +202,7 @@ export function invoke<
|
||||
},
|
||||
},
|
||||
},
|
||||
{ type: 'request', callbackId: uuid, eventName },
|
||||
{ type: 'request', callbackId, eventName },
|
||||
apiArgs,
|
||||
)
|
||||
})
|
||||
|
@@ -146,34 +146,31 @@ export namespace OB11Entities {
|
||||
message_data['data']['text'] = text
|
||||
}
|
||||
else if (element.replyElement) {
|
||||
message_data['type'] = OB11MessageDataType.reply
|
||||
const { replyElement } = element
|
||||
const peer = {
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
guildId: ''
|
||||
}
|
||||
try {
|
||||
const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords)
|
||||
const records = msg.records.find(msgRecord => msgRecord.msgId === replyElement.sourceMsgIdInRecords)
|
||||
if (!records) throw new Error('找不到回复消息')
|
||||
let replyMsg = (await ctx.ntMsgApi.getMsgsBySeqAndCount({
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
}, element.replyElement.replayMsgSeq, 1, true, true))?.msgList[0]
|
||||
let replyMsg = (await ctx.ntMsgApi.getMsgsBySeqAndCount(peer, replyElement.replayMsgSeq, 1, true, true)).msgList[0]
|
||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||
const peer = {
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
}
|
||||
replyMsg = (await ctx.ntMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq))?.msgList[0]
|
||||
replyMsg = (await ctx.ntMsgApi.getSingleMsg(peer, replyElement.replayMsgSeq)).msgList[0]
|
||||
}
|
||||
// 284840486: 合并消息内侧 消息具体定位不到
|
||||
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||
throw new Error('回复消息消息验证失败')
|
||||
}
|
||||
message_data['data']['id'] = replyMsg && MessageUnique.createMsg({
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
}, replyMsg.msgId)?.toString()
|
||||
message_data = {
|
||||
type: OB11MessageDataType.reply,
|
||||
data: {
|
||||
id: MessageUnique.createMsg(peer, replyMsg ? replyMsg.msgId : records.msgId).toString()
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
ctx.logger.error('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq)
|
||||
ctx.logger.error('获取不到引用的消息', replyElement.replayMsgSeq, e.stack)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user