I just wrote this, and I think it pretty much sums it up.
code:
// This function gets called when the user sends
// a message in a conversation. This is where we
// shall look for our command.
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
// Check if the message starts with "/", then
// it is a command.
if(Message.charAt(0) == "/")
{
// Split the string into smaller parts.
var Parts = Message.split(" ");
// Get the command name, and remove the first
// character ("/").
var CommandName = Parts[0].substr(1, Parts[0].length).toLowerCase();
// Check if the command name is "command"
if(CommandName == "command")
{
// If there are any parameters.
if(Parts.length > 1)
{
// Show the first parameter in the debug window, there could be more.
Debug.Trace("/command was called with parameter " + Parts[1]);
}
// Prevent the command from being sent.
return "";
}
// Check if it's our second command.
else if(CommandName == "command2")
{
if(Parts.length > 2)
{
// Parts[1] is the first parameter.
// Parts[2] is the second parameter etc..
Debug.Trace("/command2 was called with 2 parameters, " + Parts[1] + " and " + Parts[2]);
}
// Prevent the command from being sent.
return "";
}
}
// Send the message to the contact.
return Message;
}
// This function gets called when Messenger Plus!
// gathers all commands available from your script
function OnGetScriptCommands( )
{
// Start the ScriptCommands tag.
var ScriptCommands = "<ScriptCommands>";
// Add Command tags inside the ScriptCommand tag.
// Note: Do not add the "/" character here.
ScriptCommands += CreateCommand("command", "Command Description", "Parameter Description");
// You can also add a command tag without my CreateCommand function.
ScriptCommands += "<Command>";
ScriptCommands += "<Name>";
ScriptCommands += "command2";
ScriptCommands += "</Name>";
ScriptCommands += "<Description>";
ScriptCommands += "Command2 description here!";
ScriptCommands += "</Description>";
ScriptCommands += "</Command>";
// End the ScriptCommands tag.
ScriptCommands += "</ScriptCommands>";
// Return the commands to Messenger Plus!
return ScriptCommands;
}
// This function returns the XML tag for a command.
function CreateCommand(Name, Description, Parameter)
{
return "<Command><Name>" + Name + "</Name><Description>" + Description + "</Description><Parameters><" + Parameter + "></Parameters></Command>";
}
Feel free to edit my comments, my code. And use it however you want.