diff options
Diffstat (limited to 'src/RegexFramework.js')
| -rw-r--r-- | src/RegexFramework.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/RegexFramework.js b/src/RegexFramework.js new file mode 100644 index 0000000..fb915aa --- /dev/null +++ b/src/RegexFramework.js @@ -0,0 +1,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; + } +}; |
