Shoutbox

anti flood to my script - 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: anti flood to my script (/showthread.php?tid=98567)

anti flood to my script by Damire on 11-19-2011 at 02:01 AM

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


RE: anti flood to my script by whiz on 11-25-2011 at 10:37 PM

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

RE: anti flood to my script by matty on 11-26-2011 at 12:25 PM

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

RE: anti flood to my script by Spunky on 11-26-2011 at 03:42 PM

quote:
Originally posted by matty
Taking it one step further, making it work on a per contact basis...


Unless they change their name :p


RE: anti flood to my script by matty on 11-27-2011 at 01:08 AM

Good point... It was 7:30am... I shouldn't post so early!