fix: use constructor to pass config name

This commit is contained in:
Wesley F. Young 2024-08-12 01:08:55 +08:00
parent 6d863ac29c
commit 436249597d
3 changed files with 11 additions and 7 deletions

View File

@ -3,12 +3,13 @@ import fs from 'node:fs';
import type { NapCatCore } from '@/core';
export abstract class ConfigBase<T> {
abstract name: string;
name: string;
coreContext: NapCatCore;
configPath: string;
configData: T = {} as T;
constructor(coreContext: NapCatCore, configPath: string) {
protected constructor(name: string, coreContext: NapCatCore, configPath: string) {
this.name = name;
this.coreContext = coreContext;
this.configPath = configPath;
fs.mkdirSync(this.configPath, { recursive: true });

View File

@ -1,11 +1,13 @@
import { ConfigBase } from "@/common/utils/ConfigBase";
import { LogLevel } from "@/common/utils/log";
import napCatDefaultConfig from '@/core/external/napcat.json';
import { NapCatCore } from '@/core';
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export type NapCatConfig = typeof napCatDefaultConfig;
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class NapCatConfigLoader extends ConfigBase<NapCatConfig> {
name = 'napcat';
constructor(coreContext: NapCatCore, configPath: string) {
super('napcat', coreContext, configPath);
}
}

View File

@ -1,10 +1,11 @@
import { ConfigBase } from '@/common/utils/ConfigBase';
import ob11DefaultConfig from '@/onebot/external/onebot11.json';
import { NapCatCore } from '@/core';
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export type OB11Config = typeof ob11DefaultConfig;
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class OB11ConfigLoader extends ConfigBase<OB11Config> {
name = 'onebot11';
constructor(coreContext: NapCatCore, configPath: string) {
super('onebot11', coreContext, configPath);
}
}