What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [IDEA] plusQuery

[IDEA] plusQuery
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [IDEA] plusQuery
quote:
Originally posted by matty
One thing I noticed

You cannot obtain the Contact object by passing the origin parameter to the GetContact function.
He extended the GetContact implementation so that you can search by name as well.
Javascript code:
$.wrappers.Contacts.prototype.extend({
    GetContact: function (str) {
        if (str.toLowerCase() === Messenger.MyEmail.toLowerCase()) {
            return this[0];
        } else if (this.original.GetContact(str)) {
            return $(this.original.GetContact(str));
        } else {
            for (var i = 0; i < this.length; i++) {
                if (this[i].Name === str) {
                    return this[i]; // Only returns the first match
                }
            }
        }
 
        return null;
    }
});

Still, it's not a good idea to do this. The value of origin may not resolve to the right contact, for example when a contact has a nickname assigned. Contact.Name always returns the name as published by the contact, whereas origin may contain the nickname of that contact. I think it's better to simply use origin - if the developer wants to resolve this to a contact, he can just implement this in the callback or override the event himself.



Also, the local command parsing should be a bit more sophisticated. For example, script commands should be escapable by adding an extra leading slash, such as "//mycommand". Also, parameters can be separated by many sorts of whitespace characters such as \n, \r,... Therefore, you'll need a regular expression to properly detect whether a given message is a script command and correctly separate the command from the parameter. Luckily, Cookie has written an excellent regular expression for this: CookieRevised's reply to Gettin data from "/" commands.

The way I parse local commands is based upon Cookie's regular expression but instead of using the global RegExp object to retrieve the data, I use the result from exec() itself. It's better to use your local data rather than having to rely on global side effects. ;)
Javascript code:
var match = /^\/([^ \n\r\v\xA0\/][^ \n\r\v\xA0]*)(?:[ \n\r\v\xA0]([\s\S]*))?$/.exec(message);
if ( match ) {
    var command = match[1]; // note: command will have no leading slash
    var parameters = match[2];
 
    var tmp = $.triggerCommand($(chatWnd), $.MyContact, command, parameters, message, false);
    return (tmp === undefined ? message : tmp);
}

This principle can't be easily ported to external commands though, since you don't know what the leading character will be (! or @ or ...). However, you won't have to deal with escaped commands either. I'd recommend to simply look for the command until the first encountered whitespace character and use the remaining part as parameters.
Javascript code:
var match = /^([^ \n\r\v\xA0]*)[ \n\r\v\xA0]?([\s\S]*)$/.exec(sMessage);
if ( match ) {
    var command = m[1]; // note: command will retain its leading character
    var parameters = m[2];
 
    $.triggerCommand($(chatWnd), $.MyContact, command, parameters, message, true);
}


quote:
Originally posted by Eljay
JScript does have a global scope. In regular JScript (WSH) you can just do "var global = this" in global scope then access it anywhere.
I know, I tried that but it's inaccessible. You can't read global variables from it or add variables to it. Heck, you can't even iterate over its contents. Very sad indeed. :(

Long post is long indeed.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

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

Messages In This Thread
[IDEA] plusQuery - by Amec on 07-13-2010 at 04:43 AM
RE: [IDEA] plusQuery - by Spunky on 07-13-2010 at 06:29 AM
RE: [IDEA] plusQuery - by Matti on 07-13-2010 at 07:55 AM
RE: [IDEA] plusQuery - by CookieRevised on 07-13-2010 at 11:47 PM
RE: [IDEA] plusQuery - by Matti on 07-14-2010 at 10:28 AM
RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 04:34 AM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 09:43 AM
RE: RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 11:12 AM
RE: [IDEA] plusQuery - by matty on 04-06-2011 at 12:46 PM
RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 02:07 PM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 03:03 PM
RE: RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 04:11 PM
RE: [IDEA] plusQuery - by matty on 04-06-2011 at 05:19 PM
RE: [IDEA] plusQuery - by Eljay on 04-06-2011 at 06:03 PM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 06:11 PM
RE: [IDEA] plusQuery - by Eljay on 04-06-2011 at 06:20 PM
RE: [IDEA] plusQuery - by CookieRevised on 04-06-2011 at 10:27 PM
RE: [IDEA] plusQuery - by Amec on 04-07-2011 at 05:43 AM
RE: [IDEA] plusQuery - by CookieRevised on 04-07-2011 at 09:36 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