Spaces:
Runtime error
Runtime error
File size: 1,065 Bytes
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 | import fs from "fs";
import path from "path";
const filePath = path.resolve("./guildConfigs.json");
export const DEFAULT_CONFIG = {
logChannelId: null,
textModel: "yaya36095/xlm-roberta-text-detector",
imageModel: "capcheck/ai-image-detection"
};
export function loadConfig(guildId) {
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, JSON.stringify({}));
}
try {
const data = JSON.parse(fs.readFileSync(filePath, "utf-8"));
return data[guildId] || { ...DEFAULT_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;
}
} |