var roll20API = roll20API || {};
roll20API.apiCommands = [ {description: "Area Of Effect.", long: "aoe", short: "aoe", process: "processAOE"}, {description: "Attack.", long: "attack", short: "atk", process: "processATK"}, ];
on("chat:message", function(msg) { if(msg.type != "api"){return;}; //Return and do nothing if its not an API command. if(msg.content.indexOf(' ') == -1){ roll20API.contentMessage = null; roll20API.contentCommand = msg.content.toLowerCase().substr(1, msg.content.toLowerCase().length); }else{ roll20API.contentMessage = msg.content.toLowerCase().substr(msg.content.toLowerCase().indexOf(' ') + 1); roll20API.contentCommand = msg.content.toLowerCase().substr(1, msg.content.toLowerCase().indexOf(' ') - 1); }; //get the API command as roll20API.contentCommand //get any message with the API command as roll20API.contentMessage var processToCall = undefined; _.each(roll20API.apiCommands, function(indexCommands) { if(indexCommands.long == roll20API.contentCommand || indexCommands.short == roll20API.contentCommand){ processToCall = indexCommands.process; }; }); //Loop through all the valid commands to find see what was given is found if(processToCall == undefined){return;}; var functionString = eval(processToCall); functionString(); });
processAOE = function() { sendChat("API", "processAOE triggered by \"!" + roll20API.contentCommand + "\" and using \"" + roll20API.contentMessage + "\"") };
processATK = function() { sendChat("API", "processATK triggered by \"!" + roll20API.contentCommand + "\" and using \"" + roll20API.contentMessage + "\"") };