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 |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
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
<Eljay> "Problems encountered: shit blew up"
|
|
09-28-2008 05:53 PM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
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.
|
|
09-29-2008 11:01 AM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
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
<Eljay> "Problems encountered: shit blew up"
|
|
09-29-2008 11:05 AM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
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
And what about if it was a comma, or full-stop, or semicolon, or exclamation mark, etc....?
|
|
09-29-2008 11:22 AM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
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
And what about if it was a comma, or full-stop, or semicolon, or exclamation mark, etc....?
RegExp
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
<Eljay> "Problems encountered: shit blew up"
|
|
09-29-2008 03:34 PM |
|
|
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 ...
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 |
|
|
|
|