-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwhitelist.js
executable file
·52 lines (48 loc) · 1.94 KB
/
whitelist.js
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
var fs = require("fs")
function addToWhitelist(user, message) {
var whitelist = JSON.parse(fs.readFileSync("whitelist.json"));
if (whitelist.includes(user)) {
if (message != null) {
message.channel.send("<@" + message.author.id + "> " + user + " is already in the whitelist.")
}
} else {
whitelist.push(user)
fs.writeFile('whitelist.json', JSON.stringify(whitelist, null, 2), function(err) {
if (err == null) {
if (message != null) {
message.channel.send("<@" + message.author.id + "> Sucessfully added " + user + " to whitelist.")
} else {
if (message != null) {
message.channel.send("<@" + message.author.id + "> Error adding " + user + " to whitelist. Please try again")
}
}
}
})
}
}
function removeFromWhitelist(user, message) {
var whitelist = JSON.parse(fs.readFileSync("whitelist.json"));
if (whitelist.includes(user)) {
var aIndex = whitelist.indexOf(user)
if (aIndex > -1) {
whitelist.splice(aIndex, 1);
fs.writeFile('whitelist.json', JSON.stringify(whitelist, null, 2), function(err) {
if (message != null) {
if (err == null) {
message.channel.send("<@" + message.author.id + "> Sucessfully remvoed " + user + " from whitelist.")
} else {
message.channel.send("<@" + message.author.id + "> Error removing " + user + " from whitelist. Please try again")
}
}
})
}
} else {
if (message != null) {
message.channel.send("<@" + message.author.id + "> " + user + " is not in the whitelist.")
}
}
}
module.exports = {
addToWhitelist: addToWhitelist,
removeFromWhitelist: removeFromWhitelist
}