From 946f12cf6a0cf9080dc06d9b0d7bf2fcec593827 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: Fri, 9 Aug 2024 11:11:45 +0800 Subject: [PATCH] =?UTF-8?q?remove:=20core=E4=B8=8D=E8=A6=81=E5=B9=B2?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E4=BA=8B=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/core.ts | 32 +++++++++++++++++--------------- src/core/entities/user.ts | 10 ++++++++++ src/core/listeners/index.ts | 1 + 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/core/core.ts b/src/core/core.ts index c54ab644..be71fda4 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -4,9 +4,9 @@ import fs from "node:fs"; import { InstanceContext } from "./wrapper"; import { NTEventChannel } from "@/common/framework/event"; import { proxiedListenerOf } from "@/common/utils/proxy-handler"; -import { MsgListener } from "./listeners"; +import { MsgListener, ProfileListener } from "./listeners"; import { sleep } from "@/common/utils/helper"; -import { SelfInfo, LineDevice } from "./entities"; +import { SelfInfo, LineDevice, SelfStatusInfo } from "./entities"; export enum NapCatCoreWorkingEnv { Unknown = 0, @@ -30,12 +30,6 @@ export class NapCatCore { // runtime info, not readonly selfInfo: SelfInfo; - deviceList: { - app_id: string, - device_name: string, - device_kind: string - }[] = []; - // 通过构造器递过去的 runtime info 应该尽量少 constructor(context: InstanceContext, selfInfo: SelfInfo) { this.selfInfo = selfInfo; @@ -50,16 +44,24 @@ export class NapCatCore { msgListener.onRecvMsg = (msg) => { console.log("RecvMsg", msg); } - msgListener.onLineDev = (devices: LineDevice[]) => { - this.deviceList = devices.map((device: LineDevice) => ({ - app_id: device.devUid, - device_name: device.clientType.toString(), - device_kind: device.clientType.toString(), - })); - }; //await sleep(2500); this.context.session.getMsgService().addKernelMsgListener( new this.context.wrapper.NodeIKernelMsgListener(proxiedListenerOf(msgListener, this.context.logger)) ); + + const profileListener = new ProfileListener(); + profileListener.onProfileDetailInfoChanged = (profile) => { + if (profile.uid === this.selfInfo.uid) { + Object.assign(this.selfInfo, profile); + } + }; + profileListener.onSelfStatusChanged = (Info: SelfStatusInfo) => { + // if (Info.status == 20) { + // log("账号状态变更为离线") + // } + }; + this.context.session.getProfileService().addKernelProfileListener( + new this.context.wrapper.NodeIKernelProfileListener(proxiedListenerOf(profileListener, this.context.logger)) + ); } } diff --git a/src/core/entities/user.ts b/src/core/entities/user.ts index 6dac7b30..0658ac6f 100644 --- a/src/core/entities/user.ts +++ b/src/core/entities/user.ts @@ -177,6 +177,16 @@ export interface FriendV2 extends SimpleInfo { categoryId?: number; categroyName?: string; } +export interface SelfStatusInfo { + uid: string + status: number + extStatus: number + termType: number + netType: number + iconType: number + customStatus: any + setTime: string + } export interface UserDetailInfoListenerArg { uid: string; uin: string; diff --git a/src/core/listeners/index.ts b/src/core/listeners/index.ts index cc8ad4a2..1d06ea02 100644 --- a/src/core/listeners/index.ts +++ b/src/core/listeners/index.ts @@ -6,6 +6,7 @@ export * from './NodeIKernelGroupListener'; export * from './NodeIKernelBuddyListener'; export * from './NodeIKernelProfileListener'; export * from './NodeIKernelRobotListener'; +export * from './NodeIKernelProfileListener'; export * from './NodeIKernelTicketListener'; export * from './NodeIKernelStorageCleanListener'; export * from './NodeIKernelFileAssistantListener';