-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.js
128 lines (102 loc) · 3.13 KB
/
config.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Hello there! Please do not adjust any settings in this file. Instead,
make all changes in your config.yaml file.
*/
const yaml = require('js-yaml');
const fs = require('fs');
let userCfg = {};
// Try for yaml config
try {
userCfg = yaml.safeLoad(fs.readFileSync('config.yaml', 'utf8'));
}
catch (e) {
console.log(e);
}
// The only required option is token
const requiredOpt = ['token'];
// Default config generation
const defaultCfg = {
// Public settings
'token': null,
'serverIds': [],
'channelIds': [],
// Spam settings.
'spam': false,
'toSpam': [],
'deleteSpam': false,
'sabotage': false,
'minClaimDelay': 500,
'maxClaimDelay': 1000,
'minSpamDelay': 25000,
'maxSpamDelay': 35000,
'slowmode': false,
'slowmodeTime': 605000,
// Private settings
'trick': 'h!trick',
'treat': 'h!treat',
'specServer': false,
'specChannel': false,
// Everything but receiving MESSAGE_UPDATE & MESSAGE_CREATE. Increases performance.
// https://abal.moe/Eris/docs/reference#ws-event-names
'disabledEvents': {
'CHANNEL_CREATE': true,
'CHANNEL_DELETE': true,
'CHANNEL_UPDATE': true,
'GUILD_BAN_ADD': true,
'GUILD_BAN_REMOVE': true,
'GUILD_CREATE': true,
'GUILD_DELETE': true,
'GUILD_MEMBER_ADD': true,
'GUILD_MEMBER_REMOVE': true,
'GUILD_MEMBER_UPDATE': true,
'GUILD_ROLE_CREATE': true,
'GUILD_ROLE_DELETE': true,
'GUILD_ROLE_UPDATE': true,
'GUILD_UPDATE': true,
'MESSAGE_DELETE': true,
'MESSAGE_DELETE_BULK': true,
'PRESENCE_UPDATE': true,
'TYPING_START': true,
'USER_UPDATE': true,
'VOICE_STATE_UPDATE': true,
},
};
// Combine user config with default config to form final config
const finalizedCfg = Object.assign({}, defaultCfg);
// Transfer user options onto the final config
for (const [prop, value] of Object.entries(userCfg)) {
finalizedCfg[prop] = value;
}
// If channelIds are specified, specChannel gets set to true
if(finalizedCfg.channelIds[0]) {
finalizedCfg.specChannel = true;
}
// If serverIds are specified, specServer gets set to true
if(finalizedCfg.serverIds[0]) {
finalizedCfg.specServer = true;
}
// If config sabotage is true, swap the values of treat & trick
if(finalizedCfg.sabotage) {
console.log('Sabotage active.');
[finalizedCfg.trick, finalizedCfg.treat] = [finalizedCfg.treat, finalizedCfg.trick];
}
// Make sure we have what we need //
// If a user specifices spam but doesnt give us a server to spam, we can't do it.
// Can actually be either channel or server
if(finalizedCfg.spam && !finalizedCfg.serverIds[0] && !finalizedCfg.channelIds[0]) {
console.error('Cannot spam server without a server id or channel id in config.yaml.');
process.exit(1);
}
if(finalizedCfg.spam && !finalizedCfg.toSpam[0]) {
console.error('Please specify messages to send in config.yaml.');
process.exit(1);
}
// Make sure all of the required config options are present
for (const opt of requiredOpt) {
if (!finalizedCfg[opt]) {
console.error('Missing required option: ${opt} in config.yaml');
process.exit(1);
}
}
// Export the finalized config
module.exports = finalizedCfg;