Files
LLOneBot/src/main/config.ts
linyuchen 0c131ff555 fix: get_group_member_list, send_private_msg, send_group_msg.
feat: auto identify qq to read config
2023-12-02 11:58:50 +08:00

29 lines
722 B
TypeScript

import {Config} from "../common/types";
const fs = require("fs")
export class ConfigUtil{
configPath: string;
constructor(configPath: string) {
this.configPath = configPath;
}
getConfig(): Config{
if (!fs.existsSync(this.configPath)) {
return {port:3000, hosts: ["http://192.168.1.2:5000/"]}
} else {
const data = fs.readFileSync(this.configPath, "utf-8");
let jsonData =JSON.parse(data);
if (!jsonData.hosts){
jsonData.hosts = []
}
return jsonData;
}
}
setConfig(config: Config){
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
}
}