(partially) fix: 'throw' of exception caught locally

This commit is contained in:
Seijo Cecilia 2024-08-27 15:05:51 +08:00
parent 8565aee8b6
commit 3f2dcfbacc
5 changed files with 106 additions and 192 deletions

View File

@ -60,20 +60,17 @@ export class QQBasicInfoWrapper {
getAppidV2(): { appid: string; qua: string } { getAppidV2(): { appid: string; qua: string } {
const appidTbale = AppidTable as unknown as QQAppidTableType; const appidTbale = AppidTable as unknown as QQAppidTableType;
try {
const fullVersion = this.getFullQQVesion(); const fullVersion = this.getFullQQVesion();
if (!fullVersion) throw new Error('QQ版本获取失败'); if (fullVersion) {
const data = appidTbale[fullVersion]; const data = appidTbale[fullVersion];
if (data) { if (data) {
return data; return data;
} }
} catch (e) {
this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
} }
// 以下是兜底措施
this.context.logger.log( // else
`[QQ版本兼容性检测] ${this.getFullQQVesion()} 版本兼容性不佳,可能会导致一些功能无法正常使用`, this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
); this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,);
return { appid: systemPlatform === 'linux' ? '537240795' : '537240709', qua: this.getQUAInternal() }; return { appid: systemPlatform === 'linux' ? '537240795' : '537240709', qua: this.getQUAInternal() };
} }
} }

View File

@ -184,11 +184,8 @@ export class NTQQWebApi {
const HonorInfo: any = { group_id: groupCode }; const HonorInfo: any = { group_id: groupCode };
if (getType === WebHonorType.TALKATIVE || getType === WebHonorType.ALL) { if (getType === WebHonorType.TALKATIVE || getType === WebHonorType.ALL) {
try {
const RetInternal = await getDataInternal(groupCode, 1); const RetInternal = await getDataInternal(groupCode, 1);
if (!RetInternal) { if (RetInternal) {
throw new Error('获取龙王信息失败');
}
HonorInfo.current_talkative = { HonorInfo.current_talkative = {
user_id: RetInternal[0]?.uin, user_id: RetInternal[0]?.uin,
avatar: RetInternal[0]?.avatar, avatar: RetInternal[0]?.avatar,
@ -206,16 +203,13 @@ export class NTQQWebApi {
nickname: talkative_ele?.name, nickname: talkative_ele?.name,
}); });
} }
} catch (e) { } else {
this.context.logger.logDebug(e); this.context.logger.logError('获取龙王信息失败');
} }
} }
if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) { if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) {
try {
const RetInternal = await getDataInternal(groupCode, 2); const RetInternal = await getDataInternal(groupCode, 2);
if (!RetInternal) { if (RetInternal) {
throw new Error('获取群聊之火失败');
}
HonorInfo.performer_list = []; HonorInfo.performer_list = [];
for (const performer_ele of RetInternal) { for (const performer_ele of RetInternal) {
HonorInfo.performer_list.push({ HonorInfo.performer_list.push({
@ -225,16 +219,13 @@ export class NTQQWebApi {
description: performer_ele?.desc, description: performer_ele?.desc,
}); });
} }
} catch (e) { } else {
this.context.logger.logDebug(e); this.context.logger.logError('获取群聊之火失败');
} }
} }
if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) { if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) {
try {
const RetInternal = await getDataInternal(groupCode, 3); const RetInternal = await getDataInternal(groupCode, 3);
if (!RetInternal) { if (RetInternal) {
throw new Error('获取群聊炽焰失败');
}
HonorInfo.legend_list = []; HonorInfo.legend_list = [];
for (const legend_ele of RetInternal) { for (const legend_ele of RetInternal) {
HonorInfo.legend_list.push({ HonorInfo.legend_list.push({
@ -244,16 +235,13 @@ export class NTQQWebApi {
desc: legend_ele?.description, desc: legend_ele?.description,
}); });
} }
} catch (e) { } else {
this.context.logger.logDebug('获取群聊炽焰失败', e); this.context.logger.logError('获取群聊炽焰失败');
} }
} }
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) { if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
try {
const RetInternal = await getDataInternal(groupCode, 6); const RetInternal = await getDataInternal(groupCode, 6);
if (!RetInternal) { if (RetInternal) {
throw new Error('获取快乐源泉失败');
}
HonorInfo.emotion_list = []; HonorInfo.emotion_list = [];
for (const emotion_ele of RetInternal) { for (const emotion_ele of RetInternal) {
HonorInfo.emotion_list.push({ HonorInfo.emotion_list.push({
@ -263,11 +251,11 @@ export class NTQQWebApi {
desc: emotion_ele.description, desc: emotion_ele.description,
}); });
} }
} catch (e) { } else {
this.context.logger.logDebug('获取快乐源泉失败', e); this.context.logger.logError('获取快乐源泉失败');
} }
} }
//冒尖小春笋好像已经被tx扬了 // 冒尖小春笋好像已经被tx扬了 R.I.P.
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) { if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
HonorInfo.strong_newbie_list = []; HonorInfo.strong_newbie_list = [];
} }

