From 9e05e086ebc9f5f3e91bf132c206fc54c31da165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 4 Aug 2024 15:01:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/QQBasicInfo.ts | 6 +++--- src/core/src/apis/friend.ts | 6 +++++- src/onebot11/action/msg/SendMsg/index.ts | 10 ++-------- src/onebot11/action/user/GetFriendList.ts | 1 + 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/common/utils/QQBasicInfo.ts b/src/common/utils/QQBasicInfo.ts index bdcfac4a..3a121d85 100644 --- a/src/common/utils/QQBasicInfo.ts +++ b/src/common/utils/QQBasicInfo.ts @@ -3,7 +3,7 @@ import fs from 'node:fs'; import { systemPlatform } from '@/common/utils/system'; import { getDefaultQQVersionConfigInfo, getQQVersionConfigPath } from './helper'; import AppidTable from '@/core/external/appid.json'; -import { logNotice } from '@/onebot11/log'; +import { log } from './log'; //基础目录获取 export let QQMainPath = process.execPath; @@ -11,9 +11,9 @@ export let QQPackageInfoPath: string = path.join(path.dirname(QQMainPath), 'reso export let QQVersionConfigPath: string | undefined = getQQVersionConfigPath(QQMainPath); //基础信息获取 无快更则启用默认模板填充 -export let { appid: QQVersionAppid, qua: QQVersionQua } = getAppidV2(); export let isQuickUpdate: boolean = !!QQVersionConfigPath; export let QQVersionConfig: QQVersionConfigType = isQuickUpdate ? JSON.parse(fs.readFileSync(QQVersionConfigPath!).toString()) : getDefaultQQVersionConfigInfo(); +export let { appid: QQVersionAppid, qua: QQVersionQua } = getAppidV2(); export let QQPackageInfo: QQPackageInfoType = JSON.parse(fs.readFileSync(QQPackageInfoPath).toString()); //基础函数 @@ -39,7 +39,7 @@ export function getAppidV2(): { appid: string, qua: string } { } } catch (e) { - logNotice('[QQ版本兼容性检测] 版本兼容性不佳,可能会导致一些功能无法正常使用'); + log('[QQ版本兼容性检测] 版本兼容性不佳,可能会导致一些功能无法正常使用', e); } // 以下是兜底措施 return { appid: systemPlatform === 'linux' ? '537237950' : '537237765', qua: getQUAInternal() }; diff --git a/src/core/src/apis/friend.ts b/src/core/src/apis/friend.ts index 047000be..41053001 100644 --- a/src/core/src/apis/friend.ts +++ b/src/core/src/apis/friend.ts @@ -1,9 +1,13 @@ import { FriendRequest, User } from '@/core/entities'; -import { BuddyListReqType, napCatCore, OnBuddyChangeParams } from '@/core'; +import { BuddyListReqType, napCatCore, NodeIKernelBuddyListener, OnBuddyChangeParams } from '@/core'; import { NTEventDispatch } from '@/common/utils/EventTask'; export class NTQQFriendApi { static async getBuddyV2(refresh = false) { + NTEventDispatch.RegisterListen('NodeIKernelBuddyListener/onBuddyListChange', 1, 5000, (arg: OnBuddyChangeParams) => { + console.log(arg); + return true; + }).catch().then(); if (!refresh) { return await napCatCore.session.getBuddyService().getBuddyListFromCache('0'); } diff --git a/src/onebot11/action/msg/SendMsg/index.ts b/src/onebot11/action/msg/SendMsg/index.ts index ced34a79..0b557dcf 100644 --- a/src/onebot11/action/msg/SendMsg/index.ts +++ b/src/onebot11/action/msg/SendMsg/index.ts @@ -10,6 +10,7 @@ import { ActionName, BaseCheckResult } from '@/onebot11/action/types'; import { getGroup } from '@/core/data'; import { ChatType, ElementType, Group, NTQQFileApi, NTQQFriendApi, NTQQMsgApi, NTQQUserApi, Peer, SendMessageElement, } from '@/core'; import fs from 'node:fs'; +import fsPromise from 'node:fs/promises'; import { logDebug, logError } from '@/common/utils/log'; import { decodeCQCode } from '@/onebot11/cqcode'; import createSendElements from './create-send-elements'; @@ -71,14 +72,7 @@ export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], de logDebug('发送消息id获取失败', e); returnMsg!.id = 0; } - - deleteAfterSentFiles.map((f) => { - try { - fs.unlinkSync(f); - } catch (e) { - logError('发送消息删除文件失败', e); - } - }); + deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logError('发送消息删除文件失败', e)); }); return returnMsg; } diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index 4cd9acd2..278f15fb 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -20,6 +20,7 @@ export default class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList; PayloadSchema = SchemaData; protected async _handle(payload: Payload) { + let data = await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache=== 'true'); if (friends.size === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { const _friends = await NTQQFriendApi.getFriends(true); // log('强制刷新好友列表,结果: ', _friends)