blob: fb915aa54a296e9fc23d2bd6d731f3a3dcb97692 (
plain)
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
|
const CommandHandler = require('dbot-regex-handler');
module.exports = class RegexFramework extends CommandHandler {
endpoint(r, perms, cb) {
super.endpoint(r, cb);
this.commands[this.commands.length - 1].p = perms;
}
apply(str, context) {
for (let i = 0; i < this.commands.length; i++) {
let match = str.match(this.commands[i].regex);
if (match) {
let missingPerms = [];
this.commands[i].p.forEach(name => {
if (!context.member.permission.has(name)) {
missingPerms.push(name);
}
});
if (missingPerms.length === 0) {
this.commands[i].callback(match, context);
return true;
}
else {
return missingPerms;
}
}
}
return false;
}
};
|