View File

@ -34,15 +34,10 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
const NTQQMsgApi = this.core.apis.MsgApi; const NTQQMsgApi = this.core.apis.MsgApi;
const NTQQGroupApi = this.core.apis.GroupApi; const NTQQGroupApi = this.core.apis.GroupApi;
const NTQQFileApi = this.core.apis.FileApi; const NTQQFileApi = this.core.apis.FileApi;
let UuidData: {
high: string;
low: string;
} | undefined;
try { try {
UuidData = UUIDConverter.decode(payload.file); const uuidData = UUIDConverter.decode(payload.file);
if (UuidData) { const peerUin = uuidData.high;
const peerUin = UuidData.high; const msgId = uuidData.low;
const msgId = UuidData.low;
const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin); const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin);
let peer: Peer | undefined; let peer: Peer | undefined;
//识别Peer //识别Peer
@ -79,7 +74,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
file_size: fileSize, file_size: fileSize,
file_name: fileName, file_name: fileName,
}; };
if (true/*enableLocalFile2Url*/ && downloadPath) { if (/* enableLocalFile2Url && */ downloadPath) {
try { try {
res.base64 = await fs.readFile(downloadPath, 'base64'); res.base64 = await fs.readFile(downloadPath, 'base64');
} catch (e) { } catch (e) {
@ -88,7 +83,6 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
} }
//不手动删除?文件持久化了 //不手动删除?文件持久化了
return res; return res;
}
} catch { } catch {
this.core.context.logger.logDebug('GetFileBase Mode - 1 Error'); this.core.context.logger.logDebug('GetFileBase Mode - 1 Error');
} }
@ -119,7 +113,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
file_size: NTSearchNameResult[0].fileSize.toString(), file_size: NTSearchNameResult[0].fileSize.toString(),
file_name: NTSearchNameResult[0].fileName, file_name: NTSearchNameResult[0].fileName,
}; };
if (true/*enableLocalFile2Url*/ && downloadPath) { if (/* enableLocalFile2Url && */ downloadPath) {
try { try {
res.base64 = await fs.readFile(downloadPath, 'base64'); res.base64 = await fs.readFile(downloadPath, 'base64');
} catch (e) { } catch (e) {
@ -130,66 +124,6 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
return res; return res;
} }
throw new Error('file not found'); throw new Error('file not found');
// let cache = await dbUtil.getFileCacheByName(payload.file);
// if (!cache) {
// cache = await dbUtil.getFileCacheByUuid(payload.file);
// }
// if (!cache) {
// throw new Error('file not found');
// }
// const { enableLocalFile2Url } = ob11Config;
// try {
// await fs.access(cache.path, fs.constants.F_OK);
// } catch (e) {
// logDebug('local file not found, start download...');
// // if (cache.url) {
// // const downloadResult = await uri2local(cache.url);
// // if (downloadResult.success) {
// // cache.path = downloadResult.path;
// // dbUtil.updateFileCache(cache).then();
// // } else {
// // throw new Error('file download failed. ' + downloadResult.errMsg);
// // }
// // } else {
// // // 没有url的可能是私聊文件或者群文件需要自己下载
// // log('需要调用 NTQQ 下载文件api');
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
// let msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
// // log('文件 msg', msg);
// if (msg) {
// // 构建下载函数
// const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
// cache.elementId, '', '');
// // await sleep(1000);
// // log('download result', downloadPath);
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
// msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
// // log('下载完成后的msg', msg);
// cache.path = downloadPath!;
// dbUtil.updateFileCache(cache).then();
// // log('下载完成后的msg', msg);
// // }
// }
// }
// // log('file found', cache);
// const res: GetFileResponse = {
// file: cache.path,
// url: cache.url,
// file_size: cache.size.toString(),
// file_name: cache.name
// };
// if (enableLocalFile2Url) {
// if (!cache.url) {
// try {
// res.base64 = await fs.readFile(cache.path, 'base64');
// } catch (e) {
// throw new Error('文件下载失败. ' + e);
// }
// }
// }
//return res;
} }
} }

