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 path from "node:path";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { InstanceContext } from "./wrapper";
|
import { InstanceContext } from "./wrapper";
|
||||||
@ -6,7 +6,7 @@ import { NTEventChannel } from "@/common/framework/event";
|
|||||||
import { proxiedListenerOf } from "@/common/utils/proxy-handler";
|
import { proxiedListenerOf } from "@/common/utils/proxy-handler";
|
||||||
import { MsgListener } from "./listeners";
|
import { MsgListener } from "./listeners";
|
||||||
import { sleep } from "@/common/utils/helper";
|
import { sleep } from "@/common/utils/helper";
|
||||||
import { CoreCache, LineDevice } from "./entities";
|
import { SelfInfo, LineDevice } from "./entities";
|
||||||
|
|
||||||
export enum NapCatCoreWorkingEnv {
|
export enum NapCatCoreWorkingEnv {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
@ -27,20 +27,21 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi {
|
|||||||
export class NapCatCore {
|
export class NapCatCore {
|
||||||
readonly context: InstanceContext;
|
readonly context: InstanceContext;
|
||||||
readonly eventChannel: NTEventChannel;
|
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.context = context;
|
||||||
this.eventChannel = new NTEventChannel(context.wrapper, context.session);
|
this.eventChannel = new NTEventChannel(context.wrapper, context.session);
|
||||||
this.cache = {
|
|
||||||
selfInfo: {
|
|
||||||
uid: "",
|
|
||||||
uin: "",
|
|
||||||
nick: ""
|
|
||||||
},
|
|
||||||
DeviceList: []
|
|
||||||
}
|
|
||||||
this.initNapCatCoreListeners().then().catch(console.error);
|
this.initNapCatCoreListeners().then().catch(console.error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renamed from 'InitDataListener'
|
// Renamed from 'InitDataListener'
|
||||||
@ -49,16 +50,12 @@ export class NapCatCore {
|
|||||||
msgListener.onRecvMsg = (msg) => {
|
msgListener.onRecvMsg = (msg) => {
|
||||||
console.log("RecvMsg", msg);
|
console.log("RecvMsg", msg);
|
||||||
}
|
}
|
||||||
msgListener.onLineDev = (Devices: LineDevice[]) => {
|
msgListener.onLineDev = (devices: LineDevice[]) => {
|
||||||
this.cache.DeviceList.splice(0, this.cache.DeviceList.length);
|
this.deviceList = devices.map((device: LineDevice) => ({
|
||||||
Devices.map((Device: LineDevice) => {
|
app_id: device.devUid,
|
||||||
let DeviceData = {
|
device_name: device.clientType.toString(),
|
||||||
app_id: Device.devUid,
|
device_kind: device.clientType.toString(),
|
||||||
device_name: Device.clientType.toString(),
|
}));
|
||||||
device_kind: Device.clientType.toString(),
|
|
||||||
};
|
|
||||||
this.cache.DeviceList.push(DeviceData);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
//await sleep(2500);
|
//await sleep(2500);
|
||||||
this.context.session.getMsgService().addKernelMsgListener(
|
this.context.session.getMsgService().addKernelMsgListener(
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { LogWrapper } from "@/common/utils/log";
|
import { LogWrapper } from "@/common/utils/log";
|
||||||
import { QQBasicInfoWrapper } from "@/common/utils/QQBasicInfo";
|
import { QQBasicInfoWrapper } from "@/common/utils/QQBasicInfo";
|
||||||
import { NapCatCoreWorkingEnv } from "../core";
|
import { NapCatCoreWorkingEnv } from "@/core";
|
||||||
import { SelfInfo } from "../entities";
|
import { SelfInfo } from "../entities";
|
||||||
import { NodeIKernelLoginService } from "../services";
|
import { NodeIKernelLoginService } from "../services";
|
||||||
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "./wrapper";
|
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core";
|
||||||
|
|
||||||
export interface InstanceContext {
|
export interface InstanceContext {
|
||||||
readonly workingEnv: NapCatCoreWorkingEnv;
|
readonly workingEnv: NapCatCoreWorkingEnv;
|
||||||
@ -11,6 +11,5 @@ export interface InstanceContext {
|
|||||||
readonly session: NodeIQQNTWrapperSession;
|
readonly session: NodeIQQNTWrapperSession;
|
||||||
readonly logger: LogWrapper;
|
readonly logger: LogWrapper;
|
||||||
readonly loginService: NodeIKernelLoginService;
|
readonly loginService: NodeIKernelLoginService;
|
||||||
readonly selfInfo: SelfInfo;
|
|
||||||
readonly basicInfoWrapper: QQBasicInfoWrapper;
|
readonly basicInfoWrapper: QQBasicInfoWrapper;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { NTEventChannel } from "@/common/framework/event";
|
|
||||||
import { NapCatPathWrapper } from "@/common/framework/napcat";
|
import { NapCatPathWrapper } from "@/common/framework/napcat";
|
||||||
import { LogWrapper } from "@/common/utils/log";
|
import { LogWrapper } from "@/common/utils/log";
|
||||||
import { proxiedListenerOf } from "@/common/utils/proxy-handler";
|
import { proxiedListenerOf } from "@/common/utils/proxy-handler";
|
||||||
@ -61,9 +60,8 @@ export class NapCatLiteLoader {
|
|||||||
session,
|
session,
|
||||||
logger,
|
logger,
|
||||||
loginService,
|
loginService,
|
||||||
selfInfo,
|
|
||||||
basicInfoWrapper
|
basicInfoWrapper
|
||||||
};
|
};
|
||||||
this.core = new NapCatCore(this.context);
|
this.core = new NapCatCore(this.context, selfInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,10 +149,9 @@ export class NapCatShell {
|
|||||||
session,
|
session,
|
||||||
logger,
|
logger,
|
||||||
loginService,
|
loginService,
|
||||||
selfInfo,
|
|
||||||
basicInfoWrapper
|
basicInfoWrapper
|
||||||
};
|
};
|
||||||
this.core = new NapCatCore(this.context);
|
this.core = new NapCatCore(this.context, selfInfo);
|
||||||
|
|
||||||
new NapCatOneBot11Adapter(this.core, this.context);
|
new NapCatOneBot11Adapter(this.core, this.context);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user