Brozy123 commited on
Commit
501b7b6
·
verified ·
1 Parent(s): 5205a89

Create grant_system.js

Browse files
Files changed (1) hide show
  1. grant_system.js +51 -0
grant_system.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const storage = require('./storage');
2
+
3
+ /**
4
+ * grant_system.js
5
+ * Manages administrative access to sensitive global commands like !servers
6
+ */
7
+
8
+ // Initialize storage if needed
9
+ if (!storage.data.settings) storage.data.settings = {};
10
+ if (!storage.data.settings.serverViewers) storage.data.settings.serverViewers = [];
11
+
12
+ async function grantAccess(client, userId, grantorId) {
13
+ const app = await client.application.fetch();
14
+ const ownerId = app.owner?.ownerId || app.owner?.id;
15
+
16
+ // Only owner can grant
17
+ if (grantorId !== ownerId) return { success: false, message: "Only the Bot Owner can grant access." };
18
+
19
+ if (!storage.data.settings.serverViewers.includes(userId)) {
20
+ storage.data.settings.serverViewers.push(userId);
21
+ storage.save('settings');
22
+ return { success: true, message: `Access granted to <@${userId}>.` };
23
+ }
24
+ return { success: false, message: "User already has access." };
25
+ }
26
+
27
+ async function revokeAccess(client, userId, grantorId) {
28
+ const app = await client.application.fetch();
29
+ const ownerId = app.owner?.ownerId || app.owner?.id;
30
+
31
+ if (grantorId !== ownerId) return { success: false, message: "Only the Bot Owner can revoke access." };
32
+
33
+ const index = storage.data.settings.serverViewers.indexOf(userId);
34
+ if (index > -1) {
35
+ storage.data.settings.serverViewers.splice(index, 1);
36
+ storage.save('settings');
37
+ return { success: true, message: `Access revoked for <@${userId}>.` };
38
+ }
39
+ return { success: false, message: "User does not have access." };
40
+ }
41
+
42
+ function hasAccess(userId, ownerId) {
43
+ if (userId === ownerId) return true;
44
+ return storage.data.settings.serverViewers.includes(userId);
45
+ }
46
+
47
+ module.exports = {
48
+ grantAccess,
49
+ revokeAccess,
50
+ hasAccess
51
+ };