-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
The argument parser has been implemented to be flexible and has options in order to adjust the parsing.
Wallace/coreplugins/plug/PlugMessage.js
Lines 18 to 100 in 28e450a
| parseMessage(message, options) { | |
| if (message == "") { | |
| return []; // :) | |
| } | |
| if (!options) { | |
| options = {}; | |
| } | |
| options.keepquotes = options.keepquotes || false; | |
| options.quotes = options.quotes || true; | |
| options.users = options.users || true; | |
| function matchName(query, i, users) { | |
| let matches = []; | |
| for(let iuser in users) { | |
| if (!users.hasOwnProperty(iuser)) { | |
| continue; | |
| } | |
| let user = users[iuser]; | |
| let cmpname = user.username.split(" ").slice(0, i).join(" "); | |
| if (cmpname === query) { | |
| matches.push(user); | |
| } | |
| } | |
| return matches; | |
| } | |
| let users = this.plugin.plug.getUsers(); | |
| users.sort(function(a, b) { | |
| return b.username.length - a.username.length; | |
| }); | |
| let parts = message.split(" "); | |
| for (let i = 0; i < parts.length; i++) { | |
| let part = parts[i]; | |
| if (options.quotes && part[0] === "\"") { | |
| for (let j = 1; j <= 10 && i + j < parts.length; j++) { | |
| console.log(part); | |
| if (part[part.length - 1] === "\"") { | |
| parts.splice(i + 1, j - 1); | |
| if (options.keepquotes === true) { | |
| parts[i] = part; | |
| } | |
| else { | |
| parts[i] = part.substring(1, part.length - 1); | |
| } | |
| break; | |
| } | |
| part = part + " " + parts[i + j]; | |
| } | |
| } | |
| else if (options.users && part[0] === "@") { | |
| part = part.slice(1); | |
| let matches = users; | |
| for (let j = 1; j <= 10 && i + j < parts.length; j++) { | |
| matches = matchName(part, j, matches); | |
| if (matches.length > 0) { | |
| if (matches.length === 1) { //is this the name we're looking for? | |
| if (matches[0].username === part) { | |
| parts.splice(i + 1, j - 1); | |
| parts[i] = "@" + part; | |
| } | |
| } | |
| } | |
| else { | |
| break; | |
| } | |
| part = part + " " + parts[i + j]; | |
| } | |
| } | |
| } | |
| return parts; | |
| } |
As part of the latest changes there is now a decorator for commands, which allows them to register the minimum user rank (and potentially other things), so this could allow for specifying options for the argument parser.
@CommandHandler("unban", {rank: "bouncer", argparser: {
users: false
}})