mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 04:45:46 +00:00
Merge pull request #303 from NapNeko/dev/RefactoredMsgParsers
style: Error Object
This commit is contained in:
commit
d947fe743b
@ -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);
|
||||
|
@ -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> {
|
||||
|
@ -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() };
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user