Advertisement
Guest User

antiflood comandos eggdrop

a guest
Oct 11th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.21 KB | None | 0 0
  1. #Selective Flood Control
  2. #(c) Copyright 2006 Daniel Milstein
  3. #Version 0.1
  4. #Ignores the user if they give too many commands to the bot
  5.  
  6. #To use, add the following line as the first line of the proc for commands whose usage you want limited:
  7. #if {![checkUser $nick $chan]} {return}
  8. #Where $nick is the nick of the person who give the command and $chan is the channel that they give the command on
  9.  
  10. #The user is allowed to send $floodMessages public messages to the bot within $floodTime _seconds_. If s/he exceeds that, the user will be banned from using commands that the above line of code has been added to for $banLength _minutes_
  11. set floodTime 30
  12. set floodMessages 5
  13. set banLength 10
  14.  
  15. #Data structure for users:
  16. #Users is an associative array
  17. #Keys are {{a} {b}}
  18. #If the user is set on ignore, a is the time when the user will be able to talk to the bot again; otherwise, a is 0
  19. #b is the list of times that the user has given commands to the bot; it is cleaned of old entries when checkUser is called
  20.  
  21. proc initUser {host time} {
  22.    #add the user to the array
  23.    global users
  24.    set users($host) [list 0 [list $time]]
  25.    return
  26. }
  27.  
  28. proc checkUser {nick chan} {
  29.    #Get the user's host
  30.    set host [getchanhost $nick $chan]
  31.    
  32.    #Return 1 if the user can give bot commands; otherwise, return 0
  33.    global users banLength floodTime floodMessages
  34.    set time [unixtime]
  35.  
  36.    #check if the array exists yet
  37.    if {![array exists users]} {
  38.       #the array doesn't exist; therefore, the user isn't in the array
  39.       initUser $host $time
  40.       return 1
  41.    }
  42.  
  43.    #check if the user is in the array
  44.    set seenNick 0
  45.    foreach user [array names users] {
  46.       if {$user == $host} {set seenNick 1; break}
  47.    }
  48.    if {$seenNick == 0} {
  49.       #user is not in the array yet
  50.       initUser $host $time
  51.       return 1
  52.    }
  53.    
  54.    #The user is in the array
  55.  
  56.    #Check if the user is banned
  57.  
  58.    if {[lindex $users($host) 0] != 0} {
  59.       #User is banned; check if the ban has expired
  60.       if {[lindex $users($host) 0] <= $time} {
  61.      #Ban has expired; unset the ban, add $time to the record of the user giving bot commands, and have the bot listen
  62.      array set users [list $host [list 0 [list $time]]]
  63.          return 1
  64.       }
  65.       #The ban has not expired; ignore the user
  66.       return 0
  67.    }
  68.  
  69.    #Sort through the times that the user has sent a message; if the message happend within the last $floodTime seconds, the time is put into messages. Also, put the latest time in messages
  70.    set messages {}
  71.    foreach m [lindex $users($host) 1] {
  72.       if {[expr $time-$m] <= $floodTime} {
  73.      lappend messages $m
  74.       }
  75.    }
  76.    lappend messages $time
  77.    array set users [list $host [list 0 $messages]]
  78.  
  79.    #Check to see if the size of messages has exceeded $floodMessages
  80.    if {[llength $messages] > $floodMessages} {
  81.       #The user is flooding the channel with bot commands; ban him/her!
  82.       putchan $chan "0,4 WARNING!!!2,0 $nick: 1Voy a ignorar sus comandos públicos por4 $banLength1 minutos. 0,4 NO FLOOD "
  83.       array set users [list $host [list [expr $time+($banLength*60)] {}]]
  84.       return 0
  85.    }
  86.  
  87.    #All is well; update the user status and let the user have his/her bot fun
  88.    return 1
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement