I didn't really sit down to make a fully functional production script that will sit and handle user error well, but as it seems that is what is expected I present the uber emas script of doom with custom command parsing and follow on macro activation: Useage: !emas Message [options] [macros .....] Options: --Name name : sets the name, if you don't use this you must select a token or it will whisper an error. Macros can be anything "/r 1d20", but macros will not work, on the other hand abilities will, IE: Will work: !emas "Hello World!" --name Alex "%{bob|test}" This will not: !emas "Hello World!" --name Alex "#test" on("chat:message", function(msg) {
function emas(arg, opt, who) {
var Message = "", Who = "", i = 0, selectedObject = false;
if(arg != undefined && arg.length > 0) {
Message = arg[0];
if(opt != undefined && opt.name) {
if(opt.name !== true) {
Who = opt.name;
} else {
sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]");
sendChat("Api", "/w " + who + " Options: --Name : Supply a name.");
return;
}
} else if(msg.selected != undefined) {
selectedObject = getObj("graphic", msg.selected[0]._id);
if(selectedObject != undefined && "get" in selectedObject) {
Who = selectedObject.get("name");
} else {
sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]");
sendChat("Api", "/w " + who + " Options: --Name : Supply a name.");
return;
}
} else {
sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]");
sendChat("Api", "/w " + who + " Options: --Name : Supply a name.");
return;
}
sendChat(Who, "/me " + Message);
if(arg.length > 1) {
for(i = 1; i < arg.length; i++) {
sendChat(Who, arg[i]);
}
}
} else {
sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]");
sendChat("Api", "/w " + who + " Options: --Name : Supply a name.");
return;
}
}
function parseString(str) {
var re = /(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g, res=[], arr=null, arg = [], opt = {}, i = 0, optName = "";
while (arr = re.exec(str)) { res.push(arr[1] ? arr[1] : arr[0]); }
for(i = 0; i < res.length; i++) {
if(res[i].indexOf("--") !== 0) { // arg
arg.push(res[i]);
} else {
optName = res[i].replace("--", "").toLowerCase();
opt[optName] = true;
if((i + 1) < res.length) {
opt[optName] = res[++i];
}
}
}
return [arg, opt];
}
if(msg.type === "api") {
var parseRes = parseString(msg.content),Command = "", Who = "", i = 0, arg = [], opt = {};
if(parseRes != undefined && parseRes.length === 2) {
opt = parseRes[1];
arg = parseRes[0];
if(arg.length > 0) {
Command = arg[0].toLowerCase();
arg.splice(0, 1); //Remove the command.
Who = msg.who.split(" ")[0];
if(Command === "!emas") { emas(arg, opt, Who) }
}
}
}
});