mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2011
Posts: 1
Y
Ydoow Offline OP
Mostly harmless
OP Offline
Mostly harmless
Y
Joined: Jun 2011
Posts: 1
I've got my bot in a channel, but of course people want to flood my bot with commands until the admins kick my bot because the others won't stop.

So basically what I want is flood protection, but because I'm not an admin I can't kick or ban the spammers.
My idea was to just ignore the people so my bot doesn't react to them. (however if you have a better idea let me know).


I've looked all over for scripts like this, but I can't find one like this. I also would like to create my own instead.

I was thinking to do an on TEXT event, then establish variables for the $nick and a variable named after the nick which would count his posts per second. A 1 second timer would be created, and after it ends it would delete both variables.

So my biggest problem is how to name a variable after $Nick.
It would be %$Nick, which I know wont work.
I looked into using brackets [ ], but for the life of me I cannot make it work. The guides I've been using are lacking some sort of explanation, or it's been going right over my head lol.

I was going to provide with some code I've already written, but it's so incomplete and incorrect, it really wouldn't do you any good.

So if the variable $nick (lets pretend $nick = nommer) counts to 3 in under 1 second, it will issue a command to ignore nommer.

The reason I wanted to make each variable named after the $nick was so that I could control who it counts for. I didn't want it counting for 3 different people who all posted within the same second. I believe you'd need to make sure it checks who said what, because the script doesn't instantiate a new variable each time the event is triggered, right?

So any help would be appreciated. Whether you just explain what I'd have to do, give me an actual script that does it (please explain steps so I can learn from it), or just explain a few things for me.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Alt+O -> IRC -> Flood

Done.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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:

Code:
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:

Code:
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:

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

Code:
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:

Code:
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. smile

Wherever you want flood control, you would insert:

Code:
  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:

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

Last edited by Riamus2; 23/06/11 09:42 PM.

Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard