Shoutbox

Need an example of proper /commands to show to other scripters - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Need an example of proper /commands to show to other scripters (/showthread.php?tid=69689)

Need an example of proper /commands to show to other scripters by Menthix on 12-19-2006 at 04:52 PM

Hey,

As most of  you know i'm moderating the scripts DB, when adding new scripts i always check them out first. The thing i seem to run into more and more is that people don't use proper /commands, but they use their own ones that don't show up in the command helper or the make their commands case sensitive.

I always mail people back when things like that happen and tell them what's wrong and point them to where in the documentation they can find a solution for it. But is would be nice if there is an piece of example code that deals with all the common /command problems and shows beginning devvers how its done and what they should look out for.

At the moment i have more than 20 new scripts waiting to be added and more are dripping in. I'm sure it takes me much longer to read through the documentation than it takes for an experienced scripter to write an nice example, so i ask your help :).

What am i looking for?
- Basically a example code that shows how to deal with all the aspects of /commands
- Well commented code, a beginning unexperienced coder should be able to understand why you do things the way you do it in the example
- How to add commands to the command helper, including description (OnGetScriptCommands)
- How to catch your commands (OnGetScriptCommands)
- Make commands case insensitive
- How to work with commands that include parameters (optional parameters / multiple parameters)
- How to add parameter info to the command helper
- other things that i forgot which people should know

Put the example together with all the comments in a .js and post in here in the topic, or maybe better, post it in a BBcode block so people can easily read it and improve if needed. Once we have a nice example i'll put it in a new sticky(+locked?) topic so i can point people to there in the future.

Thanks for helping out :)


RE: Need an example of proper /commands to show to other scripters by vikke on 11-07-2007 at 08:29 PM

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>&lt;" + Parameter + "&gt;</Parameters></Command>";
}
Feel free to edit my comments, my code. And use it however you want.
RE: Need an example of proper /commands to show to other scripters by Spunky on 11-07-2007 at 09:32 PM

That fails simply because it doesn't take // into account when sending a message without parsing commands... :p I think Cookie's RegExp is the best example we've seen so far. Even if some people find it confuding at first, you don't have to actually edit it.


RE: Need an example of proper /commands to show to other scripters by Menthix on 11-08-2007 at 06:43 AM

quote:
Originally posted by SpunkyLoveMuff
Cookie's RegExp
Link? :)
RE: Need an example of proper /commands to show to other scripters by Felu on 11-08-2007 at 07:08 AM

quote:
Originally posted by MenthiX
quote:
Originally posted by SpunkyLoveMuff
Cookie's RegExp
Link? :)
I think Spunky is referring to http://shoutbox.menthix.net/showthread.php?tid=74...d=819024#pid819024
RE: Need an example of proper /commands to show to other scripters by vikke on 11-08-2007 at 05:50 PM

I agree. Cookies RegExp code is better than mine. But what about multiple parameters, and adding the commands to the command-list?

Also RegExp could be confusing to new members.


RE: Need an example of proper /commands to show to other scripters by Spunky on 11-08-2007 at 06:51 PM

quote:
Originally posted by vikke
Also RegExp could be confusing to new members.

quote:
Originally posted by SpunkyLoveMuff
Even if some people find it confusing at first, you don't have to actually edit it

As for multiple params, I'm fairly sure it does (or can be made to) handle these