Skip to content

Instantly share code, notes, and snippets.

@BaldarSilveraxe
Created December 11, 2013 01:11
Show Gist options
  • Save BaldarSilveraxe/7903455 to your computer and use it in GitHub Desktop.
Save BaldarSilveraxe/7903455 to your computer and use it in GitHub Desktop.
Roll20 API AD&D 2E (DRAFT)
//API:Events:processMessage
processMessage = function(msg) {
if(msg.type !== "api"){return};
roll20API.contentPlayer = getObj("player", msg.playerid);
roll20API.contentUserid = roll20API.contentPlayer.get("d20userid");
roll20API.contentPlayerid = roll20API.contentPlayer.get("_id");
//Remove or move
if(roll20API.allowedUser.indexOf(roll20API.contentUserid) == -1){return};
roll20API.contentGiven = msg.content.toLowerCase();
roll20API.contentGivenProper = msg.content;
if (msg.who.indexOf(" (GM)") !== -1){roll20API.Who = msg.who.substr(0,msg.who.length - 5);};
if(roll20API.contentGiven.indexOf(' ') == -1){
roll20API.contentMessage = null;
roll20API.contentCommand = roll20API.contentGiven.substr(1, roll20API.contentGiven.length);
}else{
roll20API.contentMessage = roll20API.contentGiven.substr(roll20API.contentGiven.indexOf(' ') + 1);
roll20API.contentCommand = roll20API.contentGiven.substr(1, roll20API.contentGiven.indexOf(' ')-1);};
if(roll20API.contentMessage == "yes"){roll20API.valid = true;}else{roll20API.valid = false;};
if(roll20API.Who.indexOf(' ') == -1){roll20API.FirstName = roll20API.Who;
}else{roll20API.FirstName = roll20API.Who.substr(0,roll20API.Who.indexOf(' '));};
roll20API.Type = "Player";
roll20API.Long = "help";
roll20API.Family = "common";
_.each(roll20API.apiCommands, function(indexCommands) {
if(indexCommands.Long == roll20API.contentCommand || indexCommands.Short == roll20API.contentCommand){
roll20API.Type = indexCommands.Type;
roll20API.Long = indexCommands.Long;
roll20API.Family = indexCommands.Family;
};
});
messageType();
};
//API:Events:processMessage:messageType
messageType = function() {
switch (roll20API.Type){
case "Player":
playerFamily();
break;
case "GM":
if(roll20API.gmUser.indexOf(roll20API.contentUserid) == -1){return};
sendChat("API", "gm")
break;
case "Owner":
if(roll20API.allowedUser.indexOf(roll20API.contentUserid) == -1){return};
sendChat("API", "owner")
break;
};
};
//API:Events:processMessage:messageType:playerFamily
playerFamily = function() {
switch (roll20API.Family){
case "Common": playerCommon(); break;
case "Language": processAPIlanguage(); break;
};
};
//API:Events:processMessage:messageType:playerCommon
playerCommon = function() {
switch (roll20API.Long){
case "help": processAPIhelp(); break;
case "broll": processAPIbroll(); break;
case "rules": processAPIrules(); break;
case "monsters": processAPImonsters(); break;
case "wizard": processAPIwizard(); break;
case "priest": processAPIpriest(); break;
case "school": processAPIschool(); break;
case "sphere": processAPIsphere(); break;
case "equipment": processAPIequipment(); break;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment