Spaces:
Runtime error
Runtime error
Download grant_system.js from Brozy123/LineUp-Bot: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/main/grant_system.js
- Command line
-
hf download hf://spaces/Brozy123/LineUp-Bot/grant_system.js
-
curl -L -o grant_system.js https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/main/grant_system.js
1.77 kB
| const storage = require('./storage'); | |
| /** | |
| * grant_system.js | |
| * Manages administrative access to sensitive global commands like !servers | |
| */ | |
| // Initialize storage if needed | |
| if (!storage.data.settings) storage.data.settings = {}; | |
| if (!storage.data.settings.serverViewers) storage.data.settings.serverViewers = []; | |
| async function grantAccess(client, userId, grantorId) { | |
| const app = await client.application.fetch(); | |
| const ownerId = app.owner?.ownerId || app.owner?.id; | |
| // Only owner can grant | |
| if (grantorId !== ownerId) return { success: false, message: "Only the Bot Owner can grant access." }; | |
| if (!storage.data.settings.serverViewers.includes(userId)) { | |
| storage.data.settings.serverViewers.push(userId); | |
| storage.save('settings'); | |
| return { success: true, message: `Access granted to <@${userId}>.` }; | |
| } | |
| return { success: false, message: "User already has access." }; | |
| } | |
| async function revokeAccess(client, userId, grantorId) { | |
| const app = await client.application.fetch(); | |
| const ownerId = app.owner?.ownerId || app.owner?.id; | |
| if (grantorId !== ownerId) return { success: false, message: "Only the Bot Owner can revoke access." }; | |
| const index = storage.data.settings.serverViewers.indexOf(userId); | |
| if (index > -1) { | |
| storage.data.settings.serverViewers.splice(index, 1); | |
| storage.save('settings'); | |
| return { success: true, message: `Access revoked for <@${userId}>.` }; | |
| } | |
| return { success: false, message: "User does not have access." }; | |
| } | |
| function hasAccess(userId, ownerId) { | |
| if (userId === ownerId) return true; | |
| return storage.data.settings.serverViewers.includes(userId); | |
| } | |
| module.exports = { | |
| grantAccess, | |
| revokeAccess, | |
| hasAccess | |
| }; |