What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Scripting - help with commands (Was: HELP!)

Scripting - help with commands (Was: HELP!)
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: HELP!
split() isn't the best way to parse command, regular expressions are more effective:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   if(/^\/command\s(.+)$/i.test(Message)) { //Regular expression to do the check
      var Param = RegExp.$1; //Store Param, making the code easier to understand
      MsgPlus.DisplayToast("Example", "Opening page with parameter '"+Param+"'"); //Display a toast
      new ActiveXObject("WScript.Shell").Run("http://www.yoursite.com/index.php?variable="+escape(Param)); //Open the page with escaped Param to avoid any conflicts
      return ""; //Don't send the message, otherwise Plus! warns you that the command couldn't be parsed
}
Or, instead of using the ActiveX object, you could replace that rule with:
code:
Interop.Call("shell32", "ShellExecuteW", 0, "open", "http://www.yoursite.com/index.php?variable="+escape(Param), null, null, 1);

The advantage here is that it works for more than one word! :P


quote:
Originally posted by TheGuruSupremacy
code:
function OnGetScriptCommands(){
    var commands = "<ScriptCommands>";
        commands += "  <Command>"
        commands += "    <Name>command</Name>"
        commands += "    <Description>TheGuruSupremacy</Description>"
        commands += "  </Command>"
        commands += "</ScriptCommands>"
    return commands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
var split=Message.split("/command")
if(split[0]==""){
var url="http://www.yoursite.com/index.php?variable=" + split[1]
Interop.Call("shell32","ShellExecuteW",0,"open",url,null,null,1)
MsgPlus.DisplayToast("Example",split[1])
return "";}}

That code will work, but it will be case sensitive and it's not the recommend way to parse commands. Also, this won't work too good either with your code:
quote:
/command I'm testing this /command, funny huh!
Therefore, it's more common to use regular expressions. They're harder to understand and learn, but they avoid a lot of problems you can have when using such split() calls. ;)

This post was edited on 04-01-2007 at 01:32 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!
04-01-2007 01:26 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Scripting - help with commands (Was: HELP!) - by Ashylay on 04-01-2007 at 12:47 PM
RE: HELP! - by TheGuruSupremacy on 04-01-2007 at 12:52 PM
RE: HELP! - by Ashylay on 04-01-2007 at 01:00 PM
RE: HELP! - by TheGuruSupremacy on 04-01-2007 at 01:07 PM
RE: HELP! - by Ashylay on 04-01-2007 at 01:13 PM
RE: HELP! - by TheGuruSupremacy on 04-01-2007 at 01:20 PM
RE: Scripting - help with commands (Was: HELP!) - by Ashylay on 04-01-2007 at 01:25 PM
RE: HELP! - by Matti on 04-01-2007 at 01:26 PM
RE: Scripting - help with commands (Was: HELP!) - by TheGuruSupremacy on 04-01-2007 at 01:28 PM
RE: Scripting - help with commands (Was: HELP!) - by Matti on 04-01-2007 at 01:33 PM
RE: Scripting - help with commands (Was: HELP!) - by Ashylay on 04-01-2007 at 01:35 PM
RE: Scripting - help with commands (Was: HELP!) - by TheGuruSupremacy on 04-01-2007 at 01:52 PM
RE: Scripting - help with commands (Was: HELP!) - by markee on 04-01-2007 at 03:47 PM


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