This commit is contained in:
手瓜一十雪 2024-08-25 23:57:16 +08:00
parent 337ac0eab9
commit 5b37ae9026
4 changed files with 11 additions and 11 deletions

View File

@ -101,7 +101,7 @@ export class NTQQFileApi {
): Promise<SendFileElement> {
const { fileName: _fileName, path, fileSize } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.FILE);
if (fileSize === 0) {
throw '文件异常大小为0';
throw new Error('文件异常大小为0');
}
return {
elementType: ElementType.FILE,
@ -122,7 +122,7 @@ export class NTQQFileApi {
): Promise<SendPicElement> {
const { md5, fileName, path, fileSize } = await this.core.apis.FileApi.uploadFile(picPath, ElementType.PIC, subType);
if (fileSize === 0) {
throw '文件异常大小为0';
throw new Error('文件异常大小为0');
}
const imageSize = await this.core.apis.FileApi.getImageSize(picPath);
const picElement: any = {
@ -155,7 +155,7 @@ export class NTQQFileApi {
const logger = this.core.context.logger;
const { fileName: _fileName, path, fileSize, md5 } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.VIDEO);
if (fileSize === 0) {
throw '文件异常大小为0';
throw new Error('文件异常大小为0');
}
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`);
thumb = pathLib.dirname(thumb);
@ -255,11 +255,11 @@ export class NTQQFileApi {
} = await encodeSilk(pttPath, this.core.NapCatTempPath, this.core.context.logger);
// log("生成语音", silkPath, duration);
if (!silkPath) {
throw '语音转换失败, 请检查语音文件是否正常';
throw new Error('语音转换失败, 请检查语音文件是否正常');
}
const { md5, fileName, path, fileSize } = await this.core.apis.FileApi.uploadFile(silkPath!, ElementType.PTT);
if (fileSize === 0) {
throw '文件异常大小为0';
throw new Error('文件异常大小为0');
}
if (converted) {
fsPromises.unlink(silkPath);

View File

@ -33,7 +33,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
}
throw '缺少参数 user_id';
throw new Error( '缺少参数 user_id');
}
async _handle(payload: Payload): Promise<null> {

View File

@ -26,7 +26,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
}
if (!payload.group_id) {
throw '缺少参数 group_id 或 user_id';
throw new Error( '缺少参数 group_id 或 user_id');
}
return { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
}

View File

@ -36,7 +36,7 @@ export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements:
const NTQQMsgApi = coreContext.apis.MsgApi;
const logger = coreContext.context.logger;
if (!sendElements.length) {
throw new Error ('消息体无法解析, 请检查是否发送了不支持的消息类型');
throw new Error('消息体无法解析, 请检查是否发送了不支持的消息类型');
}
let totalSize = 0;
let timeout = 10000;
@ -95,7 +95,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
}
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
const Uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
if (!Uid) throw '无法获取用户信息';
if (!Uid) throw new Error('无法获取用户信息');
const isBuddy = await NTQQFriendApi.isBuddy(Uid);
if (!isBuddy) {
const ret = await NTQQMsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, Uid);
@ -125,7 +125,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
guildId: '',
};
}
throw '请指定 group_id 或 user_id';
throw new Error('请指定 group_id 或 user_id');
}
function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
@ -274,7 +274,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
let retMsgIds: string[] = [];
if (needSendSelf) {
for (const [, msg] of nodeMsgArray.entries()) {
if (msg.peerUid === this.CoreContext.selfInfo.uid){
if (msg.peerUid === this.CoreContext.selfInfo.uid) {
retMsgIds.push(msg.msgId);
continue;
}