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

Help - /commands!
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. Huh?  Help - /commands!
Okay, here goes...

I'm making an Instant Response script, which is currently controlled entirely from the script menu, but I'm now adding /commands, which are as follows:
Javascript code:
function OnGetScriptCommands()
{
    var ScriptCommands = "<ScriptCommands>";
 
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.enable</Name>";
    ScriptCommands    +=         "<Description>Turn Instant Response on.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.disable</Name>";
    ScriptCommands    +=         "<Description>Turn Instant Response off.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.message</Name>";
    ScriptCommands    +=         "<Description>Change the Instant Response message.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.timer</Name>";
    ScriptCommands    +=         "<Description>Change the Instant Response timer.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.pluson</Name>";
    ScriptCommands    +=         "<Description>Turn the Instant Response Plus! Style on.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.plusoff</Name>";
    ScriptCommands    +=         "<Description>Turn the Instant Response Plus! Style off.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.alerton</Name>";
    ScriptCommands    +=         "<Description>Turn the Instant Response sign-in alert on.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.alertoff</Name>";
    ScriptCommands    +=         "<Description>Turn the Instant Response sign-in alert off.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    +=     "<Command>";
    ScriptCommands    +=         "<Name>ir.status</Name>";
    ScriptCommands    +=         "<Description>Check the status of Instant Response.</Description>";
    ScriptCommands    +=     "</Command>";
    ScriptCommands    += "</ScriptCommands>";
 
    return ScriptCommands;
}

That bit works fine, but it's the programming bit that's causing trouble...
Javascript code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage)
{
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null)
    {
        var command = RegExp.$1.toLowerCase();
        var parameter = RegExp.$2;
        switch (command)
        {
            case 'ir.enable':
                if(settingEnable)
                {
                }
                else
                {
                    settingEnable = true;
                    var Message = "Activation: enabled";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Activation: enabled");
                }
            return "";
            case 'ir.disable':
                if(settingEnable)
                {
                    settingEnable = false;
                    var Message = "Activation: disabled";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Activation: disabled");
                }
                return "";
            case 'ir.message':
 
                return "";
            case 'ir.timer':
 
                return "";
            case 'ir.pluson':
                if(setMsgPlusAM)
                {
                }
                else
                {
                    setMsgPlusAM = true;
                    var Message = "Plus! Style: on";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Plus! Style: on");
                }
                return "";
            case 'ir.plusoff':
                if(setMsgPlusAM)
                {
                    setMsgPlusAM = false;
                    var Message = "Plus! Style: off";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Plus! Style: off");
                }
                return "";
            case 'ir.alerton':
                if(setSignInAlert)
                {
                }
                else
                {
                    setSignInAlert = true;
                    var Message = "Sign-in Alert: enabled";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Sign-in Alert: on");
                }
                return "";
            case 'ir.alertoff':
                if(setSignInAlert)
                {
                    setSignInAlert = false;
                    var Message = "Sign-in Alert: disabled";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Sign-in Alert: off");
                }
                return "";
            case 'ir.status':
                if (settingEnable)
                {
                    var Message1 = "Message: " + settingMessage + "\nTimer: " + settingTimer + " milliseconds" + "\nPlus! Style: "
                    if (setMsgPlusAM) { var PMessage = "on" } else { var PMessage = "off" }
                    var Message2 = "\nSign-in Alert: "
                    if (setSignInAlert) { var SMessage = "on" } else { var SMessage = "off" }
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message1 + PMessage + Message2 + SMessage);
                    Debug.Trace("Instant Response  |  Message: " + settingMessage);
                    Debug.Trace("Instant Response  |  Timer: " + settingTimer + " milliseconds");
                    if (setMsgPlusAM) { Debug.Trace("Instant Response  |  Plus! Style: on"); }
                    else { Debug.Trace("Instant Response  |  Plus! Style: off"); }
                    if (setSignInAlert) { Debug.Trace("Instant Response  |  Sign-in Alert: on"); }
                    else { Debug.Trace("Instant Response  |  Sign-in Alert: off"); }
                }
                else
                {
                    var Message = "Unable to show the status.  You need to enable the script first!";
                    Message = MsgPlus.RemoveFormatCodes(Message);
                    MsgPlus.DisplayToast("Instant Response", Message);
                    Debug.Trace("Instant Response  |  Status check error.");
                }
                return "";
            default:
                return 0;
        }
    }
}


