What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » / commands

/ commands
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: / commands
Aaah... here's where regular expressions can help. :-)

I'll try to simplify it for you, since I guess you've never worked with those.
code:
var myCommand = "myscriptcmd"; //This is the name of your command! Please don't use any special characters to avoid problems with the regular expression
var myCommandDesc = "My first script command!"; //Here you can add a description for your command which will be shown in the shortcut menu when you press "/"

//Register our command
function OnGetScriptCommands() {
   var s = "<ScriptCommands>";
   s += "<Command>";
   s += "<Name>"+myCommand+"</Name>";
   s += "<Description>"+myCommandDesc+"</Description>";
   s += "<Parameters>&lt;message&gt;</Parameters>";
   s += "</Command>";
   s += "</ScriptCommands>";
   return s;
}

//The send event!
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   var reCheck = MakeRegExp(myCommand); //Get a regular expression
   if(reCheck.test(Message)) { //Checks if the message is our command
      var Param = RegExp.$1; //This thing is where the captured parameter is stored
      Message = MyFunction(Param); //Change this to your function name, and eventually add other parameters to it.
   }
   return Message;
}

//A simple function to create a regular expression
function MakeRegExp(str) {
   return new RegExp("/^\/"+str+"\s(.+)$", "i");
}

//An example function. Note that you always have to return something to be sent as replacement for the original message. If you want it to stop sending a message (eg if you want the command to only open a window), just return an empty string. (return "")
function MyFunction(Param) {
   var newMsg = "[c=4]"+Param+"[/c]";
   return newMsg;
}
Note: this code is not tested. It's possible that something wasn't noticed while I reviewed my post. If so, please let me know (or you can try to fix it yourself of course)!

This post was edited on 02-04-2007 at 06:49 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-04-2007 06:47 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
/ commands - by JANiT0R on 02-04-2007 at 05:17 PM
RE: / commands - by Matti on 02-04-2007 at 06:47 PM
RE: RE: / commands - by CookieRevised on 02-05-2007 at 01:16 AM
RE: / commands - by JANiT0R on 02-10-2007 at 09:02 PM
RE: / commands - by roflmao456 on 02-10-2007 at 11:49 PM
RE: / commands - by CookieRevised on 02-11-2007 at 10:25 AM
RE: / commands - by roflmao456 on 02-11-2007 at 03:33 PM
RE: / commands - by CookieRevised on 02-12-2007 at 11:07 AM


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