level-system-phoenix
Version:
Ein Levelsystem für WhatsApp Bots mit Baileys und Command-Handlern inklusive Cheat-Schutz, XP, Ränge und Speicher.
30 lines (28 loc) • 806 B
JavaScript
const fs = require('fs');
const path = require('path');
class Storage {
constructor(dataFile = path.join(__dirname, '../../../database/', 'leveldata.json')) {
this.dataFile = dataFile;
this.data = {};
this._load();
}
_load() {
if (fs.existsSync(this.dataFile)) {
this.data = JSON.parse(fs.readFileSync(this.dataFile, 'utf-8'));
}
}
_save() {
fs.writeFileSync(this.dataFile, JSON.stringify(this.data, null, 2), 'utf-8');
}
getUser(userId) {
if (!this.data[userId]) {
this.data[userId] = { xp: 0, level: 1, lastXP: 0 };
}
return this.data[userId];
}
updateUser(userId, userData) {
this.data[userId] = userData;
this._save();
}
}
module.exports = Storage;