What I need, for the message and timer, is that the user types in the command, followed by the message/timer, and the script will set it.
code:
Example: /ir.message Hello there.  -->  (sets message to "Hello there.")
Example: /ir.timer 1000  -->  (sets timer to "1000")

How do I do this?  :S  (edit: codes in JavaScript now)

This post was edited on 02-15-2009 at 11:45 AM by whiz.
02-01-2009 12:38 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Help - /commands!
Javascript code:
//Add to the top of the script
var strMessage = '';
var intTimer = 0;


Javascript code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
        var command = RegExp.$1.toLowerCase();
        var parameter = RegExp.$2;
        switch (command) {
                case 'ir.message':
                        strMessage = parameter;                        return "";
                case 'ir.timer':
                        intTimer = (typeof parseInt(parameter) === 'number' ? parseInt(parameter) : 0);                         return "";
        }
    }
}


This post was edited on 02-01-2009 at 05:53 PM by matty.
02-01-2009 05:53 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - /commands!
Okay, thanks, that works!  :D

Another question, though.

Using my current system of selecting a message from the script menu, if a command is selected (eg. /nudge, /block etc.), the script sends just the message.  If any other message is sent, it adds "AutoMessage:" to the start, so it sends in the Plus! auto-message format.

It does this with two variables, "setMsgPlusAM" (the user's way of turning the Plus! auto-message style on or off), and "setnoteMesCmd" (automatically turned on if the message starts with a /), which, if active, disables the "AutoMessage:" start.  The code below will hopefully explain this better.
Javascript code:
function OnEvent_Timer(TimerID)
{
    Debug.Trace("Instant Response  |  Timer completed!");
    if (setMsgPlusAM)  // user's Plus! auto-message setting on
    {
        if (setnoteMesCmd)  // if message starts with a "/" (/command)
        {
            Messenger.OpenChat(TimerID).SendMessage(settingMessage);
            //  do not add the prefix to the message
        }
        else
        {
            Messenger.OpenChat(TimerID).SendMessage("AutoMessage: " + settingMessage);
            //  add the prefix to the message
        }
    }
    else
    {
        Messenger.OpenChat(TimerID).SendMessage(settingMessage);
        //  do not add the prefix to the message
    }
    Debug.Trace("Instant Response  |  Message sent!");
}


Can I set the script so that when the user types "/ir.message /command", the script can turn the "setnoteMesCmd" variable as true, so that the auto-message prefix will not be added?

Is this possible with a wildcard of some sort?  Like:
Javascript code:
if (parameter=="/" + *)
{
setnoteMesCmd = true;
}
else
{
setnoteMesCmd = false;
}

02-02-2009 10:59 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Help - /commands!
Well, the easiest way to do it would be to check if the first character of "parameter" is a slash, using:
Javascript code:
setnoteMesCmd = (parameter.charAt(0) === "/");

However, this is far from perfect, as Plus! allows commands to be escaped by doubling the slash and you should check that the command itself doesn't contain invalid characters. Therefore, the "best" way to do this is by using regular expressions! :D
Javascript code:
setnoteMesCmd = (/^\/[^\s\/]+\s*[\s\S]*$/.test(parameter));

Basically, this is the same regular expression as you use in your command parser, the only difference is that it doesn't capture anything.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-02-2009 03:30 PM
Profile E-Mail PM Web Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: RE: Help - /commands!
Great, that works fine.  That's that script finished...  :D  Thanks!

Actually, I have another question (sorry to keep on at this).  This script blocks the opening of single conversations, group conversations, or both, opened by other users.
Javascript code:
var Window;
var WindowContacts;
 
var FirstRunSetup = true;
var UserEmail = Messenger.MyEmail;
 
var SingleEnabled = false;
var GroupEnabled = false;
 
var SingleMessage = "";
var GroupMessage = "";
 
function OnEvent_Initialize(MessengerStart)
{
    Debug.Trace("-> Welcome to ChatBlock!")
    Debug.Trace("---> Settings for " + UserEmail + ":")
    Debug.Trace("-----> Single chat block = " + SingleEnabled)
    Debug.Trace("-------> Single chat message = \"" + SingleMessage + "\"")
    Debug.Trace("-----> Group chat block = " + GroupEnabled)
    Debug.Trace("-------> Group chat message = \"" + GroupMessage + "\"")
}
 
function OnEvent_ChatWndCreated(Wnd)
{
    Window = Wnd;
    WindowContacts = Wnd.Contacts;
 
    Debug.Trace("-> Conversation window opened!")  
    Debug.Trace("---> Participants = " + WindowContacts.Count);
       
    if(WindowContacts.Count==1)
    {
        Debug.Trace("-> Single conversation detected!")
        if(SingleEnabled==true)
        {
            Debug.Trace("---> Single blocking is enabled!")
            if(SingleMessage=="")
            {
                Debug.Trace("---> No single chat message setup...")
            }
           
            else
            {
                Window.SendMessage(SingleMessage);
                Debug.Trace("---> Single chat message sent!")
            }
           
            Window.SendMessage("/close");
            MsgPlus.DisplayToast("ChatBlock", "Single conversation blocked.")
            Debug.Trace("-----> Single conversation blocked!")
        }
        else
        {
            Debug.Trace("---> Single blocking is disabled!")
        }
    }
    if(WindowContacts.Count > 1)
    {
        Debug.Trace("-> Group conversation detected!")
        if(GroupEnabled==true)
        {
            Debug.Trace("---> Group blocking is enabled!")
            if(GroupMessage=="")
            {
                Debug.Trace("---> No group chat message setup...")
            }
           
            else
            {
                Window.SendMessage(GroupMessage);
                Debug.Trace("---> Group chat message sent!")
            }
           
            Window.SendMessage("/close");
            MsgPlus.DisplayToast("ChatBlock", "Group conversation blocked.")
            Debug.Trace("-----> Group conversation blocked!")
        }
        else
        {
            Debug.Trace("---> Group blocking is disabled!")
        }
    }
}


You'll see that single and group blocking is currently disabled.  However, the problem with this is that not only does it block windows opened by other users, but it also blocks the current user from opening windows as well!  How can I set it so that if the current user opens a window (there's an email variable called "UserEmail"), the blocker will ignore it?
02-04-2009 05:54 PM
Profile E-Mail PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
37 / Male / Flag
Joined: Jul 2005
RE: Help - /commands! [NEW QUESTION!]
quote:
Originally posted by whiz
How can I set it so that if the current user opens a window (there's an email variable called "UserEmail"), the blocker will ignore it?
I don't think it's possible to do that reliably.
The OnEvent_ChatWndCreated event only provides you with a ChatWnd object, AFAIK you can not determine exactly how and why it was opened.

What you could do to "guess" how it was opened, is store each ChatWnd.Handle in a global array, and set up OnEvent_ChatWndReceiveMessage to check who sends the first message to this ChatWnd. If it's not you, you probably didn't open the window.

Please note that above method is not fool-proof at all!
Not only is there no reliable way to check who sent a message to a certain ChatWnd (think Chat-Only names and Custom names etc.), but there's also the possibility the ChatWnd was not opened by a message at all. It could be opened by e.g. a file transfer or a nudge, which don't trigger OnEvent_ChatWndReceiveMessage IIRC.
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
02-07-2009 01:15 PM
Profile PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - /commands!
Okay...  thanks anyway.  :)
02-15-2009 11:45 AM
Profile E-Mail 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