LineUp-Bot / grant_system.js
Brozy123's picture
Update grant_system.js
87adf76 verified
Raw History Blame Contribute Delete
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
};