-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.js
53 lines (46 loc) · 1.45 KB
/
configuration.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
const fs = require('fs');
const file_path = './config/guilds_settings.json';
var guilds_settings = {};
exports.get = function(id = null) {
if (id && id in guilds_settings) return guilds_settings[id]
else if (id) return null;
return guilds_settings;
}
exports.set = function(guildId,
welcome_message = true,
default_roles = [],
temp_chan_cat = null,
temp_chan_create = null,
temp_priv_create = null,
temp_hide_create = null,
auto_mod = false,
auto_mod_channel = null)
{
guilds_settings[guildId] = {
'welcome_message': welcome_message,
'default_roles': default_roles,
'temp_chan_cat': temp_chan_cat,
'temp_chan_create': temp_chan_create,
'temp_priv_create': temp_priv_create,
'temp_hide_create': temp_hide_create,
'auto_mod': auto_mod,
'auto_mod_channel': auto_mod_channel
}
}
exports.modify = function(guildId, key, data) {
guilds_settings[guildId][key] = data;
}
exports.remove = function(guildId) {
delete guilds_settings[guildId];
}
exports.save = async function() {
const data = JSON.stringify(guilds_settings, null, 2);
fs.writeFileSync(file_path, data, (err) => {if (err) throw err});
}
exports.load = async function() {
try {
const rawdata = fs.readFileSync(file_path);
const data = JSON.parse(rawdata);
guilds_settings = data;
} catch {fs.writeFileSync(file_path, '{}', (err) => {if (err) throw err})}
}