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!
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.