This repository was archived by the owner on Nov 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprefixManager.js
More file actions
49 lines (40 loc) · 1.29 KB
/
prefixManager.js
File metadata and controls
49 lines (40 loc) · 1.29 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
const fs = require('fs');
let _lastManager = null; // This will hold the last manager created
class PrefixManager {
constructor(path, defaultPrefix) {
this.path = path;
this.defaultPrefix = defaultPrefix;
this.prefixes = {};
this.load()
_lastManager = this; // Set the _lastManager as the last create PrefixManager
}
load() {
try {
const data = fs.readFileSync(this.path);
const json = JSON.parse(data);
this.prefixes = json;
} catch (e) {
console.log('error while reading or parsing prefix json', e.message)
}
}
save() {
fs.writeFileSync(this.path, JSON.stringify(this.prefixes));
}
get(message) {
if (message.guild && this.prefixes[message.guild.id]) {// hello ^_^ // hi ;D
return this.prefixes[message.guild.id];
}
return this.defaultPrefix;
}
set(message, prefix) {
if (message.guild) {
this.prefixes[message.guild.id] = prefix;
this.save();
return true
}
}
static lastManager() { // static method so it can be accessed from PrefixManager.lastManager() (without new)
return _lastManager;
}
}
module.exports = PrefixManager;