mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 04:45:46 +00:00
refactor: make selfInfo a 'runtime info'
This commit is contained in:
parent
34e4963ccd
commit
7e49bfa984
@ -1,4 +1,4 @@
|
||||
import { WrapperNodeApi } from "./wrapper/wrapper";
|
||||
import { WrapperNodeApi } from "@/core/wrapper";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import { InstanceContext } from "./wrapper";
|
||||
@ -6,7 +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";
|
||||
import { SelfInfo, LineDevice } from "./entities";
|
||||
|
||||
export enum NapCatCoreWorkingEnv {
|
||||
Unknown = 0,
|
||||
@ -27,20 +27,21 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi {
|
||||
export class NapCatCore {
|
||||
readonly context: InstanceContext;
|
||||
readonly eventChannel: NTEventChannel;
|
||||
readonly cache: CoreCache;
|
||||
constructor(context: InstanceContext) {
|
||||
|
||||
// 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;
|
||||
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'
|
||||
@ -49,16 +50,12 @@ export class NapCatCore {
|
||||
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);
|
||||
});
|
||||
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(
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { LogWrapper } from "@/common/utils/log";
|
||||
import { QQBasicInfoWrapper } from "@/common/utils/QQBasicInfo";
|
||||
import { NapCatCoreWorkingEnv } from "../core";
|
||||
import { NapCatCoreWorkingEnv } from "@/core";
|
||||
import { SelfInfo } from "../entities";
|
||||
import { NodeIKernelLoginService } from "../services";
|
||||
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "./wrapper";
|
||||
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core";
|
||||
|
||||
export interface InstanceContext {
|
||||
readonly workingEnv: NapCatCoreWorkingEnv;
|
||||
@ -11,6 +11,5 @@ export interface InstanceContext {
|
||||
readonly session: NodeIQQNTWrapperSession;
|
||||
readonly logger: LogWrapper;
|
||||
readonly loginService: NodeIKernelLoginService;
|
||||
readonly selfInfo: SelfInfo;
|
||||
readonly basicInfoWrapper: QQBasicInfoWrapper;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { NTEventChannel } from "@/common/framework/event";
|
||||
import { NapCatPathWrapper } from "@/common/framework/napcat";
|
||||
import { LogWrapper } from "@/common/utils/log";
|
||||
import { proxiedListenerOf } from "@/common/utils/proxy-handler";
|
||||
@ -61,9 +60,8 @@ export class NapCatLiteLoader {
|
||||
session,
|
||||
logger,
|
||||
loginService,
|
||||
selfInfo,
|
||||
basicInfoWrapper
|
||||
};
|
||||
this.core = new NapCatCore(this.context);
|
||||
this.core = new NapCatCore(this.context, selfInfo);
|
||||
}
|
||||
}
|
||||
|
@ -149,10 +149,9 @@ export class NapCatShell {
|
||||
session,
|
||||
logger,
|
||||
loginService,
|
||||
selfInfo,
|
||||
basicInfoWrapper
|
||||
};
|
||||
this.core = new NapCatCore(this.context);
|
||||
this.core = new NapCatCore(this.context, selfInfo);
|
||||
|
||||
new NapCatOneBot11Adapter(this.core, this.context);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user