What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Need an example of proper /commands to show to other scripters

Need an example of proper /commands to show to other scripters
Author: Message:
Menthix
forum admin
*******

Avatar

Posts: 5537
Reputation: 102
39 / Male / Flag
Joined: Mar 2002
O.P. Need an example of proper /commands to show to other scripters
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 :)
Finish the problem
Menthix.net | Contact Me
12-19-2006 04:52 PM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Need an example of proper /commands to show to other scripters
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.
11-07-2007 08:29 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Need an example of proper /commands to show to other scripters
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.
<Eljay> "Problems encountered: shit blew up" :zippy:
11-07-2007 09:32 PM
Profile PM Find Quote Report
Menthix
forum admin
*******

Avatar

Posts: 5537
Reputation: 102
39 / Male / Flag
Joined: Mar 2002
O.P. RE: Need an example of proper /commands to show to other scripters
quote:
Originally posted by SpunkyLoveMuff
Cookie's RegExp
Link? :)
Finish the problem
Menthix.net | Contact Me
11-08-2007 06:43 AM
Profile E-Mail PM Web Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
29 / Male / Flag
Joined: Apr 2006
Status: Away
RE: Need an example of proper /commands to show to other scripters
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
11-08-2007 07:08 AM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Need an example of proper /commands to show to other scripters
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.
11-08-2007 05:50 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Need an example of proper /commands to show to other scripters
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
<Eljay> "Problems encountered: shit blew up" :zippy:
11-08-2007 06:51 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On