What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Nickname highlight

Nickname highlight
Author: Message:
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Nickname highlight
An alternative to Spunky's code is to use a regular expression, which would make the code look something like this.

code:
var keywords= new Array("Spunky","SLM","Shane");
var re = new RegExp("\\b("+keywords.join("|")+")\\b","ig");

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message){
    if(Origin!==Messenger.MyName){
        var arr;
        while((arr = re.exec(Message))!==null){
            MsgPlus.DisplayToastContact("Nick Highlighter", "[c=#3682B4][b]Highlight[/b][/c]",RegExp.$1 + " has been mentioned by " + MsgPlus.RemoveFormatCodes(Origin);
        }
    }
}

Or if you didn't want it to list every word that is matched, which was sent in a single message (something like "Spunky SLM" would generate 2 toasts). then you could use the following.

code:
var keywords= new Array("Spunky","SLM","Shane");
var re = new RegExp("\\b("+keywords.join("|")+")\\b","i");

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message){
    if(Origin!==Messenger.MyName && re.exec(Message)!==null) MsgPlus.DisplayToastContact("Nick Highlighter", "[c=#3682B4][b]Highlight[/b][/c]",RegExp.$1 + " has been mentioned by " + MsgPlus.RemoveFormatCodes(Origin);
}

Also, I should note that the \\b used in the regex means that it must be the whole word (unlike spunky's which will match even "ASLMNDER" or something similar if it were ever to occur).  The i modifier allows for the letters to be in upper or lower case, just so that it doesn't matter if your friend types your name in caps for some unknown reason.

Obviously you could make the code smaller by writing straight into the regex, however I would recommend keeping the regex as a global variable unless it became contact dependant as this means it only needs to loaded the once.
[Image: markee.png]
09-29-2008 11:01 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Nickname highlight - by Johnny09 on 09-28-2008 at 04:02 PM
RE: Nickname highlight - by Spunky on 09-28-2008 at 05:53 PM
RE: Nickname highlight - by markee on 09-29-2008 at 11:01 AM
RE: Nickname highlight - by Spunky on 09-29-2008 at 11:05 AM
RE: Nickname highlight - by markee on 09-29-2008 at 11:22 AM
RE: Nickname highlight - by Spunky on 09-29-2008 at 03:34 PM
RE: Nickname highlight - by Johnny09 on 10-03-2008 at 05:26 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