mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
(partially) fix: 'throw' of exception caught locally
This commit is contained in:
@@ -60,20 +60,17 @@ export class QQBasicInfoWrapper {
|
||||
|
||||
getAppidV2(): { appid: string; qua: string } {
|
||||
const appidTbale = AppidTable as unknown as QQAppidTableType;
|
||||
try {
|
||||
const fullVersion = this.getFullQQVesion();
|
||||
if (!fullVersion) throw new Error('QQ版本获取失败');
|
||||
if (fullVersion) {
|
||||
const data = appidTbale[fullVersion];
|
||||
if (data) {
|
||||
return data;
|
||||
}
|
||||
} catch (e) {
|
||||
this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
|
||||
}
|
||||
// 以下是兜底措施
|
||||
this.context.logger.log(
|
||||
`[QQ版本兼容性检测] ${this.getFullQQVesion()} 版本兼容性不佳,可能会导致一些功能无法正常使用`,
|
||||
);
|
||||
|
||||
// else
|
||||
this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
|
||||
this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,);
|
||||
return { appid: systemPlatform === 'linux' ? '537240795' : '537240709', qua: this.getQUAInternal() };
|
||||
}
|
||||
}
|
||||
|
@@ -184,11 +184,8 @@ export class NTQQWebApi {
|
||||
const HonorInfo: any = { group_id: groupCode };
|
||||
|
||||
if (getType === WebHonorType.TALKATIVE || getType === WebHonorType.ALL) {
|
||||
try {
|
||||
const RetInternal = await getDataInternal(groupCode, 1);
|
||||
if (!RetInternal) {
|
||||
throw new Error('获取龙王信息失败');
|
||||
}
|
||||
if (RetInternal) {
|
||||
HonorInfo.current_talkative = {
|
||||
user_id: RetInternal[0]?.uin,
|
||||
avatar: RetInternal[0]?.avatar,
|
||||
@@ -206,16 +203,13 @@ export class NTQQWebApi {
|
||||
nickname: talkative_ele?.name,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
this.context.logger.logDebug(e);
|
||||
} else {
|
||||
this.context.logger.logError('获取龙王信息失败');
|
||||
}
|
||||
}
|
||||
if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) {
|
||||
try {
|
||||
const RetInternal = await getDataInternal(groupCode, 2);
|
||||
if (!RetInternal) {
|
||||
throw new Error('获取群聊之火失败');
|
||||
}
|
||||
if (RetInternal) {
|
||||
HonorInfo.performer_list = [];
|
||||
for (const performer_ele of RetInternal) {
|
||||
HonorInfo.performer_list.push({
|
||||
@@ -225,16 +219,13 @@ export class NTQQWebApi {
|
||||
description: performer_ele?.desc,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
this.context.logger.logDebug(e);
|
||||
} else {
|
||||
this.context.logger.logError('获取群聊之火失败');
|
||||
}
|
||||
}
|
||||
if (getType === WebHonorType.PERFORMER || getType === WebHonorType.ALL) {
|
||||
try {
|
||||
const RetInternal = await getDataInternal(groupCode, 3);
|
||||
if (!RetInternal) {
|
||||
throw new Error('获取群聊炽焰失败');
|
||||
}
|
||||
if (RetInternal) {
|
||||
HonorInfo.legend_list = [];
|
||||
for (const legend_ele of RetInternal) {
|
||||
HonorInfo.legend_list.push({
|
||||
@@ -244,16 +235,13 @@ export class NTQQWebApi {
|
||||
desc: legend_ele?.description,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
this.context.logger.logDebug('获取群聊炽焰失败', e);
|
||||
} else {
|
||||
this.context.logger.logError('获取群聊炽焰失败');
|
||||
}
|
||||
}
|
||||
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
|
||||
try {
|
||||
const RetInternal = await getDataInternal(groupCode, 6);
|
||||
if (!RetInternal) {
|
||||
throw new Error('获取快乐源泉失败');
|
||||
}
|
||||
if (RetInternal) {
|
||||
HonorInfo.emotion_list = [];
|
||||
for (const emotion_ele of RetInternal) {
|
||||
HonorInfo.emotion_list.push({
|
||||
@@ -263,11 +251,11 @@ export class NTQQWebApi {
|
||||
desc: emotion_ele.description,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
this.context.logger.logDebug('获取快乐源泉失败', e);
|
||||
} else {
|
||||
this.context.logger.logError('获取快乐源泉失败');
|
||||
}
|
||||
}
|
||||
//冒尖小春笋好像已经被tx扬了
|
||||
// 冒尖小春笋好像已经被tx扬了 R.I.P.
|
||||
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
|
||||
HonorInfo.strong_newbie_list = [];
|
||||
}
|
||||
|
@@ -34,15 +34,10 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
const NTQQFileApi = this.core.apis.FileApi;
|
||||
let UuidData: {
|
||||
high: string;
|
||||
low: string;
|
||||
} | undefined;
|
||||
try {
|
||||
UuidData = UUIDConverter.decode(payload.file);
|
||||
if (UuidData) {
|
||||
const peerUin = UuidData.high;
|
||||
const msgId = UuidData.low;
|
||||
const uuidData = UUIDConverter.decode(payload.file);
|
||||
const peerUin = uuidData.high;
|
||||
const msgId = uuidData.low;
|
||||
const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin);
|
||||
let peer: Peer | undefined;
|
||||
//识别Peer
|
||||
@@ -79,7 +74,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
file_size: fileSize,
|
||||
file_name: fileName,
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/ && downloadPath) {
|
||||
if (/* enableLocalFile2Url && */ downloadPath) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
@@ -88,7 +83,6 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
}
|
||||
//不手动删除?文件持久化了
|
||||
return res;
|
||||
}
|
||||
} catch {
|
||||
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_name: NTSearchNameResult[0].fileName,
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/ && downloadPath) {
|
||||
if (/* enableLocalFile2Url && */ downloadPath) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
@@ -130,66 +124,6 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
return res;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,16 +20,12 @@ export default class SendLike extends BaseAction<Payload, null> {
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
//logDebug('点赞参数', payload);
|
||||
try {
|
||||
const qq = payload.user_id.toString();
|
||||
const uid: string = await NTQQUserApi.getUidByUinV2(qq) || '';
|
||||
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
||||
//logDebug('点赞结果', result);
|
||||
if (result.result !== 0) {
|
||||
throw Error(result.errMsg);
|
||||
}
|
||||
} catch (e) {
|
||||
throw `点赞失败 ${e}`;
|
||||
throw `点赞失败 ${result.errMsg}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -89,9 +89,10 @@ export class OneBotGroupApi {
|
||||
parseInt(memberUin),
|
||||
parseInt(operatorUin),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
@@ -118,7 +119,6 @@ export class OneBotGroupApi {
|
||||
attributeNamePrefix: '',
|
||||
}).parse(grayTipElement.xmlElement.content);
|
||||
this.core.context.logger.logDebug('收到表情回应我的消息', emojiLikeData);
|
||||
try {
|
||||
const senderUin = emojiLikeData.gtip.qq.jp;
|
||||
const msgSeq = emojiLikeData.gtip.url.msgseq;
|
||||
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];
|
||||
//console.log("表情回应消息长度检测", msgSeq, replyMsg.elements);
|
||||
if (!replyMsg) throw new Error('找不到回应消息');
|
||||
if (!replyMsg) {
|
||||
this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息');
|
||||
return undefined;
|
||||
}
|
||||
return new OB11GroupMsgEmojiLikeEvent(
|
||||
this.core,
|
||||
parseInt(GroupCode),
|
||||
@@ -144,9 +147,5 @@ export class OneBotGroupApi {
|
||||
count: 1,
|
||||
}],
|
||||
);
|
||||
} catch (e: any) {
|
||||
this.core.context.logger.logError('解析表情回应消息失败', e.stack);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user