Shoutbox

Need some help with script - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Need some help with script (/showthread.php?tid=93817)

Need some help with script by Barathrum on 02-11-2010 at 07:45 PM

Hello I have this script here:

code:
function OnEvent_ChatWndReceiveMessage(oChatWnd, Email) {
if(Email == "gregorsturm12@hotmail.com") //Change to your target email.
    {
         oChatWnd.SendMessage('You are Ignored'); // Type thetext to be writen within the ' '
    }
}

I need someone to edit it so, that everytime "gregorsturm12@hotmail.com" sends a messege to the user of this script, it will send messege from the user of the script 'You are Ignored'

Currently it seems to not be working.

Thanks for help :)
RE: Need some help with script by Mnjul on 02-11-2010 at 07:51 PM

It probably won't work - the second parameter of OnEvent_ChatWndReceiveMessage is the name of the message sender, not the e-mail.


RE: Need some help with script by Barathrum on 02-11-2010 at 08:31 PM

Hmm, yeah possible, but don't know how to fix it or what to give instead


RE: Need some help with script by matty on 02-11-2010 at 08:44 PM

Javascript code:
// declare an object container
var objChatWnd = {};
 
// store the last message sent into our container
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    objChatWnd[oChatWnd.Handle] = sMessage;
}
 
function OnEvent_ChatWndReceiveMessage(oChatWnd, sOrigin, sMessage, nMessageKind) {
    // check if the message received is our message
    if (objChatWnd[oChatWnd.Handle] === sMessage) {
        // if it is delete the object from the container
        delete objChatWnd[oChatWnd.Handle];
        // return the message to the window
        return sMessage;       
    }
   
    // declare a variable
    var blnIgnoreContact = false;
    // loop through all contacts in the chat
    for (var oContact = new Enumerator(oChatWnd.Contacts); !oContact.atEnd(); oContact.moveNext()) {
        // check the users email
        if (oContact.item().Email === 'gregorsturm12@hotmail.com') {
            // if it matches then set our variable to true
            blnIgnoreContact = true;
        }
    }
   
    // after looping through all contacts check our variable
    if (blnIgnoreContact === true) {
        // send a message if the contact was found
        oChatWnd.SendMessage('You are ignored');
    }
}


RE: Need some help with script by Matti on 02-11-2010 at 09:00 PM

That code could be simplified even further. Look what I found in the documentation!

quote:
Contacts::GetContact
Return Value: A Contact object if the contact is found in the object's list, null otherwise.
You don't even need a loop to check whether that e-mail address is in the list of chat window contacts, just check that Contacts.GetContact(sIgnoredEmail) is not null! Even better, you don't need that flag variable at all, just put that expression straight in the if-condition! :D
Javascript code:
    // check whether the ignored contact is in this chat
    if (oChatWnd.Contacts.GetContact('gregorsturm12@hotmail.com') !== null) {
        // send a message if the contact was found
        oChatWnd.SendMessage('You are ignored');
    }

Pretty nifty, uh? :P
RE: Need some help with script by matty on 02-11-2010 at 09:12 PM

Good catch I forgot about GetContact.


RE: Need some help with script by Barathrum on 02-12-2010 at 11:59 AM

Thank you all for the help, the script now works :)