diff options
| author | Alejandro Sior <aho@sio.be> | 2021-02-19 11:43:18 +0100 |
|---|---|---|
| committer | Alejandro Sior <aho@sio.be> | 2021-02-19 11:43:18 +0100 |
| commit | 405051211d60afa8a7fc4fc3fa5ffb456242973d (patch) | |
| tree | dbae34350c3a54f422da70f1b7fbd857a8f5a116 /src/RegexFramework.js | |
initial commit
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; + } +}; |
