mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-09-28 04:05:12 +00:00
feat: send timeout predict
This commit is contained in:
parent
c3f3d12f83
commit
076c9cfed7
@ -9,9 +9,9 @@ import {
|
||||
import { ActionName, BaseCheckResult } from '@/onebot11/action/types';
|
||||
import { getFriend, getGroup, getUidByUin } from '@/core/data';
|
||||
import { dbUtil } from '@/core/utils/db';
|
||||
import { ChatType, Group, NTQQMsgApi, Peer, SendMessageElement, } from '@/core';
|
||||
import { ChatType, ElementType, Group, NTQQMsgApi, Peer, SendMessageElement, } from '@/core';
|
||||
import fs from 'node:fs';
|
||||
import { logDebug } from '@/common/utils/log';
|
||||
import { logDebug, logError } from '@/common/utils/log';
|
||||
import { decodeCQCode } from '@/onebot11/cqcode';
|
||||
import createSendElements from './create-send-elements';
|
||||
import { handleForwardNode } from '@/onebot11/action/msg/SendMsg/handle-forward-node';
|
||||
@ -37,6 +37,31 @@ export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], de
|
||||
if (!sendElements.length) {
|
||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
||||
}
|
||||
let totalSize = 0;
|
||||
let timeout = 5000;
|
||||
try {
|
||||
for (const fileElement of sendElements) {
|
||||
if (fileElement.elementType === ElementType.PTT) {
|
||||
totalSize += fs.statSync(fileElement.pttElement.filePath).size
|
||||
}
|
||||
if (fileElement.elementType === ElementType.FILE) {
|
||||
totalSize += fs.statSync(fileElement.fileElement.filePath).size
|
||||
}
|
||||
if (fileElement.elementType === ElementType.VIDEO) {
|
||||
totalSize += fs.statSync(fileElement.videoElement.filePath).size
|
||||
}
|
||||
if (fileElement.elementType === ElementType.PIC) {
|
||||
totalSize += fs.statSync(fileElement.picElement.sourcePath).size
|
||||
}
|
||||
}
|
||||
//且 PredictTime ((totalSize / 1024 / 512) * 1000)不等于Nan
|
||||
let PredictTime = totalSize / 1024 / 512 * 1000;
|
||||
if (!Number.isNaN(PredictTime)) {
|
||||
timeout += PredictTime// 10S Basic Timeout + PredictTime( For File 512kb/s )
|
||||
}
|
||||
} catch (e) {
|
||||
logError("发送消息计算预计时间异常", e);
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
try {
|
||||
returnMsg.id = await dbUtil.addMsg(returnMsg, false);
|
||||
|
Loading…
Reference in New Issue
Block a user