diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index b9f52d1b..d9e7b69d 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -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); diff --git a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts index 287b59e0..c777e197 100644 --- a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts +++ b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts @@ -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> { diff --git a/src/onebot/action/msg/MarkMsgAsRead.ts b/src/onebot/action/msg/MarkMsgAsRead.ts index 6cbbeea3..adc21da9 100644 --- a/src/onebot/action/msg/MarkMsgAsRead.ts +++ b/src/onebot/action/msg/MarkMsgAsRead.ts @@ -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() }; } diff --git a/src/onebot/action/msg/SendMsg.ts b/src/onebot/action/msg/SendMsg.ts index b9ad6e07..01d1f04d 100644 --- a/src/onebot/action/msg/SendMsg.ts +++ b/src/onebot/action/msg/SendMsg.ts @@ -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; }