Algabe

blacklist

Aug 12th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 17.16 KB | None | 0 0
  1. #############################################################################
  2. #                                                                           #
  3. # Coded by: Opposing ([email protected])                                     #
  4. # Version : 1.4                                                             #
  5. # Released: November 29, 2010                                               #
  6. # Source  : http://Sir-Fz.blogspot.com/                                     #
  7. ##                                                                          #
  8. # Description: A blacklist script that stores the banned masks in a db file #
  9. #              and bans everyone who matches the blacklisted masks on join  #
  10. #              or when the bot gets op.                                     #
  11. #                                                                           #
  12. # Available Commands:                                                       #
  13. # - DCC: .addbl <nick>!<user>@<host> [reason] [bantime] : Adds ban.         #
  14. #        .rembl <nick>!<user>@<host>                    : Deletes ban.      #
  15. #        .listbl                                        : Lists bans.       #
  16. # - PUB: addbl <nick>!<user>@<host> [reason] [bantime]  : Adds ban          #
  17. #        rembl <nick>!<user>@<host>                     : Deletes ban.      #
  18. #        listbl                                         : Lists bans.       #
  19. #                                                                           #
  20. # USE (DCC) .chanset #channel +blacklist to enable blacklist on a channel.  #
  21. #                                                                           #
  22. # Credits:                                                                  #
  23. #         Thanks to strikelite and user (if I recall correctly) from the    #
  24. #         egghelp.org forum for helping me with this script (back in 2003). #
  25. #         Also used user's (egghelp.org forum) maskhost proc.               #
  26. #                                                                           #
  27. # History:                                                                  #
  28. #         - 1.4: Fixed a bug when using the bansame option where nicknames  #
  29. #           with special characters (\, [, ]) were not properly banned.     #
  30. #         - 1.3: Added Flooding out protection, where the bot will start    #
  31. #           using the slowest queue in case a number of blacklisted users   #
  32. #           join in a certain period of seconds which can be defined by the #
  33. #           user. + fixed a bug with brackets.                              #
  34. #         - 1.2: Fixed a few bugs and made the script create the blacklist  #
  35. #           file if it doesn't exist.                                       #
  36. #         - 1.1: added the black list chan flag, and other features into    #
  37. #           patterns of handling the blacklist.                             #
  38. #         - 1.0: First release.                                             #
  39. #                                                                           #
  40. # Report bugs/suggestions to [email protected]                               #
  41. #                                                                           #
  42. # Copyright © 2005 Opposing (aka Sir_Fz)                                    #
  43. #                                                                           #
  44. # This program is free software; you can redistribute it and/or modify      #
  45. # it under the terms of the GNU General Public License as published by      #
  46. # the Free Software Foundation; either version 2 of the License, or         #
  47. # (at your option) any later version.                                       #
  48. #                                                                           #
  49. # This program is distributed in the hope that it will be useful,           #
  50. # but WITHOUT ANY WARRANTY; without even the implied warranty of            #
  51. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
  52. # GNU General Public License for more details.                              #
  53. #                                                                           #
  54. # You should have received a copy of the GNU General Public License         #
  55. # along with this program; if not, write to the Free Software               #
  56. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA #
  57. #                                                                           #
  58. #############################################################################
  59. #
  60. ##############################
  61. # Configurations start here: #
  62. # __________________________ #
  63.  
  64. ## Blacklist File:
  65. set blackl(file) "scripts/blacklist.txt"
  66.  
  67. ## Blacklist "Excess Flood" protection. Set here how many blacklisted users are allowed
  68. ## to join in how many seconds before using the slow queue in order for the bot not to
  69. ## flood out with reason "Excess Flood."
  70. set blackl(punish) 4:2
  71.  
  72. ## Do you want the bot to also check for blacklisted users on op ? (0: no / 1: yes)
  73. set blackl(checkop) 1
  74.  
  75. ## Do you want to ban the same ban from the blacklist file
  76. ## or do you want it to be spcific ? (0: specific / 1: same ban as the file)
  77. ### example:
  78. ## Suppose that *!lamest@* is banned.
  79. # .. bot sets mode +b *!lamest@*
  80. # .. lamer kicked by bot "Blacklisted user."
  81. ## This happens if this option is set to 1.
  82. ## but if you set it to 0, then you can choose what bantype you want to ban.
  83. set blackl(bansame) 0
  84.  
  85. ## if blackl(bansame) is set to 0:
  86. ## What ban type do you want to ban ?
  87. # 2: *!*@full.host.tld
  88. # 3: *!*user@*.host.tld
  89. # 4: *!*@*.host.tld
  90. # 6: nick!*[email protected]
  91. # 7: nick!*@full.host.tld
  92. # 8: nick!*user@*.host.tld
  93. # 9: nick!*@*.host.tld
  94. set blackl(btype) 2
  95.  
  96. ## Set default ban reason if not specified.
  97. ## NOTE: use %requester to use the nick of the one who set the ban.
  98. set blackl(kmsg) "Banned: Requested by %requester"
  99.  
  100. ## set default ban time (in minutes) if no bantime specified. (0 means no ban time)
  101. set blackl(btime) 0
  102.  
  103. ## Do you want the ban to be removed from the file after ban time expires ? (0: no / 1: yes)
  104. ## if set to 0, the bot will only remove the ban from the channel but not from the file.
  105. set blackl(rbabt) 0
  106.  
  107. ## Set here the trigger for public commands.
  108. ## example: set blackl(trig) "!"
  109. ## now using !listbl on main will show the blacklist.
  110. set blackl(trig) "!"
  111.  
  112. ## Set flags that are allowed to use these commands.
  113. ## <global flags>|<channel flags>
  114. set blackl(flags) n|-
  115.  
  116. # Configurations end here. #
  117. ############################
  118. #
  119. ######################################################################
  120. # Code starts here, please do not edit anything unless you know TCL: #
  121. # __________________________________________________________________ #
  122.  
  123. bind join - * bl:ban
  124. bind dcc $blackl(flags) addbl bl:add
  125. bind dcc $blackl(flags) rembl bl:rem
  126. bind dcc $blackl(flags) listbl bl:list
  127. bind pubm $blackl(flags) * bl:pub
  128. bind mode - "* +o" bl:cop
  129. setudef flag blacklist
  130.  
  131. if {[file exists $blackl(file)]} {
  132.  set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  133. } {
  134.  set BLNicks [list]
  135. }
  136.  
  137. foreach {blackl(lim) blackl(secs)} [split $blackl(punish) :] {break}
  138.  
  139. proc bl:ban {nick uhost hand chan} {
  140.  global BLNicks blackl blflood
  141.  if {![botisop $chan] || ![channel get $chan blacklist]} {return 0}
  142.  if {![info exists blflood([set chan [string tolower $chan]])]} { set blflood($chan) 0 }
  143.  foreach blnick $BLNicks {
  144.   if {[string match -nocase [set ban [lindex [split $blnick] 0]] $nick!$uhost]} {
  145.    set ban [string map {\\\\ \\ \\\[ \[ \\\] \]} $ban]
  146.    if {[blfollow $blackl(secs) blflood($chan)] < $blackl(lim)} {
  147.     putquick "KICK $chan $nick :[string map [list %requester [lindex [split $blnick] 1]] [join [lrange [split $blnick] 2 end-1]]]"
  148.     if {$blackl(bansame)} {
  149.      putquick "MODE $chan -o+b $nick $ban"
  150.      if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  151.       timer $btime [list rem:blban $chan $ban]
  152.      }
  153.     } {
  154.      putquick "MODE $chan -o+b $nick [set aban [blbtype $nick!$uhost $blackl(btype)]]"
  155.      if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  156.       timer $btime [list rem:blban $chan $aban]
  157.      }
  158.     }
  159.    } {
  160.     puthelp "KICK $chan $nick :[string map [list %requester [lindex [split $blnick] 1]] [join [lrange [split $blnick] 2 end-1]]]"
  161.     if {$blackl(bansame)} {
  162.      pushmode $chan -o $nick
  163.      pushmode $chan +b $ban
  164.      if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  165.       timer $btime [list rem:blban $chan $ban]
  166.      }
  167.     } {
  168.      pushmode $chan -o $nick
  169.      pushmode $chan +b [set aban [blbtype $nick!$uhost $blackl(btype)]]
  170.      if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  171.       timer $btime [list rem:blban $chan $aban]
  172.      }
  173.     }
  174.    }
  175.    putlog "\[\002BlackList\002\]: Banned \002$nick\002!\002$uhost\002 matching [string map {! \002!\002 @ \002@\002} \002$ban\002] on \002$chan\002"
  176.    break
  177.   }
  178.  }
  179. }
  180.  
  181. proc bl:add {hand idx arg} {
  182.  if {$arg == ""} { putlog "SYNTAX: \003.addbl <nick!user@host> \[reason\] \[btime\]\003"; return 0 }
  183.  if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 0]]]} {
  184.   putlog "SYNTAX: \003.addbl \002<nick>\002!\002<user>\002@\002<host>\002 \[reason\] \[bantime\]\003"
  185.   return 0
  186.  }
  187.  if {[bl:do:add $hand $arg]} {
  188.   foreach chan [channels] {
  189.    if {![channel get $chan blacklist]} { continue }
  190.    foreach ubchecked [chanlist $chan] {
  191.     bl:ban $ubchecked [getchanhost $ubchecked $chan] [nick2hand $ubchecked] $chan
  192.    }
  193.   }
  194.   putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] has been \002added\002 to the blacklist."
  195.  } {
  196.   putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] already \002exists\002 in the blacklist."
  197.  }
  198. }
  199.  
  200. proc bl:do:add {hand arg} {
  201.  global blackl BLNicks
  202.  set added 0
  203.  if {[llength [lrange [split $arg] 1 end]] == 1} {
  204.   if {[string is integer [lindex [split $arg] end]]} {
  205.    set kreason "$blackl(kmsg)"
  206.    set btime "[lindex [split $arg] end]"
  207.   } else {
  208.    set kreason "[lrange [split $arg] 1 end]"
  209.    set btime "$blackl(btime)"
  210.   }
  211.  } elseif {[llength [lrange [split $arg] 1 end]] > 1} {
  212.   if {[string is integer [lindex [split $arg] end]]} {
  213.    set kreason "[join [lrange [split $arg] 1 end-1]]"
  214.    set btime "[lindex [split $arg] end]"
  215.   } else {
  216.    set kreason "[join [lrange [split $arg] 1 end]]"
  217.    set btime "$blackl(btime)"
  218.   }
  219.  } else {
  220.   set kreason "$blackl(kmsg)"
  221.   set btime "$blackl(btime)"
  222.  }
  223.  if {![file exists $blackl(file)]} {
  224.   set temp [open $blackl(file) w]
  225.   close $temp
  226.  }
  227.  set blnick "[string map {\\ \\\\ \[ \\\[ \] \\\]} [lindex [split $arg] 0]]"
  228.  if {![we:can:find:ban $blnick add]} {
  229.   puts [set fs [open $blackl(file) a]] "$blnick $hand $kreason $btime"
  230.   close $fs
  231.   set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  232.   set added 1
  233.  }
  234.  set added
  235. }
  236.  
  237. proc bl:rem {hand idx arg} {
  238.  if {$arg == ""} { putlog "SYNTAX: \003.rembl <nick!user@host>\003"; return 0 }
  239.  if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 0]]]} {
  240.   putlog "SYNTAX: \003.rembl \002<nick>\002!\002<user>\002@\002<host>\002\003"
  241.   return 0
  242.  }
  243.  if {[bl:do:rem $arg]} {
  244.   foreach chan [channels] {
  245.    if {![channel get $chan blacklist]} { continue }
  246.    foreach ban [chanbans $chan] {
  247.     if {[string match -nocase $blnick [set sban [lindex $ban 0]]]} {
  248.      pushmode $chan -b $sban
  249.     }
  250.    }
  251.   }
  252.   putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002deleted\002 from the blacklist."
  253.  } {
  254.   putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002not\002 found in the blacklist."
  255.  }
  256. }
  257.  
  258. proc bl:do:rem arg {
  259.  global blackl BLNicks
  260.  set remmed 0
  261.  set blnick [lindex [split $arg] 0]
  262.  if {![file exists $blackl(file)]} {
  263.   set temp [open $blackl(file) w]
  264.   close $temp
  265.  }
  266.  if {[we:can:find:ban $blnick rem]} {
  267.   set z ""
  268.   set a [open $blackl(file) r]
  269.   while {![eof $a]} {
  270.    set b [gets $a]
  271.    if {![string equal -nocase [lindex $b 0] $blnick]} { lappend z ${b} }
  272.   }
  273.   close $a
  274.   set n [open $blackl(file) w]
  275.   foreach k $z {
  276.    if {$k != ""} { puts $n $k }
  277.   }
  278.   close $n
  279.   set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  280.   set remmed 1
  281.  }
  282.  set remmed
  283. }
  284.  
  285. proc bl:list {hand idx arg} {
  286.  global BLNicks
  287.  if {[string equal "{} {}" $BLNicks] || [string equal "" $BLNicks]} {
  288.   putlog "There are \002no\002 bans in the blacklist."
  289.  } {
  290.   set c 1
  291.   foreach blnick $BLNicks {
  292.    if {$blnick != ""} {
  293.     putlog "\[\002$c\002\] - \002Mask\002: [lindex [split $blnick] 0] - \002Requester\002: [lindex [split $blnick] 1] - \002Bantime\002: [lindex [split $blnick] end]"
  294.     incr c
  295.    } {
  296.     putlog "\[\002*\002\] - End of list."
  297.    }
  298.   }
  299.  }
  300. }
  301.  
  302. proc bl:pub {nick uhost hand chan arg} {
  303.  global blackl BLNicks
  304.  if {![string equal $blackl(trig) [string index $arg 0]]} {return 0}
  305.  switch -- [lindex [lindex [split $arg $blackl(trig)] 1] 0] {
  306.   "addbl" {
  307.    if {[join [lrange [split $arg] 1 end]] == ""} { puthelp "NOTICE $nick :SYNTAX: \003$blackl(trig)addbl <nick!user@host> \[reason\] \[btime\]\003"; return 0 }
  308.    if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 1]]]} {
  309.     puthelp "NOTICE $nick :SYNTAX: \003$blackl(trig)addbl \002<nick>\002!\002<user>\002@\002<host>\002 \[reason\] \[bantime\]\003"
  310.     return 0
  311.    }
  312.    if {[bl:do:add $hand [join [lrange [split $arg] 1 end]]]} {
  313.     if {[channel get $chan blacklist]} {
  314.      foreach ubchecked [chanlist $chan] {
  315.       bl:ban $ubchecked [getchanhost $ubchecked $chan] [nick2hand $ubchecked] $chan
  316.      }
  317.     }
  318.     puthelp "NOTICE $nick :[string map {! \002!\002 @ \002@\002} \002$blnick\002] has been \002added\002 to the blacklist."
  319.    } {
  320.     puthelp "NOTICE $nick :[string map {! \002!\002 @ \002@\002} \002$blnick\002] already \002exists\002 in the blacklist."
  321.    }
  322.   }
  323.   "rembl" {
  324.    if {[join [lrange [split $arg] 1 end]] == ""} { puthelp "NOTICE $nick :SYNTAX: \003$blackl(trig)rembl <nick!user@host>\003"; return 0 }
  325.    if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 1]]]} {
  326.     puthelp "NOTICE $nick :SYNTAX: \003$blackl(trig)rembl \002<nick>\002!\002<user>\002@\002<host>\002\003"
  327.     return 0
  328.    }
  329.    if {[bl:do:rem [join [lrange [split $arg] 1 end]]]} {
  330.     if {[channel get $chan blacklist]} {
  331.      foreach ban [chanbans $chan] {
  332.       if {[string match -nocase $blnick [set sban [lindex $ban 0]]]} {
  333.        pushmode $chan -b $sban
  334.       }
  335.      }
  336.     }
  337.     puthelp "NOTICE $nick :[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002deleted\002 from the blacklist."
  338.    } {
  339.     puthelp "NOTICE $nick :[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002not\002 found in the blacklist."
  340.    }
  341.   }
  342.   "listbl" {
  343.    if {[string equal "{} {}" $BLNicks] || [string equal "" $BLNicks]} {
  344.     puthelp "NOTICE $nick :There are \002no\002 bans in the blacklist."
  345.    } {
  346.     set c 1
  347.     foreach blnick $BLNicks {
  348.      if {$blnick != ""} {
  349.       puthelp "NOTICE $nick :\[\002$c\002\] - \002Mask\002: [lindex [split $blnick] 0] - \002Requester\002: [lindex [split $blnick] 1] - \002Bantime\002: [lindex [split $blnick] end]"
  350.       incr c
  351.      } {
  352.       puthelp "NOTICE $nick :\[\002*\002\] - End of list."
  353.      }
  354.     }
  355.    }
  356.   }
  357.  }
  358. }
  359.  
  360. proc bl:cop {nick uhost hand chan mc targ} {
  361.  global blackl
  362.  if {[isbotnick $targ] && $blackl(checkop) && [channel get $chan blacklist]} {
  363.   foreach blnick [chanlist $chan] {
  364.    bl:ban $blnick [getchanhost $blnick $chan] [nick2hand $blnick] $chan
  365.   }
  366.  }
  367. }
  368.  
  369. proc rem:blban {chan ban} {
  370.  global blackl
  371.  if {$blackl(rbabt)} {
  372.   pushmode $chan -b $ban
  373.   bl:do:rem $ban
  374.  } {
  375.   pushmode $chan -b $ban
  376.  }
  377. }
  378.  
  379. proc we:can:find:ban {blnick type} {
  380.  global blackl
  381.  set spfound 0
  382.  switch -- $type {
  383.   "add" {
  384.    foreach temp [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf] {
  385.     if {[string equal -nocase [lindex [split $temp] 0] $blnick]} { set spfound 1 ; break }
  386.    }
  387.   }
  388.   "rem" {
  389.    foreach temp [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf] {
  390.     if {[string equal -nocase [lindex [split $temp] 0] [string map {\\ \\\\ \[ \\\[ \] \\\]} $blnick]]} { set spfound 1 ; break }
  391.    }
  392.   }
  393.  }
  394.  set spfound
  395. }
  396.  
  397. proc blfollow {secs blvar} {
  398.  upvar $blvar fvar
  399.  utimer $secs [list bldicr $blvar]
  400.  incr fvar
  401. }
  402.  
  403. proc bldicr blvar {
  404.  upvar $blvar fvar
  405.  if {$fvar > 0} {
  406.   incr fvar -1
  407.  }
  408. }
  409.  
  410. set blbtypeDefaultType 3
  411.  
  412. proc blbtype [list name [list type $blbtypeDefaultType]] {
  413.  if {[scan $name {%[^!]!%[^@]@%s} nick user host]!=3} {
  414.   error "Usage: maskbhost <nick!user@host> \[type\]"
  415.  }
  416.  if [string match {[3489]} $type] {
  417.   if [string match {*[0-9]} $host] {
  418.    set host [join [lrange [split $host .] 0 2] .].*
  419.   } elseif {[string match *.*.* $host]} {
  420.    set host *.[join [lrange [split $host .] end-1 end] .]
  421.   }
  422.  }
  423.  if [string match {[1368]} $type] {
  424.   set user *[string trimleft $user ~]
  425.  } elseif {[string match {[2479]} $type]} {
  426.   set user *
  427.  }
  428.  if [string match {[01234]} $type] {
  429.   set nick *
  430.  }
  431.  set name $nick!$user@$host
  432. }
  433.  
  434. putlog "BlackList v1.4 By Opposing (a.k.a Sir_Fz) Loaded..."
Advertisement
Add Comment
Please, Sign In to add comment