refactor: Init Core

This commit is contained in:
手瓜一十雪 2024-11-14 10:43:37 +08:00
parent cbf98ffb89
commit f228129c19
3 changed files with 9 additions and 7 deletions

View File

@ -84,11 +84,10 @@ export function getMajorPath(QQVersion: string): string {
} }
export class NapCatCore { export class NapCatCore {
readonly context: InstanceContext; readonly context: InstanceContext;
readonly apis: StableNTApiWrapper;
readonly eventWrapper: NTEventWrapper; readonly eventWrapper: NTEventWrapper;
// readonly eventChannel: NTEventChannel; NapCatDataPath: string = '';
NapCatDataPath: string; NapCatTempPath: string = '';
NapCatTempPath: string; apis: StableNTApiWrapper;
// runtime info, not readonly // runtime info, not readonly
selfInfo: SelfInfo; selfInfo: SelfInfo;
util: NodeQQNTWrapperUtil; util: NodeQQNTWrapperUtil;
@ -112,6 +111,8 @@ export class NapCatCore {
UserApi: new NTQQUserApi(this.context, this), UserApi: new NTQQUserApi(this.context, this),
GroupApi: new NTQQGroupApi(this.context, this), GroupApi: new NTQQGroupApi(this.context, this),
}; };
}
async initCore() {
this.NapCatDataPath = path.join(this.dataPath, 'NapCat'); this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
fs.mkdirSync(this.NapCatDataPath, { recursive: true }); fs.mkdirSync(this.NapCatDataPath, { recursive: true });
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp'); this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
@ -133,7 +134,6 @@ export class NapCatCore {
this.configLoader.configData.consoleLogLevel as LogLevel, this.configLoader.configData.consoleLogLevel as LogLevel,
); );
} }
get dataPath(): string { get dataPath(): string {
let result = this.context.wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig(); let result = this.context.wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
if (!result) { if (!result) {

View File

@ -55,11 +55,12 @@ export async function NCoreInitFramework(
// await sleep(2500); // await sleep(2500);
// 初始化 NapCatFramework // 初始化 NapCatFramework
const loaderObject = new NapCatFramework(wrapper, session, logger, loginService, selfInfo, basicInfoWrapper, pathWrapper); const loaderObject = new NapCatFramework(wrapper, session, logger, loginService, selfInfo, basicInfoWrapper, pathWrapper);
await loaderObject.core.initCore();
//启动WebUi //启动WebUi
InitWebUi(logger, pathWrapper).then().catch(logger.logError.bind(logger)); InitWebUi(logger, pathWrapper).then().catch(logger.logError.bind(logger));
//初始化LLNC的Onebot实现 //初始化LLNC的Onebot实现
new NapCatOneBot11Adapter(loaderObject.core, loaderObject.context, pathWrapper).InitOneBot(); await new NapCatOneBot11Adapter(loaderObject.core, loaderObject.context, pathWrapper).InitOneBot();
} }
export class NapCatFramework { export class NapCatFramework {

View File

@ -292,7 +292,7 @@ export async function NCoreInitShell() {
fs.mkdirSync(dataPath, { recursive: true }); fs.mkdirSync(dataPath, { recursive: true });
logger.logDebug('本账号数据/缓存目录:', accountDataPath); logger.logDebug('本账号数据/缓存目录:', accountDataPath);
new NapCatShell( await new NapCatShell(
wrapper, wrapper,
session, session,
logger, logger,
@ -331,6 +331,7 @@ export class NapCatShell {
} }
async InitNapCat() { async InitNapCat() {
await this.core.initCore();
new NapCatOneBot11Adapter(this.core, this.context, this.context.pathWrapper).InitOneBot() new NapCatOneBot11Adapter(this.core, this.context, this.context.pathWrapper).InitOneBot()
.catch(e => this.context.logger.logError.bind(this.context.logger)('初始化OneBot失败', e)); .catch(e => this.context.logger.logError.bind(this.context.logger)('初始化OneBot失败', e));
} }