In addition to built-in flood control, you can easily add flood control to a script with a variable. Here's is a basic example letting a user request the time at the bot's location:
on *:text:!time:#: {
msg $chan The time right now is: $time
}
Now, you don't want that to display over and over if someone tries to flood the bot. Here's a flood control solution:
on *:text:!time:#: {
if (%flood) { return }
set -u10 %flood On
msg $chan The time right now is: $time
}
Flood will be set for 10 seconds and the unset itself. If the command is used during that 10 seconds, nothing happens. Now, you might want to allow multiple people to access a command in a short time, but not a single person. For that, you can use a dynamic variable:
on *:text:!time:#: {
if ($($+(%,flood.,$nick),2)) { return }
set -u10 %flood. $+ $nick On
msg $chan The time right now is: $time
}
That will do the same thing as above, but will let many people use the command at in a short time, but each person can only use it once every 10 seconds. You can also combine the two...
on *:text:!time:#: {
if ($($+(%,flood.,$nick),2) || %flood) { return }
set -u3600 %flood. $+ $nick On
set -u60 %flood On
msg $chan The time right now is: $time
}
This will let !time be used once every 60 seconds as long as it's used by different nicks. Each nick can only use the command once every 3600 seconds (1 hour). The combination lets you limit how often it can be used by everyone and prevent a single person from using the command more often than necessary (a single person doesn't need to know the time every minute, but another person might need to know it within that amount of time).
You can use combinations of these to set up some good protection based on what you need for each command.
Here's an example of how to do this for many events without repeating it in each:
on *:text:!time:#: {
if ($floodcontrol(!time,60,3600)) { return }
msg $chan The time right now is: $time
}
on *:text:!date:#: {
if ($floodcontrol(!date,60,3600)) { return }
msg $chan The date right now is: $date
}
alias floodcontrol {
if ($($+(%,flood.,$1,.,$nick),2) || $($+(%,flood.,$1),2)) { return $true }
set $+(-u,$3) %flood. $+ $+($1,.,$nick) On
set $+(-u,$2) %flood. $+ $1 On
return $false
}
* Note that I couldn't test this, but it should work.
Wherever you want flood control, you would insert:
if ($floodcontrol(!date,60,3600)) { return }
Everything after that will not occur if the flood control check returns $true.
!date would be the command. This lets you have different flood control for each command. 60 is the time (seconds) between each time the command can be used by different people. 3600 is the time (in seconds) between each time the command can be used by a single person.
If you want to have multiple commands use the same flood timer, just put the same word/command/etc in place of !date. For example, if you wanted !date and !time to use the same timer (so a person can use one or the other but not both within the time frame), you might use datetime instead of !date.
If you want to also include an overall flood control, you can modify the alias like this:
alias floodcontrol {
if ($($+(%,flood.,$1,.,$nick),2) || $($+(%,flood.,$1),2) || %flood) { return $true }
set $+(-u,$3) %flood. $+ $+($1,.,$nick) On
set $+(-u,$2) %flood. $+ $1 On
set -u5 %flood On
return $false
}
That would set an overall flood control at 5 seconds. This would prevent any command that uses this floodcontrol alias from being used for 5 seconds after the previous command was used, no matter who uses it or what the command is. This would normally be set to a very low number if you used it and is mainly to prevent you from being flooded off the network for replying too many times in a short amount of time.