-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.js
97 lines (97 loc) · 2.8 KB
/
gen.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Main System Dont Touch \\
const fs = require("fs");
const config = require("./premium.json");
const checkpremium = config.id
module.exports = {
getAlt: type => {
if (!fs.existsSync(`./alts/${type}.txt`)) return "";
else {
let alts = module.exports.readFile(type).filter(r => r !== "");
let rnd = Math.floor(Math.random() * alts.length);
return alts[rnd];
}
},
CheckPremium: id => {
let access = false;
if (!fs.existsSync(`./premium.json`)) return "";
else {
let urmom = module.exports.readFile(`./premium.json`).filter(r => r !== "");
if(!urmom.Includes(id)) return false
else return true
}
},
addAlt: (type, alt) => {
if (!fs.existsSync(`./alts/${type}.txt`)) return;
else {
fs.appendFile(`./alts/${type}.txt`, `${alt}\n`, "utf8", err => {
if (err) console.log(err);
});
}
},
removeAlt: (type, alt) => {
if (!fs.existsSync(`./alts/${type}.txt`)) return;
else {
let alts = module.exports.readFile(type);
alts = alts.filter(r => r !== alt);
alts = alts.filter(r => r !== "");
module.exports.saveFile(type, alts);
}
},
readFile: type => {
if (!fs.existsSync(`./alts/${type}.txt`)) return [];
else {
let text = fs.readFileSync(`./alts/${type}.txt`, "utf8");
return text.split("\n").filter(r => r !== "");
}
},
saveFile: (type, alts) => {
if (!fs.existsSync(`./alts/${type}.txt`)) return;
else {
let list = ``;
for (const alt of alts) list += `${alt}\n`;
fs.writeFileSync(`./alts/${type}.txt`, list, "utf8", err => {
if (err) console.log(err);
});
}
},
getAllowedRoles: () => {
let roleIds = config.allowedRoles;
return roleIds;
},
getAllowedChannels: () => {
let channelsIds = config.allowedChannels;
return channelsIds;
},
getAllowedFreeChannels: () => {
let channelsIds = config.allowedFreeChannels;
return channelsIds;
},
hasAccess: member => {
let access = false;
member.roles.forEach(role => {
if (module.exports.getAllowedRoles().includes(role.id)) access = true;
});
if (access) return true;
else return false;
},
allowedChannel: channel => {
if (module.exports.getAllowedChannels().includes(channel.id)) return true;
else return false;
},
allowedFreeChannel: channel => {
if (module.exports.getAllowedFreeChannels().includes(channel.id))
return true;
else return false;
},
calculateStock: async () => {
fs.readdir("./alts", (err, files) => {
if (err) return console.log(err);
module.exports.stock = [];
files.forEach((file, i) => {
let type = file.split(".")[0];
let number = module.exports.readFile(type).length;
module.exports.stock[i] = [type, number];
});
});
}
};