View File

@ -20,16 +20,12 @@ export default class SendLike extends BaseAction<Payload, null> {
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.core.apis.UserApi; const NTQQUserApi = this.core.apis.UserApi;
//logDebug('点赞参数', payload); //logDebug('点赞参数', payload);
try {
const qq = payload.user_id.toString(); const qq = payload.user_id.toString();
const uid: string = await NTQQUserApi.getUidByUinV2(qq) || ''; const uid: string = await NTQQUserApi.getUidByUinV2(qq) || '';
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1); const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
//logDebug('点赞结果', result); //logDebug('点赞结果', result);
if (result.result !== 0) { if (result.result !== 0) {
throw Error(result.errMsg); throw `点赞失败 ${result.errMsg}`;
}
} catch (e) {
throw `点赞失败 ${e}`;
} }
return null; return null;
} }

View File

@ -89,9 +89,10 @@ export class OneBotGroupApi {
parseInt(memberUin), parseInt(memberUin),
parseInt(operatorUin), parseInt(operatorUin),
); );
} } else {
return undefined; return undefined;
} }
}
async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) { async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) {
const NTQQGroupApi = this.core.apis.GroupApi; const NTQQGroupApi = this.core.apis.GroupApi;
@ -118,7 +119,6 @@ export class OneBotGroupApi {
attributeNamePrefix: '', attributeNamePrefix: '',
}).parse(grayTipElement.xmlElement.content); }).parse(grayTipElement.xmlElement.content);
this.core.context.logger.logDebug('收到表情回应我的消息', emojiLikeData); this.core.context.logger.logDebug('收到表情回应我的消息', emojiLikeData);
try {
const senderUin = emojiLikeData.gtip.qq.jp; const senderUin = emojiLikeData.gtip.qq.jp;
const msgSeq = emojiLikeData.gtip.url.msgseq; const msgSeq = emojiLikeData.gtip.url.msgseq;
const emojiId = emojiLikeData.gtip.face.id; const emojiId = emojiLikeData.gtip.face.id;
@ -133,7 +133,10 @@ export class OneBotGroupApi {
} }
const replyMsg = replyMsgList.filter(e => e.msgSeq == msgSeq).sort((a, b) => parseInt(a.msgTime) - parseInt(b.msgTime))[0]; const replyMsg = replyMsgList.filter(e => e.msgSeq == msgSeq).sort((a, b) => parseInt(a.msgTime) - parseInt(b.msgTime))[0];
//console.log("表情回应消息长度检测", msgSeq, replyMsg.elements); //console.log("表情回应消息长度检测", msgSeq, replyMsg.elements);
if (!replyMsg) throw new Error('找不到回应消息'); if (!replyMsg) {
this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息');
return undefined;
}
return new OB11GroupMsgEmojiLikeEvent( return new OB11GroupMsgEmojiLikeEvent(
this.core, this.core,
parseInt(GroupCode), parseInt(GroupCode),
@ -144,9 +147,5 @@ export class OneBotGroupApi {
count: 1, count: 1,
}], }],
); );
} catch (e: any) {
this.core.context.logger.logError('解析表情回应消息失败', e.stack);
}
return undefined;
} }
} }