-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadmin-system.js
More file actions
82 lines (69 loc) · 1.78 KB
/
Copy pathadmin-system.js
File metadata and controls
82 lines (69 loc) · 1.78 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require('fs');
const path = require('path');
class AdminSystem {
constructor() {
this.adminsPath = './data/admins.json';
this.BOT_OWNER_ID = '1383706658315960330'; // Your ID
this.ensureDataFiles();
}
ensureDataFiles() {
const dataDir = './data';
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}
if (!fs.existsSync(this.adminsPath)) {
// Initialize with bot owner
const initialData = {
[this.BOT_OWNER_ID]: {
level: 'owner',
addedBy: 'system',
addedAt: Date.now()
}
};
fs.writeFileSync(this.adminsPath, JSON.stringify(initialData, null, 2));
}
}
getAdminData() {
try {
return JSON.parse(fs.readFileSync(this.adminsPath, 'utf8'));
} catch (error) {
return {};
}
}
saveAdminData(data) {
fs.writeFileSync(this.adminsPath, JSON.stringify(data, null, 2));
}
isOwner(userId) {
return userId === this.BOT_OWNER_ID;
}
isAdmin(userId) {
const admins = this.getAdminData();
return admins[userId] || this.isOwner(userId);
}
getAdminLevel(userId) {
if (this.isOwner(userId)) return 'owner';
const admins = this.getAdminData();
return admins[userId]?.level || null;
}
addAdmin(userId, level, addedBy) {
const admins = this.getAdminData();
admins[userId] = {
level: level,
addedBy: addedBy,
addedAt: Date.now()
};
this.saveAdminData(admins);
return true;
}
removeAdmin(userId) {
if (this.isOwner(userId)) return false; // Cannot remove owner
const admins = this.getAdminData();
delete admins[userId];
this.saveAdminData(admins);
return true;
}
getAllAdmins() {
return this.getAdminData();
}
}
module.exports = AdminSystem;