mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-15 21:00:34 +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 { ActionName, BaseCheckResult } from '@/onebot11/action/types';
|
||||||
import { getFriend, getGroup, getUidByUin } from '@/core/data';
|
import { getFriend, getGroup, getUidByUin } from '@/core/data';
|
||||||
import { dbUtil } from '@/core/utils/db';
|
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 fs from 'node:fs';
|
||||||
import { logDebug } from '@/common/utils/log';
|
import { logDebug, logError } from '@/common/utils/log';
|
||||||
import { decodeCQCode } from '@/onebot11/cqcode';
|
import { decodeCQCode } from '@/onebot11/cqcode';
|
||||||
import createSendElements from './create-send-elements';
|
import createSendElements from './create-send-elements';
|
||||||
import { handleForwardNode } from '@/onebot11/action/msg/SendMsg/handle-forward-node';
|
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) {
|
if (!sendElements.length) {
|
||||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
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);
|
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||||
try {
|
try {
|
||||||
returnMsg.id = await dbUtil.addMsg(returnMsg, false);
|
returnMsg.id = await dbUtil.addMsg(returnMsg, false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user