quote:
Originally posted by ryannathans
how about a code for saying heyy only if the contact has NOT been on in the last 10 mins?
That's a bit more difficult. Basically, you'd have to store the time when they went online in some kind of global object and when they come online again, check the time difference first before sending the message.
Here's some documented example code. Have a look at it first, make sure you understand what I've done and then try it out.
js code:
/* Global variables */
var sHelloMessage = "Hey!"; //Message to send on contact sign-in
var oContactSigninTimes = {}; // Store for the contact signin times
var nMinSigninInterval = 10 * 60 * 1000; // 10 minutes (expressed in milliseconds)
function OnEvent_ContactSignin( sEmail ) {
// Set up some local variables
var nTime = new Date().getTime(); //Get the current time, as a number
var nLastSignin = 0; //Placeholder for the contact's last sign-in time
// First check if we have a logged sign-in time
if( nLastSignin = oContactSigninTimes[sEmail] ) {
// Compare it to the time now
if( (nTime - nLastSignin) < nMinSigninInterval ) {
// If the difference is less than the configured interval,
// stop further execution of this function.
return;
}
}
// If we don't have a previously logged sign-in time or
// if the difference is greater than the configured interval,
// store the current time and send the message.
oContactSigninTimes[sEmail] = nTime;
Messenger.OpenChat(sEmail).SendMessage(sHelloMessage);
}
Oh, and by the way: we have an
button here, no need for double post in less than a minute!