Shoutbox

[Help] ChatWndReceiveMessage function - 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: [Help] ChatWndReceiveMessage function (/showthread.php?tid=88772)

[Help] ChatWndReceiveMessage function by SquidWeed on 01-28-2009 at 10:52 PM

Hello,
I'm new to scripting in msgPlus.
I made a script that sends a message as soon as it recieves one.
for some reason, after a random amount of messages recieved, ChatWndReceiveMessage function stops responding.
It start responding again only when the next message is recieved.

I would like to know why it stops responding, and how can I stop this from happening?

tnx in advance,
SquidWeed


RE: [Help] ChatWndReceiveMessage function by djdannyp on 01-28-2009 at 11:04 PM

Can you post your code?


RE: [Help] ChatWndReceiveMessage function by SquidWeed on 01-28-2009 at 11:15 PM

function OnEvent_Initialize(MessengerStart)
{
activated=false;
contact=null;
msgs=new Array("bb","cya","have fun","good night");
}

function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    if(Message == "*bye*"){
        activated=!activated;
        var e = new Enumerator(ChatWnd.Contacts);
        contact=e.item();
    }
}
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
    if(activated && contact.Name==Origin) ChatWnd.SendMessage(msgs[Math.ceil(Math.random()*msgs.length)]);
}


RE: [Help] ChatWndReceiveMessage function by Matti on 01-29-2009 at 04:50 PM

Messenger Plus! Live has a built-in flood protection on the ChatWnd.SendMessage function, which prevents a script from sending lots and lots of messages - I think the limit was 10 or 15 or so. I guess that's what you've encountered here, and there's nothing you can do to make it send more. Perhaps you could add a delay of 1 or 2 seconds in your ReceiveMessage event with MsgPlus.AddTimer and OnEvent_Timer to somehow work around this problem, although I'm not very sure whether it'll stop the flood protection.


RE: [Help] ChatWndReceiveMessage function by Spunky on 01-29-2009 at 06:31 PM

quote:
Originally posted by Matti
Messenger Plus! Live has a built-in flood protection on the ChatWnd.SendMessage function, which prevents a script from sending lots and lots of messages - I think the limit was 10 or 15 or so. I guess that's what you've encountered here, and there's nothing you can do to make it send more. Perhaps you could add a delay of 1 or 2 seconds in your ReceiveMessage event with MsgPlus.AddTimer and OnEvent_Timer to somehow work around this problem, although I'm not very sure whether it'll stop the flood protection.


IIRC flood protection is at 15 messages at which point the user needs to send a message for it to be reset
RE: [Help] ChatWndReceiveMessage function by SquidWeed on 01-30-2009 at 02:44 AM

I already tried to add a delay of 2 seconds, it didn't work.
And I'm not sure it's a flood protection, because It never gets to 15 messages, the number of messages sent is between 3 to 12.

Besides that, I'm sending only one message at the time so basically it's not flooding, it's an auto-respond

tnx for your replies!


RE: [Help] ChatWndReceiveMessage function by SquidWeed on 02-17-2009 at 10:33 PM

any other suggestions?


RE: [Help] ChatWndReceiveMessage function by SquidWeed on 02-22-2009 at 11:34 PM

Last bump I guess, :(


RE: [Help] ChatWndReceiveMessage function by matty on 02-22-2009 at 11:49 PM

Your code is wrong. What is happening is that the random number generated can potentially be 4 because the length of the array is 4. However an Array is zero based meaning it starts counting at 0 not 1. Therefore you need to have msgs.length-1. Like so: When you are using Math.floor you do not need to subtract 1 from the length of the array

js code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
    if(activated && contact.Name==Origin) ChatWnd.SendMessage(msgs[Math.floor(Math.random()*msgs.length)]);
}

You need to use Math.floor not Math.ceil. Math.floor will round down to the nearest integer where Math.ceil rounds upwards.