Spaces:
Runtime error
Runtime error
Download roleStorage.js from Brozy123/LineUp-Bot: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/refs%2Fpr%2F1/roleStorage.js
- Command line
-
hf download hf://spaces/Brozy123/LineUp-Bot@refs/pr/1/roleStorage.js
-
curl -L -o roleStorage.js https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/refs%2Fpr%2F1/roleStorage.js
1.41 kB
| const fs = require('fs'); | |
| const path = require('path'); | |
| class RoleManager { | |
| constructor() { | |
| this.file = path.join(__dirname, 'data', 'roles.json'); | |
| this.roles = {}; | |
| this.load(); | |
| } | |
| load() { | |
| if (fs.existsSync(this.file)) { | |
| try { | |
| this.roles = JSON.parse(fs.readFileSync(this.file, 'utf8')); | |
| } catch (e) { | |
| this.roles = {}; | |
| } | |
| } | |
| } | |
| save() { | |
| // Ensure data directory exists | |
| const dir = path.dirname(this.file); | |
| if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); | |
| fs.writeFileSync(this.file, JSON.stringify(this.roles, null, 2)); | |
| } | |
| addRole(guildId, roleId) { | |
| if (!this.roles[guildId]) this.roles[guildId] = []; | |
| if (!this.roles[guildId].includes(roleId)) { | |
| this.roles[guildId].push(roleId); | |
| this.save(); | |
| } | |
| } | |
| removeRole(guildId, roleId) { | |
| if (!this.roles[guildId]) return; | |
| this.roles[guildId] = this.roles[guildId].filter(id => id !== roleId); | |
| this.save(); | |
| } | |
| isWhitelisted(guildId, member) { | |
| if (member.permissions.has('Administrator')) return true; | |
| const allowedRoles = this.roles[guildId] || []; | |
| return member.roles.cache.some(r => allowedRoles.includes(r.id)); | |
| } | |
| } | |
| module.exports = new RoleManager(); | |