Shoutbox

Scripting - help with commands (Was: HELP!) - 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: Scripting - help with commands (Was: HELP!) (/showthread.php?tid=73202)

Scripting - help with commands (Was: HELP!) by Ashylay on 04-01-2007 at 12:47 PM

Okay so Im not the best at scripting and I was just wondering how this would happen.

So basically with the pre-installed scripts when you type say /name your name changes to whatever you type after the /name command so I just want to know how do you reffer to what you type after that.

I want it so say you type:

/command Hello!

A toast appears with the text 'Hello!'

Help?!?


RE: HELP! by TheGuruSupremacy on 04-01-2007 at 12:52 PM

quote:
Originally posted by Ashylay
Okay so Im not the best at scripting and I was just wondering how this would happen.

So basically with the pre-installed scripts when you type say /name your name changes to whatever you type after the /name command so I just want to know how do you reffer to what you type after that.

I want it so say you type:

/command Hello!

A toast appears with the text 'Hello!'

Help?!?




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(" ")
if(split[0]=="/command"){
MsgPlus.DisplayToast("Example",split[1])
return "";}}


RE: HELP! by Ashylay on 04-01-2007 at 01:00 PM

Is there a possible way to involve this in a getURL function of some sort? && The above script only works with one word ;o


RE: HELP! by TheGuruSupremacy on 04-01-2007 at 01:07 PM

quote:
Originally posted by Ashylay
Is there a possible way to involve this in a getURL function of some sort?

I don't understand....Involve in a geturl function????Tell me what you want to do....Try to explain it better...
RE: HELP! by Ashylay on 04-01-2007 at 01:13 PM

Well say on a webpage you used a variable

Would it be possible to load an internet page which has a variable on it and use the writing you wrote as the varibale so some of the script would look like this:

"http://www.yoursite.com/index.php?variable=" + split[1]

Then it would load

http://www.yoursite.com/index.php?variable=WHATEVER YOU PUT FOR SPLIT 1


RE: HELP! by TheGuruSupremacy on 04-01-2007 at 01:20 PM

quote:
Originally posted by Ashylay
Well say on a webpage you used a variable

Would it be possible to load an internet page which has a variable on it and use the writing you wrote as the varibale so some of the script would look like this:

"http://www.yoursite.com/index.php?variable=" + split[1]

Then it would load

http://www.yoursite.com/index.php?variable=WHATEVER YOU PUT FOR SPLIT 1


Ok...if i have understand well...you want this:

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(" ")
if(split[0]=="/command"){
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 "";}}


RE: Scripting - help with commands (Was: HELP!) by Ashylay on 04-01-2007 at 01:25 PM

Yes and also is it possible to use a for loop so I can type say

/command more than one word.


RE: HELP! by Matti on 04-01-2007 at 01:26 PM

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. ;)
RE: Scripting - help with commands (Was: HELP!) by TheGuruSupremacy on 04-01-2007 at 01:28 PM


quote:
Originally posted by Ashylay
Yes and also is it possible to use a for loop so I can type say

/command more than one word.

Yes..It's possible:

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 "";}}


RE: Scripting - help with commands (Was: HELP!) by Matti on 04-01-2007 at 01:33 PM

quote:
Originally posted by TheGuruSupremacy
quote:
Originally posted by Mattike

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

Also with split function works for more than one word
But not when you have "/command" in your actual message, read edited post.

I'm soo slow at editing...
RE: Scripting - help with commands (Was: HELP!) by Ashylay on 04-01-2007 at 01:35 PM

Thanks Mattike, exactly what I wanted.


RE: Scripting - help with commands (Was: HELP!) by TheGuruSupremacy on 04-01-2007 at 01:52 PM

quote:
Originally posted by Mattike
quote:
Originally posted by TheGuruSupremacy
quote:
Originally posted by Mattike

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

Also with split function works for more than one word
But not when you have "/command" in your actual message, read edited post.

I'm soo slow at editing...

It's improbably that "/command" is in message however
You are right split is not the best way to parse command...However
you can also do this:

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){
if (Message.substring(0,8)=="/command"){
var url="http://www.yoursite.com/index.php?variable=" + Message.substring(8,Message.lenght)
Interop.Call("shell32","ShellExecuteW",0,"open",url,null,null,1)
MsgPlus.DisplayToast("Example",Message.substring(8,Message.lenght))
return "";}}


quote:
Originally posted by Mattike

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.


Yes it's true but is not necessary using regular expressions to parse a command..
RE: Scripting - help with commands (Was: HELP!) by markee on 04-01-2007 at 03:47 PM

It might not be necessary to use regular expressions, but it sure is nicer.  Have a look at CookieRevised's reply to [Release] Exit WLM for some really good examples. ;)