Shoutbox

Random Line Away messages - 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: Random Line Away messages (/showthread.php?tid=84580)

Random Line Away messages by Aztek on 06-29-2008 at 02:40 AM

Hello

I would like an script that can take lines of strings and send them randomly every 10 seconds if i am away and receive a message but only send the message once every 10 seconds and only if the contact has sent a message

example:

contact: hi
me: Automessage: randomline
10+ seconds later
contact: hi
me: Automessage: randomline2
less than 10 seconds later
contact: hi
... (nothingness)
10+ seconds later
contact: hi
me: Automessage: randomline3


RE: Random Line Away messages by SmokingCookie on 06-29-2008 at 04:44 PM

Hello Aztek,

I understand that you want the script to send a random message, ten seconds after a contact has sent a message to you (please correct me if I'm wrong)?


RE: Random Line Away messages by Aztek on 06-29-2008 at 05:12 PM

no the message is sent instantly after reciving a message but if the contact says something within 10 seconds nothing is sent but if he/she waits for over 10 seconds to send the next message another random message is sent


RE: Random Line Away messages by SmokingCookie on 06-29-2008 at 05:29 PM

Okay..

I have an idea that _should_ work (can't guarantee though):

code:
var RandomMessages = new Array("Message 0","Message 2",...,"Message9"); // no further than 9
OnEvent_ChatWndReceiveMessage(pChatWnd,mOrigin,sMessage,kMsgKind) {
      cWnd = pChatWnd;
      if(!TimerStarted) {
            if(mOrigin != Messenger.MyName) {
                  TimerStarted = true;
                  MsgPlus.AddTimer("TmrMsg",10000);
            }
      } else {
            MsgPlus.CancelTimer("TmrMsg");
            TimerStarted = false;
      }
      return sMessage;
}

function OnEvent_Timer(sTimerId) {
      if(sTimerId == "TmrMsg") {
            if(TimerStarted) {
                  cWnd.SendMessage(RandomMessage());
                  MsgPlus.AddTimer("TmrMsg",10000);
            }
      }
}

function RandomMessage() {
      Index = Math.random().charAt(4);
      return RandomMessages[Index];
}


EDIT::

Maybe you should prefix the messages with "AutoMessage: ", since this uses Plus!'s AutoMessage feature (when a personalised status is used)..
RE: Random Line Away messages by Aztek on 06-29-2008 at 05:31 PM

how could i put more than 9 ??


RE: Random Line Away messages by SmokingCookie on 06-29-2008 at 05:33 PM

Uhm.. Please let me think for another 10 seconds....

EDIT::

Change the last function to:[

code:

var Index = new Array();

function RandomMessage() {
      Index[0] = Math.random().charAt(4); // could be any number between 2 and 18
      Index[1] = Math.random().charAt(7); //  // could be any number between 2 and 18
      Index[2] = Math.random().substr(Index[0],Index[1]); // Please note!! You need 99 messages, or the chat will send "undefined";
      return RandomMessages[Index[2]];
}



RE: Random Line Away messages by Aztek on 06-29-2008 at 05:42 PM

nice but could you send the entire script ?

im having problems assembling this thingy :P

as i said, im VERY bad at jscript (or well i did on irc)

edit: oh and i have 460 messages to put into the script :P


RE: Random Line Away messages by SmokingCookie on 06-29-2008 at 06:03 PM

I'm sorry, I no longer have time now, have to go.
I'll give it another try tomorrow..


RE: Random Line Away messages by CookieRevised on 06-29-2008 at 11:12 PM

quote:
Originally posted by SmokingCookie
Uhm.. Please let me think for another 10 seconds....

EDIT::

Change the last function to:
code:
var Index = new Array();

function RandomMessage() {
      Index[0] = Math.random().charAt(4); // could be any number between 2 and 18
      Index[1] = Math.random().charAt(7); //  // could be any number between 2 and 18
      Index[2] = Math.random().substr(Index[0],Index[1]); // Please note!! You need 99 messages, or the chat will send "undefined";
      return RandomMessages[Index[2]];
}



ermmm... that is the most "original" method I've seen to get a random number between x and y...

The proper way would be to multiply the random number (which is always a decimal number between 0 and 1) with a certain upper bound number to enlarge it, and maybe add another lower bound number to start the random number from...

Math.floor((upperbound - lowerbound + 1) * Math.random() + lowerbound);

see "CookieRevised's reply to [Request] Random Number Generator"...

And you might also check "CookieRevised's reply to Random numbers, prevent from being used more than once" for a snippet very related to this random message sending stuff...

Anyways, the script you've posted so far doesn't work at all like Aztek wanted.

Sorry to be so negative though... :(:$ But way cool that you at least tried to help.

Anyways, Aztek, did you already checked the official scripting Database? I wouldn't be surprised if the script you ask for already exists...
RE: Random Line Away messages by Aztek on 06-29-2008 at 11:16 PM

CookieRevised, could you fix it ?


RE: Random Line Away messages by CookieRevised on 06-30-2008 at 01:35 AM

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];
}


RE: RE: Random Line Away messages by SmokingCookie on 06-30-2008 at 07:29 AM

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
RE: Random Line Away messages by CookieRevised on 06-30-2008 at 06:52 PM

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...