-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageParser.js
More file actions
30 lines (30 loc) · 900 Bytes
/
MessageParser.js
File metadata and controls
30 lines (30 loc) · 900 Bytes
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
module.exports = class MessageParser {
constructor(prefix){
this.__config__ = {
prefix: (prefix != null) ? prefix : "!"
};
}
setPrefix(prefix) {
if(typeof(prefix) == "string"){
this["__config__"].prefix = prefix;
} else {
throw new Error("MessageParser: setPrefix(prefix) : prefix should be a string.");
}
}
parse(string){
let res = {
command: null,
arguments: [],
parsed: false
};
if(string.startsWith(this['__config__'].prefix)){
let _main_ = (string.slice(this['__config__'].prefix.length)).split(' ');
res.command = _main_.shift();
res.arguments = _main_;
res.parsed = true;
return res;
} else {
return res;
}
}
}