Spaces:
Runtime error
Runtime error
File size: 1,766 Bytes
501b7b6 87adf76 | 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 45 46 47 48 49 50 51 | 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
}; |