What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Random Line Away messages

Pages: (2): « First « 1 [ 2 ] Last »
Random Line Away messages
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Random Line Away messages
this is untested code:

code:
var TimeOut = 10    // Timeout in seconds.

var arrEnabled = new Boolean();
var arrTimers = new Array();
var arrMessages = GetAllMessages();


////////////////////////////////////////////////
// FUNCTIONS DIRECTLY RELATED TO THE MESSAGES //
////////////////////////////////////////////////

function GetAllMessages() {
    // Normally you read in all the possible messages from a file in here
    // since that is easier to update.
    return Array(
        "MessageA",
        "MessageB",
        "MessageC",
        "MessageD",
        "MessageE",
        "MessageF"
    );
}

function GetRandomMessage() {
    // Get a random message from the array.
    // Note that in this function you could build in a system
    // to make sure that random messages aren't repeated too much.
    // For example, see: CookieRevised's reply to Random numbers, prevent from being used more than once
    return arrMessages[Math.floor(arrMessages.length * Math.random())];
}


/////////////////////////////////////////////////////
// FUNCTIONS TO ENABLED/DISABLE THE MESSAGE SYSTEM //
/////////////////////////////////////////////////////

function OnEvent_SigninReady() {
    // Check the status of the user and enable/disable everything accordingly.
    OnEvent_MyStatusChange(Messenger.MyStatus);
}

function OnEvent_Signout() {
    // User signed out, so remove all timers. This is highly important and
    // quite often forgotten in many scripts. If we don't do this there is
    // a chance that the timers will still be running when another user signs
    // in and thus they will conflict with his/her timers.
    OnEvent_MyStatusChange(1 /* OFFLINE */);
}

function OnEvent_MyStatusChange(eNewStatus) {
    if (eNewStatus === 6 /* IDLE */ || eNewStatus === 7 /* AWAY */) {
        // Enable everything when the status of the user is set to Away or Idle.
        arrEnabled = true;
    } else {
        // Disable everything and clear the timer array.
        arrEnabled = false;
        for (Id in arrTimers) {
            MsgPlus.CancelTimer("TmrMsg" + Id);
            delete arrTimers[Id];
        }
    }
}



///////////////////////////////////////////////////////
// MAIN FUNCTION WHICH CHECKS AND SENDS THE MESSAGES //
///////////////////////////////////////////////////////

function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, eMsgKind) {
    // First check if the away message system is active or not.
    if (arrEnabled) {
        // Check if the recieved message comes from the user or not.
        // There are better ways to do this though since this will fail if
        // the contact happens to have the same display name as the user.
        if (sOrigin !== Messenger.MyName) {
            // Check if there is already a timer running for this conversation.
            // If so, we have already send a message in the last 10 seconds.
            if (arrTimers[pChatWnd.Handle] !== true) {
                // There isn't a timer running for this conversation yet,
                // so we may send a new random message.
                // But first we should always check if Plus! can send a message.
                if (pChatWnd.EditChangeAllowed) pChatWnd.SendMessage(GetRandomMessage());
                // Add the timer id to our global array so we can check later
                // if it is running or not. Note that this is an unique id.
                // This makes that if there are multiple conversations, they
                // wont influence the delay of other conversations. To make an
                // unique id we use the window handle of the conversation which
                // is always an unique number in Windows.
                arrTimers[pChatWnd.Handle] = true;
            }
            // Initialize the timer for this chat window (again). Note that this
            // is placed outside that last check. This makes that the timer will
            // also be reset in case the contact typed a message before the
            // timeout occured. This means that the contact will never see a new
            // message again as long as he is sending messages within 10 seconds.
            // If you don't want this, and you want the contact to see a new
            // message after 10 seconds, even if he is constantly sending messages
            // himself, then move the next line right after the above line within
            // the previous IF-block.
            MsgPlus.AddTimer(pChatWnd.Handle, TimeOut * 1000);
        }
    }
}


////////////////////////////////////
// FUNCTIONS TO HANDLE THE TIMERS //
////////////////////////////////////

function OnEvent_Timer(sTimerId) {
    // Timeout has elapsed, so remove its indication from the global timer array.
    // Note: the unique identifier, the window handle, starts after "TmrMsg".
    delete arrTimers[sTimerId.substr( 6)];
}

function OnEvent_ChatWndDestroyed(pChatWnd) {
    // A chat window is being closed, so we don't need the timer
    // for this window anymore. Removing this timer makes that
    // we can immediatly reuse its unique value in case a new
    // window with the same handle is created.
    MsgPlus.CancelTimer("TmrMsg" + pChatWnd.Handle);
    delete arrTimers[pChatWnd.Handle];
}


This post was edited on 06-30-2008 at 01:38 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-30-2008 01:35 AM
Profile PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: RE: Random Line Away messages
quote:
Originally posted by CookieRevised
ermmm... that is the most "original" method I've seen to get a random number between x and y...

He at school, I'm known for my originality :P xD

@ Aztek: as soon as CookieRevised mixes himself in a thread, your questions and problems will be fixed in no-time :P
06-30-2008 07:29 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Random Line Away messages
quote:
Originally posted by SmokingCookie
@ Aztek: as soon as CookieRevised mixes himself in a thread, your questions and problems will be fixed in no-time :P
hehe, only if I'm lucky...
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-30-2008 06:52 PM
Profile PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« 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