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:
Johnny09
New Member
*


Posts: 13
Joined: Sep 2008
O.P. Nickname highlight
Hello community,

those users who use irc may already know it. once your nickname is mentioned in a channel a small box appears in the lower right corner of your desktop and you get informed about this (e.g. Nickname 'Johnny' was mentioned in #irc).

is there a similar function to this for msgplus?

it would be useful e.g. in a mass conversation.

a normal msgplus message (MsgPlus.DisplayToastContact("Information","Your nickname has been mentioned by User")) should appear.

im also a scripter, but not experienced in msgplus scripting.
so it would be nice if you could help me.
its okay.. i figured it out myself:

--
var highwords = new Array ("johnny", "jay");

function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{
     var e = new Enumerator(ChatWnd.Contacts);
     var contact = e.item();

    checkAndDisplay (Message, contact.Name);
}

function checkAndDisplay (Message, my)
{
    for (i in highwords) {
        if (Message.toLowerCase().search(highwords[i]) != -1) {
            MsgPlus.DisplayToastContact("Nick Highlighter", "[c=#3682B4]Highlight[/c]", "'"+ucfirst(highwords[i])+"' has been mentioned by: " + my, null, "locateDetectedAddress");
        }
    }
}

function ucfirst(str) {
    return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}
09-28-2008 04:02 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Nickname highlight
code:
var keywords= new Array("Spunky","SLM","Shane");

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message){
    if(Origin!==Messenger.MyName){
        for(var s in keywords){
            if(Message.search(keywords[s])!==-1){
                 MsgPlus.DisplayToastContact("Nick Highlighter", "[c=#3682B4]Highlight[/c]",keywords[s] + " has been mentioned by " + MsgPlus.RemoveFormatCodes(Origin);
            }
        }
    }
}


Should do the same thing, but more efficiently... Could probably be improved upon though. Also, you can add other words into the array apart from names such as words relating to certain topics :p
<Eljay> "Problems encountered: shit blew up" :zippy:
09-28-2008 05:53 PM
Profile PM Find Quote Report
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
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Nickname highlight
Lol. I could have added a space to either side of the word when checking... I should have tested it lol :p
<Eljay> "Problems encountered: shit blew up" :zippy:
09-29-2008 11:05 AM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Nickname highlight
quote:
Originally posted by SpunkyLoveMuff
Lol. I could have added a space to either side of the word when checking... I should have tested it lol :p
And what about if it was a comma, or full-stop, or semicolon, or exclamation mark, etc....?
[Image: markee.png]
09-29-2008 11:22 AM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Nickname highlight
quote:
Originally posted by markee
quote:
Originally posted by SpunkyLoveMuff
Lol. I could have added a space to either side of the word when checking... I should have tested it lol :p
And what about if it was a comma, or full-stop, or semicolon, or exclamation mark, etc....?

RegExp :p

use \W to check that it's not an alphanumeric character before the word. I do agree RegExps are great, but I tried to keep it simple.

It's because of you I started using them in the first place :p
<Eljay> "Problems encountered: shit blew up" :zippy:
09-29-2008 03:34 PM
Profile PM Find Quote Report
Johnny09
New Member
*


Posts: 13
Joined: Sep 2008
O.P. RE: Nickname highlight
yeah, regexp is also a good solution,
thought to use also a reg.expression but at this time ive had a blackout and have forgotten that "new RegExp()" exists ... :P

i have another question,
on highlighting, a message (ToastContact) appears ...

can we handle it like this, when you click on that message, the window where they highlighted your name opens at the same time? (set a focus on that msn window).


// Edit
found something nice on the web

....
MsgPlus.DisplayToastContact("Highlighter", "[c=#3682B4]Highlight[/c]", "'"+ucfirst(highwords[i])+"' has been mentioned by: " + MsgPlus.RemoveFormatCodes(contact.Name), null, "focusMyWin", ChatWnd.Handle);
...

code:
function focusMyWin (dow) {
    Interop.Call('User32','OpenIcon', dow);
    Interop.Call('User32','BringWindowToTop', dow);
    Interop.Call('User32','SetForegroundWindow', dow);
    Interop.Call('User32','ShowWindow', dow, 1);
    Interop.Call('User32','SwitchToThisWindow', dow, "FALSE");
}

This post was edited on 10-03-2008 at 05:47 PM by Johnny09.
10-03-2008 05:26 PM
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