What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » anti flood to my script

anti flood to my script
Author: Message:
Damire
New Member
*


Posts: 1
Joined: Nov 2011
O.P. anti flood to my script
hey i just made a script that anyone on my contacts can call just by tiping the command  "-comandtest" for example then the scripts sends a text that i made  all good but,  you know those friends start flooding me  with the command
i cant find a function to give my command a cooldown so  the command can be called for like every 10 secs or  if it is called for more than 5 times  ignore the call
sry for my bad english and  help me please if you can
THANKS
11-19-2011 02:01 AM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: anti flood to my script
For the timing cool down, you could set a variable to false when the command is used, and use MsgPlus::AddTimer() to set a delay for changing it back to true.  Then, only allow sending the text if the variable is true.

js code:
var AllowCmd = true;

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message, Origin, MsgKind)
{
    if (Message === "-comandtest" && AllowCmd)
    {
        ChatWnd.SendMessage("Command successful!"); // or whatever you want to send
        AllowCmd = false;
        MsgPlus.AddTimer("CoolDown", 10000)
    }
}

function OnEvent_Timer(TimerId)
{
    if (TimerId === "CoolDown")
    {
        AllowCmd = true;
    }
}

As for ignoring after so many calls, you would need to keep count and check each time how many have been sent.  You'd also need to add in some way of resetting the count after so long.

js code:
var CmdCount = 0;

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message, Origin, MsgKind)
{
    if (Message === "-comandtest" && CmdCount < 5)
    {
        ChatWnd.SendMessage("Command successful!"); // or whatever you want to send
        CmdCount += 1;
    }
}
11-25-2011 10:37 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: anti flood to my script
Taking it one step further, making it work on a per contact basis...

js code:
var oContacts = {};

function OnEvent_ChatWndReceiveMessage(ChatWnd, Message, Origin, MsgKind)
{
    if (Message === "-comandtest" && (oContacts[Origin].AllowCmd || typeof oContacts[Origin] === 'undefined'))
    {
        ChatWnd.SendMessage("Command successful!"); // or whatever you want to send
        oContacts[Origin].AllowCmd = false;
        MsgPlus.AddTimer(Origin, 10000)
    }
}

function OnEvent_Timer(TimerId)
{
        oContacts[TimerId].AllowCmd =  true;
}

This post was edited on 11-26-2011 at 12:27 PM by matty.
11-26-2011 12:25 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: anti flood to my script
quote:
Originally posted by matty
Taking it one step further, making it work on a per contact basis...


Unless they change their name :p

<Eljay> "Problems encountered: shit blew up" :zippy:
11-26-2011 03:42 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: anti flood to my script
Good point... It was 7:30am... I shouldn't post so early!
11-27-2011 01:08 AM
Profile E-Mail PM Find Quote Report
« 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