diff --git a/src/common/qq-basic-info.ts b/src/common/qq-basic-info.ts index cb39d6be2..c1575d19a 100644 --- a/src/common/qq-basic-info.ts +++ b/src/common/qq-basic-info.ts @@ -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版本获取失败'); + const fullVersion = this.getFullQQVesion(); + 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() }; } } diff --git a/src/core/apis/webapi.ts b/src/core/apis/webapi.ts index f544cede1..b75c97709 100644 --- a/src/core/apis/webapi.ts +++ b/src/core/apis/webapi.ts @@ -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('获取龙王信息失败'); - } + const RetInternal = await getDataInternal(groupCode, 1); + 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('获取群聊之火失败'); - } + const RetInternal = await getDataInternal(groupCode, 2); + 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('获取群聊炽焰失败'); - } + const RetInternal = await getDataInternal(groupCode, 3); + 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('获取快乐源泉失败'); - } + const RetInternal = await getDataInternal(groupCode, 6); + 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 = []; } diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index 759691e4f..892030bb3 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -34,61 +34,55 @@ export class GetFileBase extends BaseAction { 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 isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin); - let peer: Peer | undefined; - //识别Peer - if (isGroup) { - peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: peerUin }; - } - const PeerUid = await NTQQUserApi.getUidByUinV2(peerUin); - if (PeerUid) { - const isBuddy = await NTQQFriendApi.isBuddy(PeerUid); - if (isBuddy) { - peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: PeerUid }; - } else { - peer = { chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: PeerUid }; - } - } - if (!peer) { - throw new Error('chattype not support'); - } - const msgList = await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]); - if (msgList.msgList.length == 0) { - throw new Error('msg not found'); - } - const msg = msgList.msgList[0]; - const findEle = msg.elements.find(e => e.elementType == ElementType.VIDEO || e.elementType == ElementType.FILE || e.elementType == ElementType.PTT); - if (!findEle) { - throw new Error('element not found'); + 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 + if (isGroup) { + peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: peerUin }; + } + const PeerUid = await NTQQUserApi.getUidByUinV2(peerUin); + if (PeerUid) { + const isBuddy = await NTQQFriendApi.isBuddy(PeerUid); + if (isBuddy) { + peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: PeerUid }; + } else { + peer = { chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: PeerUid }; } - const downloadPath = await NTQQFileApi.downloadMedia(msgId, msg.chatType, msg.peerUid, findEle.elementId, '', ''); - const fileSize = findEle?.videoElement?.fileSize || findEle?.fileElement?.fileSize || findEle?.pttElement?.fileSize || '0'; - const fileName = findEle?.videoElement?.fileName || findEle?.fileElement?.fileName || findEle?.pttElement?.fileName || ''; - const res: GetFileResponse = { - file: downloadPath, - url: downloadPath, - file_size: fileSize, - file_name: fileName, - }; - if (true/*enableLocalFile2Url*/ && downloadPath) { - try { - res.base64 = await fs.readFile(downloadPath, 'base64'); - } catch (e) { - throw new Error('文件下载失败. ' + e); - } + } + if (!peer) { + throw new Error('chattype not support'); + } + const msgList = await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]); + if (msgList.msgList.length == 0) { + throw new Error('msg not found'); + } + const msg = msgList.msgList[0]; + const findEle = msg.elements.find(e => e.elementType == ElementType.VIDEO || e.elementType == ElementType.FILE || e.elementType == ElementType.PTT); + if (!findEle) { + throw new Error('element not found'); + } + const downloadPath = await NTQQFileApi.downloadMedia(msgId, msg.chatType, msg.peerUid, findEle.elementId, '', ''); + const fileSize = findEle?.videoElement?.fileSize || findEle?.fileElement?.fileSize || findEle?.pttElement?.fileSize || '0'; + const fileName = findEle?.videoElement?.fileName || findEle?.fileElement?.fileName || findEle?.pttElement?.fileName || ''; + const res: GetFileResponse = { + file: downloadPath, + url: downloadPath, + file_size: fileSize, + file_name: fileName, + }; + if (/* enableLocalFile2Url && */ downloadPath) { + try { + res.base64 = await fs.readFile(downloadPath, 'base64'); + } catch (e) { + throw new Error('文件下载失败. ' + e); } - //不手动删除?文件持久化了 - return res; } + //不手动删除?文件持久化了 + return res; } catch { this.core.context.logger.logDebug('GetFileBase Mode - 1 Error'); } @@ -119,7 +113,7 @@ export class GetFileBase extends BaseAction { 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 { 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; } } diff --git a/src/onebot/action/user/SendLike.ts b/src/onebot/action/user/SendLike.ts index 41f8210f2..f6b4551c2 100644 --- a/src/onebot/action/user/SendLike.ts +++ b/src/onebot/action/user/SendLike.ts @@ -20,16 +20,12 @@ export default class SendLike extends BaseAction { async _handle(payload: Payload): Promise { 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}`; + 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 `点赞失败 ${result.errMsg}`; } return null; } diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index bf7509bc4..b9538b7b0 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -89,8 +89,9 @@ export class OneBotGroupApi { parseInt(memberUin), parseInt(operatorUin), ); + } else { + return undefined; } - return undefined; } async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) { @@ -118,35 +119,33 @@ 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; - const peer = { - chatType: ChatType.KCHATTYPEGROUP, - guildId: '', - peerUid: GroupCode, - }; - const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, msgSeq)).msgList; - if (replyMsgList.length < 1) { - return; - } - 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('找不到回应消息'); - return new OB11GroupMsgEmojiLikeEvent( - this.core, - parseInt(GroupCode), - parseInt(senderUin), - MessageUnique.getShortIdByMsgId(replyMsg.msgId)!, - [{ - emoji_id: emojiId, - count: 1, - }], - ); - } catch (e: any) { - this.core.context.logger.logError('解析表情回应消息失败', e.stack); + const senderUin = emojiLikeData.gtip.qq.jp; + const msgSeq = emojiLikeData.gtip.url.msgseq; + const emojiId = emojiLikeData.gtip.face.id; + const peer = { + chatType: ChatType.KCHATTYPEGROUP, + guildId: '', + peerUid: GroupCode, + }; + const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, msgSeq)).msgList; + if (replyMsgList.length < 1) { + return; } - return undefined; + 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) { + this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息'); + return undefined; + } + return new OB11GroupMsgEmojiLikeEvent( + this.core, + parseInt(GroupCode), + parseInt(senderUin), + MessageUnique.getShortIdByMsgId(replyMsg.msgId)!, + [{ + emoji_id: emojiId, + count: 1, + }], + ); } }