diff --git a/src/core/core.ts b/src/core/core.ts index 28e49363..40cdd204 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -6,6 +6,7 @@ import { NTEventChannel } from "@/common/framework/event"; import { proxiedListenerOf } from "@/common/utils/proxy-handler"; import { MsgListener } from "./listeners"; import { sleep } from "@/common/utils/helper"; +import { CoreCache, LineDevice } from "./entities"; export enum NapCatCoreWorkingEnv { Unknown = 0, @@ -26,22 +27,42 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi { export class NapCatCore { readonly context: InstanceContext; readonly eventChannel: NTEventChannel; - + readonly cache: CoreCache; constructor(context: InstanceContext) { this.context = context; this.eventChannel = new NTEventChannel(context.wrapper, context.session); + this.cache = { + selfInfo: { + uid: "", + uin: "", + nick: "" + }, + DeviceList: [] + } this.initNapCatCoreListeners().then().catch(console.error); + } // Renamed from 'InitDataListener' async initNapCatCoreListeners() { - let msg = new MsgListener(); - msg.onRecvMsg = (msg) => { + let msgListener = new MsgListener(); + msgListener.onRecvMsg = (msg) => { console.log("RecvMsg", msg); } + msgListener.onLineDev = (Devices: LineDevice[]) => { + this.cache.DeviceList.splice(0, this.cache.DeviceList.length); + Devices.map((Device: LineDevice) => { + let DeviceData = { + app_id: Device.devUid, + device_name: Device.clientType.toString(), + device_kind: Device.clientType.toString(), + }; + this.cache.DeviceList.push(DeviceData); + }); + }; //await sleep(2500); this.context.session.getMsgService().addKernelMsgListener( - new this.context.wrapper.NodeIKernelMsgListener(proxiedListenerOf(msg, this.context.logger)) + new this.context.wrapper.NodeIKernelMsgListener(proxiedListenerOf(msgListener, this.context.logger)) ); } } diff --git a/src/core/entities/index.ts b/src/core/entities/index.ts index 5fd551d4..1328dc77 100644 --- a/src/core/entities/index.ts +++ b/src/core/entities/index.ts @@ -2,4 +2,5 @@ export * from './user'; export * from './group'; export * from './msg'; export * from './notify'; -export * from './cache'; \ No newline at end of file +export * from './cache'; +export * from './system' \ No newline at end of file diff --git a/src/core/entities/system.ts b/src/core/entities/system.ts new file mode 100644 index 00000000..6448ac72 --- /dev/null +++ b/src/core/entities/system.ts @@ -0,0 +1,16 @@ +import { SelfInfo } from "./user" + +export interface LineDevice { + instanceId: number + clientType: number + devUid: string +} +export interface OBLineDevice { + app_id: string; + device_name: string; + device_kind: string; +} +export interface CoreCache { + selfInfo: SelfInfo, + DeviceList: OBLineDevice[] +} \ No newline at end of file diff --git a/src/core/entities/user.ts b/src/core/entities/user.ts index f80c128b..6dac7b30 100644 --- a/src/core/entities/user.ts +++ b/src/core/entities/user.ts @@ -208,6 +208,7 @@ export interface QQLevel { moonNum: number; starNum: number } + export interface User { uid: string; // 加密的字符串 uin: string; // QQ号 diff --git a/src/core/wrapper/data.ts b/src/core/wrapper/data.ts deleted file mode 100644 index 36d4a9be..00000000 --- a/src/core/wrapper/data.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { SelfInfo } from "../entities"; - -export const selfInfo: SelfInfo = { - uid: '', - uin: '', - nick: '', - online: true -}; \ No newline at end of file diff --git a/src/core/wrapper/index.ts b/src/core/wrapper/index.ts index 2f85aeac..647643c8 100644 --- a/src/core/wrapper/index.ts +++ b/src/core/wrapper/index.ts @@ -1,4 +1,3 @@ export * from './wrapper'; -export * from './data'; export * from './helper'; export * from './context'; \ No newline at end of file