mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
parent
ad74854e42
commit
3570349fcd
@ -153,12 +153,7 @@ export class NTQQMsgApi extends Service {
|
||||
)
|
||||
msgList = data.msgList
|
||||
}
|
||||
const retMsg = msgList.find(msgRecord => {
|
||||
if (msgRecord.guildId === msgId) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
return retMsg!
|
||||
return msgList.find(msgRecord => msgRecord.guildId === msgId)
|
||||
}
|
||||
|
||||
async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
|
@ -11,16 +11,16 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
if (!payload.message_id) {
|
||||
throw Error('message_id不能为空')
|
||||
throw new Error('参数message_id不能为空')
|
||||
}
|
||||
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||
if (!msg) {
|
||||
throw `消息${payload.message_id}不存在`
|
||||
throw new Error(`消息${payload.message_id}不存在`)
|
||||
}
|
||||
const data = await this.ctx.ntMsgApi.recallMsg(msg.Peer, [msg.MsgId])
|
||||
if (data.result !== 0) {
|
||||
this.ctx.logger.error('delete_msg', payload.message_id, data)
|
||||
throw `消息撤回失败`
|
||||
throw new Error(`消息撤回失败`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +160,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
}
|
||||
const returnMsg = await sendMsg(this.ctx, peer, sendElements, deleteAfterSentFiles)
|
||||
if (!returnMsg) {
|
||||
throw new Error('消息发送失败')
|
||||
}
|
||||
return { message_id: returnMsg.msgShortId! }
|
||||
}
|
||||
|
||||
@ -251,9 +254,12 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
// log("分割后的转发节点", sendElementsSplit)
|
||||
for (const eles of sendElementsSplit) {
|
||||
const nodeMsg = await sendMsg(this.ctx, selfPeer, eles, [], true)
|
||||
if (!nodeMsg) {
|
||||
this.ctx.logger.warn('转发节点生成失败', eles)
|
||||
continue
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.msgId)
|
||||
await this.ctx.sleep(400)
|
||||
this.ctx.logger.info('转发节点生成成功', nodeMsg.msgId)
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
||||
}))
|
||||
|
@ -270,8 +270,10 @@ export async function sendMsg(
|
||||
const timeout = 10000 + (totalSize / 1024 / 256 * 1000) // 10s Basic Timeout + PredictTime( For File 512kb/s )
|
||||
//log('设置消息超时时间', timeout)
|
||||
const returnMsg = await ctx.ntMsgApi.sendMsg(peer, sendElements, waitComplete, timeout)
|
||||
if (returnMsg) {
|
||||
returnMsg.msgShortId = MessageUnique.createMsg(peer, returnMsg.msgId)
|
||||
ctx.logger.info('消息发送', returnMsg.msgShortId)
|
||||
deleteAfterSentFiles.map(path => fsPromise.unlink(path))
|
||||
return returnMsg
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user