mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge remote-tracking branch 'origin/v3.4.0' into v3.4.0
# Conflicts: # src/common/config.ts
This commit is contained in:
@@ -4,19 +4,21 @@ import {mergeNewProperties} from "./utils";
|
||||
const fs = require("fs");
|
||||
|
||||
export class ConfigUtil {
|
||||
configPath: string;
|
||||
private readonly configPath: string;
|
||||
private config: Config | null = null;
|
||||
|
||||
constructor(configPath: string) {
|
||||
this.configPath = configPath;
|
||||
}
|
||||
getConfig(){
|
||||
try {
|
||||
return this._getConfig()
|
||||
}catch (e) {
|
||||
console.log("获取配置文件出错", e)
|
||||
if (this.config) {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
this.config = this.reloadConfig();
|
||||
return this.config;
|
||||
}
|
||||
_getConfig(): Config {
|
||||
reloadConfig(): Config {
|
||||
let ob11Default: OB11Config = {
|
||||
httpPort: 3000,
|
||||
httpHosts: [],
|
||||
@@ -55,6 +57,7 @@ export class ConfigUtil {
|
||||
}
|
||||
|
||||
setConfig(config: Config) {
|
||||
this.config = config;
|
||||
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user