Advertisement
d_iturrizaga

blacklist

Sep 28th, 2017
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.42 KB | None | 0 0
  1. #############################################################################
  2. # #
  3. # Coded by: Opposing (Fz_Egg@yahoo.com) #
  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 Fz_Egg@yahoo.com #
  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. # .. joins lamer!lamest@lamer.org
  80. # .. bot sets mode +b *!lamest@*
  81. # .. lamer kicked by bot "Blacklisted user."
  82. ## This happens if this option is set to 1.
  83. ## but if you set it to 0, then you can choose what bantype you want to ban.
  84. set blackl(bansame) 0
  85.  
  86. ## if blackl(bansame) is set to 0:
  87. ## What ban type do you want to ban ?
  88. # 0: *!user@full.host.tld
  89. # 1: *!*user@full.host.tld
  90. # 2: *!*@full.host.tld
  91. # 3: *!*user@*.host.tld
  92. # 4: *!*@*.host.tld
  93. # 5: nick!user@full.host.tld
  94. # 6: nick!*user@full.host.tld
  95. # 7: nick!*@full.host.tld
  96. # 8: nick!*user@*.host.tld
  97. # 9: nick!*@*.host.tld
  98. set blackl(btype) 2
  99.  
  100. ## Set default ban reason if not specified.
  101. ## NOTE: use %requester to use the nick of the one who set the ban.
  102. set blackl(kmsg) "Banned: Auto-Ban"
  103.  
  104. ## set default ban time (in minutes) if no bantime specified. (0 means no ban time)
  105. set blackl(btime) 0
  106.  
  107. ## Do you want the ban to be removed from the file after ban time expires ? (0: no / 1: yes)
  108. ## if set to 0, the bot will only remove the ban from the channel but not from the file.
  109. set blackl(rbabt) 0
  110.  
  111. ## Set here the trigger for public commands.
  112. ## example: set blackl(trig) "!"
  113. ## now using !listbl on main will show the blacklist.
  114. set blackl(trig) "!"
  115.  
  116. ## Set flags that are allowed to use these commands.
  117. ## <global flags>|<channel flags>
  118. set blackl(flags) A
  119.  
  120. # Configurations end here. #
  121. ############################
  122. #
  123. ######################################################################
  124. # Code starts here, please do not edit anything unless you know TCL: #
  125. # __________________________________________________________________ #
  126.  
  127. bind join - * bl:ban
  128. bind dcc $blackl(flags) addbl bl:add
  129. bind dcc $blackl(flags) rembl bl:rem
  130. bind dcc $blackl(flags) listbl bl:list
  131. bind pubm $blackl(flags) * bl:pub
  132. bind mode - "* +o" bl:cop
  133. setudef flag blacklist
  134.  
  135. if {[file exists $blackl(file)]} {
  136. set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  137. } {
  138. set BLNicks [list]
  139. }
  140.  
  141. foreach {blackl(lim) blackl(secs)} [split $blackl(punish) :] {break}
  142.  
  143. proc bl:ban {nick uhost hand chan} {
  144. global BLNicks blackl blflood
  145. if {![botisop $chan] || ![channel get $chan blacklist]} {return 0}
  146. if {![info exists blflood([set chan [string tolower $chan]])]} { set blflood($chan) 0 }
  147. foreach blnick $BLNicks {
  148. if {[string match -nocase [set ban [lindex [split $blnick] 0]] $nick!$uhost]} {
  149. set ban [string map {\\\\ \\ \\\[ \[ \\\] \]} $ban]
  150. if {[blfollow $blackl(secs) blflood($chan)] < $blackl(lim)} {
  151. putquick "KICK $chan $nick :[string map [list %requester [lindex [split $blnick] 1]] [join [lrange [split $blnick] 2 end-1]]]"
  152. if {$blackl(bansame)} {
  153. putquick "MODE $chan -o+b $nick $ban"
  154. if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  155. timer $btime [list rem:blban $chan $ban]
  156. }
  157. } {
  158. putquick "MODE $chan -o+b $nick [set aban [blbtype $nick!$uhost $blackl(btype)]]"
  159. if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  160. timer $btime [list rem:blban $chan $aban]
  161. }
  162. }
  163. } {
  164. puthelp "KICK $chan $nick :[string map [list %requester [lindex [split $blnick] 1]] [join [lrange [split $blnick] 2 end-1]]]"
  165. if {$blackl(bansame)} {
  166. pushmode $chan -o $nick
  167. pushmode $chan +b $ban
  168. if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  169. timer $btime [list rem:blban $chan $ban]
  170. }
  171. } {
  172. pushmode $chan -o $nick
  173. pushmode $chan +b [set aban [blbtype $nick!$uhost $blackl(btype)]]
  174. if {!([set btime [lindex [split $blnick] end]] <= 0)} {
  175. timer $btime [list rem:blban $chan $aban]
  176. }
  177. }
  178. }
  179. putlog "\[\002BlackList\002\]: Banned \002$nick\002!\002$uhost\002 matching [string map {! \002!\002 @ \002@\002} \002$ban\002] on \002$chan\002"
  180. puthelp "PRIVMSG #peruops : \[\002AutoBan\002\]: Baneado \002$nick\002!\002$uhost\002 Encontrado [string map {! \002!\002 @ \002@\002} \002$ban\002] on \002$chan\002. Si crees que este ban esta mal puesto dile a un admin que tipee !rembl [string map {! \002!\002 @ \002@\002} \002$ban\002]"
  181. break
  182. }
  183. }
  184. }
  185.  
  186. proc bl:add {hand idx arg} {
  187. if {$arg == ""} { putlog "SYNTAX: \003.addbl <nick!user@host> \[reason\] \[btime\]\003"; return 0 }
  188. if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 0]]]} {
  189. putlog "SYNTAX: \003.addbl \002<nick>\002!\002<user>\002@\002<host>\002 \[reason\] \[bantime\]\003"
  190. return 0
  191. }
  192. if {[bl:do:add $hand $arg]} {
  193. foreach chan [channels] {
  194. if {![channel get $chan blacklist]} { continue }
  195. foreach ubchecked [chanlist $chan] {
  196. bl:ban $ubchecked [getchanhost $ubchecked $chan] [nick2hand $ubchecked] $chan
  197. }
  198. }
  199. putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] has been \002added\002 to the blacklist."
  200. } {
  201. putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] already \002exists\002 in the blacklist."
  202. }
  203. }
  204.  
  205. proc bl:do:add {hand arg} {
  206. global blackl BLNicks
  207. set added 0
  208. if {[llength [lrange [split $arg] 1 end]] == 1} {
  209. if {[string is integer [lindex [split $arg] end]]} {
  210. set kreason "$blackl(kmsg)"
  211. set btime "[lindex [split $arg] end]"
  212. } else {
  213. set kreason "[lrange [split $arg] 1 end]"
  214. set btime "$blackl(btime)"
  215. }
  216. } elseif {[llength [lrange [split $arg] 1 end]] > 1} {
  217. if {[string is integer [lindex [split $arg] end]]} {
  218. set kreason "[join [lrange [split $arg] 1 end-1]]"
  219. set btime "[lindex [split $arg] end]"
  220. } else {
  221. set kreason "[join [lrange [split $arg] 1 end]]"
  222. set btime "$blackl(btime)"
  223. }
  224. } else {
  225. set kreason "$blackl(kmsg)"
  226. set btime "$blackl(btime)"
  227. }
  228. if {![file exists $blackl(file)]} {
  229. set temp [open $blackl(file) w]
  230. close $temp
  231. }
  232. set blnick "[string map {\\ \\\\ \[ \\\[ \] \\\]} [lindex [split $arg] 0]]"
  233. if {![we:can:find:ban $blnick add]} {
  234. puts [set fs [open $blackl(file) a]] "$blnick $hand $kreason $btime"
  235. close $fs
  236. set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  237. set added 1
  238. }
  239. set added
  240. }
  241.  
  242. proc bl:rem {hand idx arg} {
  243. if {$arg == ""} { putlog "SYNTAX: \003.rembl <nick!user@host>\003"; return 0 }
  244. if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 0]]]} {
  245. putlog "SYNTAX: \003.rembl \002<nick>\002!\002<user>\002@\002<host>\002\003"
  246. return 0
  247. }
  248. if {[bl:do:rem $arg]} {
  249. foreach chan [channels] {
  250. if {![channel get $chan blacklist]} { continue }
  251. foreach ban [chanbans $chan] {
  252. if {[string match -nocase $blnick [set sban [lindex $ban 0]]]} {
  253. pushmode $chan -b $sban
  254. }
  255. }
  256. }
  257. putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002deleted\002 from the blacklist."
  258. } {
  259. putlog "[string map {! \002!\002 @ \002@\002} \002$blnick\002] was \002not\002 found in the blacklist."
  260. }
  261. }
  262.  
  263. proc bl:do:rem arg {
  264. global blackl BLNicks
  265. set remmed 0
  266. set blnick [lindex [split $arg] 0]
  267. if {![file exists $blackl(file)]} {
  268. set temp [open $blackl(file) w]
  269. close $temp
  270. }
  271. if {[we:can:find:ban $blnick rem]} {
  272. set z ""
  273. set a [open $blackl(file) r]
  274. while {![eof $a]} {
  275. set b [gets $a]
  276. if {![string equal -nocase [lindex $b 0] $blnick]} { lappend z ${b} }
  277. }
  278. close $a
  279. set n [open $blackl(file) w]
  280. foreach k $z {
  281. if {$k != ""} { puts $n $k }
  282. }
  283. close $n
  284. set BLNicks [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf]
  285. set remmed 1
  286. }
  287. set remmed
  288. }
  289.  
  290. proc bl:list {hand idx arg} {
  291. global BLNicks
  292. if {[string equal "{} {}" $BLNicks] || [string equal "" $BLNicks]} {
  293. putlog "There are \002no\002 bans in the blacklist."
  294. } {
  295. set c 1
  296. foreach blnick $BLNicks {
  297. if {$blnick != ""} {
  298. putlog "\[\002$c\002\] - \002Mask\002: [lindex [split $blnick] 0] - \002Requester\002: [lindex [split $blnick] 1] - \002Bantime\002: [lindex [split $blnick] end]"
  299. incr c
  300. } {
  301. putlog "\[\002*\002\] - End of list."
  302. }
  303. }
  304. }
  305. }
  306.  
  307. proc bl:pub {nick uhost hand chan arg} {
  308. global blackl BLNicks
  309. if {![string equal $blackl(trig) [string index $arg 0]]} {return 0}
  310. switch -- [lindex [lindex [split $arg $blackl(trig)] 1] 0] {
  311. "addbl" {
  312. if {[join [lrange [split $arg] 1 end]] == ""} { puthelp "PRIVMSG $chan :SYNTAX: \003$blackl(trig)addbl <nick!user@host> \[reason\] \[btime\]\003"; return 0 }
  313. if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 1]]]} {
  314. puthelp "PRIVMSG $chan :SYNTAX: \003$blackl(trig)addbl \002<nick>\002!\002<user>\002@\002<host>\002 \[reason\] \[bantime\]\003"
  315. return 0
  316. }
  317. if {[bl:do:add $hand [join [lrange [split $arg] 1 end]]]} {
  318. if {[channel get $chan blacklist]} {
  319. foreach ubchecked [chanlist $chan] {
  320. bl:ban $ubchecked [getchanhost $ubchecked $chan] [nick2hand $ubchecked] $chan
  321. }
  322. }
  323. puthelp "PRIVMSG $chan :[string map {! \002!\002 @ \002@\002} \002$blnick\002] ha sido \002agregado\002 a la lista."
  324. } {
  325. puthelp "PRIVMSG $chan :[string map {! \002!\002 @ \002@\002} \002$blnick\002] ya \002existe\002 en la lista."
  326. }
  327. }
  328. "rembl" {
  329. if {[join [lrange [split $arg] 1 end]] == ""} { puthelp "PRIVMSG $chan :SYNTAX: \003$blackl(trig)rembl <nick!user@host>\003"; return 0 }
  330. if {![string match -nocase *!*@* [set blnick [lindex [split $arg] 1]]]} {
  331. puthelp "PRIVMSG $chan :SYNTAX: \003$blackl(trig)rembl \002<nick>\002!\002<user>\002@\002<host>\002\003"
  332. return 0
  333. }
  334. if {[bl:do:rem [join [lrange [split $arg] 1 end]]]} {
  335. if {[channel get $chan blacklist]} {
  336. foreach ban [chanbans $chan] {
  337. if {[string match -nocase $blnick [set sban [lindex $ban 0]]]} {
  338. pushmode $chan -b $sban
  339. }
  340. }
  341. }
  342. puthelp "PRIVMSG $chan :[string map {! \002!\002 @ \002@\002} \002$blnick\002] es \002borrado\002 de la lista."
  343. } {
  344. puthelp "PRIVMSG $chan :[string map {! \002!\002 @ \002@\002} \002$blnick\002] \002no\002 se encuentra en la lista."
  345. }
  346. }
  347. "listbl" {
  348. if {[string equal "{} {}" $BLNicks] || [string equal "" $BLNicks]} {
  349. puthelp "PRIVMSG $chan :There are \002no\002 bans in the blacklist."
  350. } {
  351. set c 1
  352. foreach blnick $BLNicks {
  353. if {$blnick != ""} {
  354. puthelp "PRIVMSG $chan :\[\002$c\002\] - \002Mask\002: [lindex [split $blnick] 0] - \002Requester\002: [lindex [split $blnick] 1] - \002Bantime\002: [lindex [split $blnick] end]"
  355. incr c
  356. } {
  357. puthelp "PRIVMSG $chan :\[\002*\002\] - End of list."
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364.  
  365. proc bl:cop {nick uhost hand chan mc targ} {
  366. global blackl
  367. if {[isbotnick $targ] && $blackl(checkop) && [channel get $chan blacklist]} {
  368. foreach blnick [chanlist $chan] {
  369. bl:ban $blnick [getchanhost $blnick $chan] [nick2hand $blnick] $chan
  370. }
  371. }
  372. }
  373.  
  374. proc rem:blban {chan ban} {
  375. global blackl
  376. if {$blackl(rbabt)} {
  377. pushmode $chan -b $ban
  378. bl:do:rem $ban
  379. } {
  380. pushmode $chan -b $ban
  381. }
  382. }
  383.  
  384. proc we:can:find:ban {blnick type} {
  385. global blackl
  386. set spfound 0
  387. switch -- $type {
  388. "add" {
  389. foreach temp [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf] {
  390. if {[string equal -nocase [lindex [split $temp] 0] $blnick]} { set spfound 1 ; break }
  391. }
  392. }
  393. "rem" {
  394. foreach temp [split [string tolower [read [set inf [open $blackl(file)]]]] "\n"][close $inf] {
  395. if {[string equal -nocase [lindex [split $temp] 0] [string map {\\ \\\\ \[ \\\[ \] \\\]} $blnick]]} { set spfound 1 ; break }
  396. }
  397. }
  398. }
  399. set spfound
  400. }
  401.  
  402. proc blfollow {secs blvar} {
  403. upvar $blvar fvar
  404. utimer $secs [list bldicr $blvar]
  405. incr fvar
  406. }
  407.  
  408. proc bldicr blvar {
  409. upvar $blvar fvar
  410. if {$fvar > 0} {
  411. incr fvar -1
  412. }
  413. }
  414.  
  415. set blbtypeDefaultType 3
  416.  
  417. proc blbtype [list name [list type $blbtypeDefaultType]] {
  418. if {[scan $name {%[^!]!%[^@]@%s} nick user host]!=3} {
  419. error "Usage: maskbhost <nick!user@host> \[type\]"
  420. }
  421. if [string match {[3489]} $type] {
  422. if [string match {*[0-9]} $host] {
  423. set host [join [lrange [split $host .] 0 2] .].*
  424. } elseif {[string match *.*.* $host]} {
  425. set host *.[join [lrange [split $host .] end-1 end] .]
  426. }
  427. }
  428. if [string match {[1368]} $type] {
  429. set user *[string trimleft $user ~]
  430. } elseif {[string match {[2479]} $type]} {
  431. set user *
  432. }
  433. if [string match {[01234]} $type] {
  434. set nick *
  435. }
  436. set name $nick!$user@$host
  437. }
  438.  
  439. putlog "BlackList v1.4 By Opposing (a.k.a Sir_Fz) Loaded..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement