refactor: make ConfigBase abstract

This commit is contained in:
Wesley F. Young 2024-08-12 00:26:44 +08:00
parent 23ee480c4f
commit ef4dee8886
4 changed files with 6 additions and 15 deletions

View File

@ -2,17 +2,13 @@ import path from 'node:path';
import fs from 'node:fs';
import type { NapCatCore } from '@/core';
export class ConfigBase<T> {
name: string = this.getConfigName();
export abstract class ConfigBase<T> {
abstract name: string;
pathName: string | null = null; // 本次读取的文件路径
coreContext: NapCatCore;
configPath: string;
configData: T = {} as T;
getConfigName() {
return this.constructor.name
}
constructor(coreContext: NapCatCore, configPath: string) {
this.coreContext = coreContext;
this.configPath = configPath;
@ -25,7 +21,6 @@ export class ConfigBase<T> {
return null;
}
getConfigPath(pathName: string | undefined): string {
const suffix = pathName ? `_${pathName}` : '';
const filename = `${this.name}${suffix}.json`;

View File

@ -11,7 +11,5 @@ export interface NapCatConfig {
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class NapCatConfig extends ConfigBase<NapCatConfig> {
getConfigName() {
return 'napcat';
}
name = 'napcat';
}

View File

@ -36,7 +36,5 @@ export interface OB11Config {
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class OB11Config extends ConfigBase<OB11Config> {
getConfigName() {
return 'onebot11';
}
name = 'onebot11';
}

View File

@ -1,5 +1,4 @@
import { OB11Config } from "@/onebot/helper/config";
import { OB11Config } from '@/onebot/helper/config';
interface LoginRuntimeType {
LoginCurrentTime: number;
@ -30,6 +29,7 @@ const LoginRuntime: LoginRuntimeType = {
QQLoginList: [],
},
};
export const WebUiDataRuntime = {
checkLoginRate: async function(RateLimit: number): Promise<boolean> {
LoginRuntime.LoginCurrentRate++;