File size: 1,197 Bytes
f19cc50
 
 
 
 
480a4f9
f19cc50
 
480a4f9
f19cc50
 
 
 
 
 
 
 
480a4f9
 
 
 
 
 
 
f19cc50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import fs from "fs";
import path from "path";

const filePath = path.resolve("./guildConfigs.json");

// Domyślne ustawienia (teraz modele są zapisywane dynamicznie w obiekcie)
export const DEFAULT_CONFIG = {
	logChannelId: null,
	models: {} 
};

export function loadConfig(guildId) {
	if (!fs.existsSync(filePath)) {
		fs.writeFileSync(filePath, JSON.stringify({}));
	}
	try {
		const data = JSON.parse(fs.readFileSync(filePath, "utf-8"));
		const config = data[guildId] || { ...DEFAULT_CONFIG };
		
		// Upewniamy się, że obiekt "models" zawsze istnieje
		if (!config.models) {
			config.models = {};
		}
		return config;
	} catch (err) {
		console.error("Błąd podczas odczytu konfiguracji:", err);
		return { ...DEFAULT_CONFIG };
	}
}

export function saveConfig(guildId, newConfig) {
	if (!fs.existsSync(filePath)) {
		fs.writeFileSync(filePath, JSON.stringify({}));
	}
	try {
		const data = JSON.parse(fs.readFileSync(filePath, "utf-8"));
		data[guildId] = { ...DEFAULT_CONFIG, ...data[guildId], ...newConfig };
		fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
		return true;
	} catch (err) {
		console.error("Błąd podczas zapisu konfiguracji:", err);
		return false;
	}
}