BT.BanCmds.tcl 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################ BANCMDS TCL ############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. ################################ Commands ###################################
  16. ################################ ub ###################################
  17. proc ub:link {mask} {
  18. global black
  19. set chanban 0
  20. set chanlink 0
  21. foreach chan [link:get] {
  22. set chanlink [expr $chanlink + 1]
  23. foreach b [blacktools:banlist $chan] {
  24. set bhost [lindex [split $b] 3]
  25. set real_bhost [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $bhost]
  26. if {[string match -nocase $mask $real_bhost] || [string match -nocase $real_bhost $mask]} {
  27. set chanban [expr $chanban + 1]
  28. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  29. putserv "PRIVMSG $black(chanserv) :unban $chan $bhost"
  30. } else {
  31. pushmode $chan -b $bhost
  32. }
  33. blacktools:delban $real_bhost $chan "0" "0"
  34. }
  35. }
  36. }
  37. return "$chanlink $chanban"
  38. }
  39. proc ub:process {user mask nick hand host chan chan1 type gl cmd whois link} {
  40. global black
  41. set nounban 0
  42. set split_cmd [split $cmd ":"]
  43. set id [lindex $split_cmd 1]
  44. set cmd [lindex $split_cmd 0]
  45. set cmd_status [btcmd:status $chan $hand "$cmd" 0]
  46. if {$cmd_status == "1"} {
  47. return
  48. }
  49. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  50. return
  51. }
  52. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  53. return
  54. }
  55. if {$user == ""} {
  56. switch $type {
  57. 0 {
  58. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $cmd
  59. }
  60. 1 {
  61. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $cmd
  62. }
  63. 2 {
  64. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $cmd
  65. }
  66. }
  67. return
  68. }
  69. if {![validchan $chan] && $link != "1" && $gl != "1"} {
  70. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  71. return
  72. }
  73. if {$link != "1" && $gl != "1"} {
  74. if {![botisop $chan] && ![setting:get $chan xonly]} {
  75. blacktools:tell $nick $host $hand $chan $chan1 gl.noop none
  76. return
  77. }
  78. }
  79. set show_mask $mask
  80. set total_b 0
  81. set rem_b 0
  82. if {![regexp {\*} $mask] && $whois != "1" && $id != "id"} {
  83. putserv "USERHOST :$user"
  84. bind RAW - 302 ub:get:host
  85. set ::uuser $user
  86. set ::unick $nick
  87. set ::uhand $hand
  88. set ::uhost $host
  89. set ::uchan $chan
  90. set ::uchan1 $chan1
  91. set ::utype $type
  92. set ::ugl $gl
  93. set ::ucmd $cmd
  94. set ::ulink $link
  95. return
  96. }
  97. if {$link == "1"} {
  98. set return [ub:link $mask]
  99. set chanlink [lindex $return 0]
  100. set chanban [lindex $return 1]
  101. blacktools:tell $nick $host $hand $chan $chan1 ub.7 "$chanban $chanlink"
  102. return
  103. }
  104. if {$gl != "1"} {
  105. if {[onchan $user $chan]} {
  106. set mask "$user![getchanhost $user $chan]"
  107. set ident "[string tolower [lindex [split $mask "@"] 0]]"
  108. if {[string match -nocase "*.mibbit.com*" $mask]} {
  109. set return_ip [return:mibbit:mask $ident]
  110. if {$return_ip != "0"} {
  111. set mask "$user!$ident@$return_ip"
  112. }
  113. }
  114. }
  115. }
  116. if {$gl != "1"} {
  117. if {(($mask == "*") || ($mask == "*!*@*")) && [matchattr $hand -|OA $chan]} {
  118. blacktools:tell $nick $host $hand $chan $chan1 ub.5 none
  119. return
  120. }
  121. foreach b [blacktools:banlist $chan] {
  122. set bhost [lindex [split $b] 3]
  123. set real_bhost [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $bhost]
  124. set btime [lindex [split $b] 5]
  125. set num [lindex [split $b] 1]
  126. if {[string match -nocase $mask $real_bhost] || [string match -nocase $real_bhost $mask] || [string match -nocase $mask $num]} {
  127. set bywho [lindex [split $b] 4]
  128. set read_tr [lindex [split $b] 7]
  129. set total_b [expr $total_b + 1]
  130. set split_bywho [split $bywho ":"]
  131. set level [lindex $split_bywho 1]
  132. set check [blacktools:check:levelub $hand $chan $level]
  133. if {$check == "-1"} {
  134. blacktools:tell $nick $host $hand $chan $chan1 gl.nounban $bhost
  135. set nounban 1
  136. continue
  137. }
  138. if {$btime == "0" && [matchattr $hand -|O $chan]} {
  139. continue
  140. }
  141. if {([blacktools:sticky $mask $chan] == "1") && [matchattr $hand -|OA $chan]} {
  142. continue
  143. }
  144. set rem_b [expr $rem_b + 1]
  145. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  146. putserv "PRIVMSG $black(chanserv) :unban $chan $bhost"
  147. } else {
  148. pushmode $chan -b $bhost
  149. }
  150. blacktools:delban $real_bhost $chan "0" "0"
  151. if {$read_tr == "2"} {
  152. troll:del $real_bhost $chan
  153. }
  154. continue
  155. }
  156. }
  157. foreach b [banlist $chan] {
  158. set bhost [lindex $b 0]
  159. set btime [lindex $b 2]
  160. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  161. set total_b [expr $total_b + 1]
  162. if {$btime == "0" && [matchattr $hand -|O $chan]} {
  163. continue
  164. }
  165. if {[isbansticky $bhost] && [matchattr $hand -|OA $chan]} {
  166. continue
  167. }
  168. set rem_b [expr $rem_b + 1]
  169. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  170. putserv "PRIVMSG $black(chanserv) :unban $chan $bhost"
  171. } else {
  172. putserv "MODE $chan -b $bhost"
  173. }
  174. killchanban $chan $bhost
  175. }
  176. }
  177. if {$total_b == "0"} {
  178. if {[ischanban $mask $chan]} {
  179. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  180. putserv "PRIVMSG $black(chanserv) :unban $chan $mask"
  181. } else {
  182. putserv "MODE $chan -b $mask"
  183. }
  184. blacktools:tell $nick $host $hand $chan $chan1 ub.6 none
  185. return
  186. }
  187. if {$id == "id"} {
  188. blacktools:tell $nick $host $hand $chan $chan1 ub.8 $show_mask
  189. } else {
  190. blacktools:tell $nick $host $hand $chan $chan1 ub.1 $show_mask
  191. }
  192. } else {
  193. if {$id == "id"} {
  194. blacktools:tell $nick $host $hand $chan $chan1 ub.9 "$rem_b $total_b $show_mask"
  195. } else {
  196. if {$nounban == "0"} {
  197. blacktools:tell $nick $host $hand $chan $chan1 ub.2 "$rem_b $total_b $show_mask"
  198. }
  199. }
  200. }
  201. } else {
  202. foreach b [blacktools:banlist:gl] {
  203. set bhost [lindex [split $b] 3]
  204. set num [lindex [split $b] 1]
  205. set real_bhost [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $bhost]
  206. set btime [lindex [split $b] 4]
  207. if {[string match -nocase $mask $real_bhost] || [string match -nocase $real_bhost $mask] || [string match -nocase $mask $num]} {
  208. set total_b [expr $total_b + 1]
  209. set rem_b [expr $rem_b + 1]
  210. blacktools:delban $real_bhost $chan "1" "0"
  211. if {$gl == "1"} {
  212. blacktools:ub:global $real_bhost [channels] 0
  213. }
  214. continue
  215. }
  216. }
  217. foreach b [banlist] {
  218. set bhost [lindex $b 0]
  219. set btime [lindex $b 2]
  220. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  221. set total_b [expr $total_b + 1]
  222. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  223. putserv "PRIVMSG $black(chanserv) :unban $chan $bhost"
  224. } else {
  225. putserv "MODE $chan -b $bhost"
  226. }
  227. killban $bhost
  228. }
  229. }
  230. if {$total_b == "0"} {
  231. if {$id == "id"} {
  232. blacktools:tell $nick $host $hand $chan $chan1 ub.11 $show_mask
  233. } else {
  234. blacktools:tell $nick $host $hand $chan $chan1 ub.3 $show_mask
  235. }
  236. } else {
  237. if {$id == "id"} {
  238. blacktools:tell $nick $host $hand $chan $chan1 ub.10 "$total_b $show_mask"
  239. } else {
  240. blacktools:tell $nick $host $hand $chan $chan1 ub.4 "$total_b $show_mask"
  241. }
  242. }
  243. }
  244. }
  245. proc blacktools:ub:global {bhost channels num} {
  246. global black
  247. set chan [lindex $channels $num]
  248. set incnum [expr $num + 1]
  249. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  250. putserv "PRIVMSG $black(chanserv) :unban $chan $bhost"
  251. } else {
  252. putserv "MODE $chan -b $bhost"
  253. }
  254. if {[lindex $channels $incnum] != ""} {
  255. blacktools:ub:global $bhost $channels $incnum
  256. }
  257. }
  258. ################################ sb ###################################
  259. proc sb:process {bhost what nick hand host chan chan1 type cmd entry} {
  260. global botnick black tcldir
  261. set cmd_status [btcmd:status $chan $hand "sb" 0]
  262. if {$cmd_status == "1"} {
  263. return
  264. }
  265. set gl_bans 0
  266. set local_bans 0
  267. set total_bans 0
  268. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  269. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  270. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  271. return
  272. }
  273. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  274. return
  275. }
  276. if {$bhost == ""} {
  277. switch $type {
  278. 0 {
  279. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $cmd
  280. }
  281. 1 {
  282. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $cmd
  283. }
  284. 2 {
  285. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $cmd
  286. }
  287. }
  288. return 0
  289. }
  290. if {$bhost == "-"} {
  291. blacktools:tell $nick $host $hand $chan $chan1 gl.hostnotexist "none"
  292. return
  293. }
  294. if {($bhost != "") && ($entry == "")} {
  295. putserv "USERHOST :$bhost"
  296. bind RAW - 302 sb:get:host
  297. set ::suser $bhost
  298. set ::snick $nick
  299. set ::shand $hand
  300. set ::shost $host
  301. set ::schan $chan
  302. set ::schan1 $chan1
  303. set ::stype $type
  304. set ::scmd $cmd
  305. return
  306. }
  307. if {[matchattr $hand mn]} {
  308. sb:search $nick $host $hand $chan $chan1 $bhost "1" $entry
  309. return
  310. }
  311. sb:search $nick $host $hand $chan $chan1 $bhost "0" $entry
  312. }
  313. proc sb:search {nick host hand chan chan1 bhost gl entry} {
  314. global black
  315. set show_bhost $bhost
  316. set gl_bans 0
  317. set local_bans 0
  318. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  319. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  320. foreach b [blacktools:banlist $chan] {
  321. set mask [lindex [split $b] 3]
  322. set id [lindex [split $b] 1]
  323. set real_mask [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $mask]
  324. if {[string match -nocase $real_mask $bhost] || [string match -nocase $bhost $real_mask] || $bhost == $id} {
  325. set local_bans [expr $local_bans + 1]
  326. }
  327. }
  328. if {$gl == "1"} {
  329. foreach b [blacktools:banlist:gl] {
  330. set mask [lindex [split $b] 3]
  331. set id [lindex [split $b] 1]
  332. set real_mask [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $mask]
  333. if {[string match -nocase $real_mask $bhost] || [string match -nocase $bhost $real_mask] || $bhost == $id} {
  334. set gl_bans [expr $gl_bans + 1]
  335. }
  336. }
  337. }
  338. if {$gl_bans > "0"} {
  339. foreach b [blacktools:banlist:gl] {
  340. set mask [lindex [split $b] 3]
  341. set id [lindex [split $b] 1]
  342. set real_mask [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $mask]
  343. if {[string match -nocase $real_mask $bhost] || [string match -nocase $bhost $real_mask] || $bhost == $id} {
  344. set mask [lindex [split $b] 3]
  345. set id [lindex [split $b] 1]
  346. set expire [lindex [split $b] 5]
  347. set created [lindex [split $b] 6]
  348. set created [clock format $created -format %D-%H:%M:%S]
  349. set breason [lrange [split $b] 9 end]
  350. set breason [join [encoding convertfrom utf-8 $breason]]
  351. set bywho [lindex [split $b] 4]
  352. if {$expire != "0"} {
  353. set expire [return_time_2 $getlang [expr $expire - [unixtime]]]
  354. blacktools:tell $nick $host $hand $chan $chan1 sb.3 "$id $mask $bywho $created $expire $breason"
  355. } else {
  356. set expire $black(say.$getlang.banlist.13)
  357. blacktools:tell $nick $host $hand $chan $chan1 sb.10 "$id $mask $bywho $created $expire $breason"
  358. }
  359. }
  360. }
  361. }
  362. if {$local_bans > "0"} {
  363. foreach b [blacktools:banlist $chan] {
  364. set mask [lindex [split $b] 3]
  365. set id [lindex [split $b] 1]
  366. set real_mask [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $mask]
  367. if {[string match -nocase $real_mask $bhost] || [string match -nocase $bhost $real_mask] || $bhost == $id} {
  368. set mask [lindex [split $b] 3]
  369. set id [lindex [split $b] 1]
  370. set expire [lindex [split $b] 5]
  371. set created [lindex [split $b] 6]
  372. set sticky [lindex [split $b] 7]
  373. set created [clock format $created -format %D-%H:%M:%S]
  374. set breason [lrange [split $b] 9 end]
  375. set breason [join [encoding convertfrom utf-8 $breason]]
  376. set bywho [lindex [split $b] 4]
  377. set split_bywho [split $bywho ":"]
  378. set handle [lindex $split_bywho 0]
  379. set type [lindex $split_bywho 1]
  380. if {$type != "" && $type != "bot"} {
  381. set bywho "$handle\([encoding convertfrom utf-8 $type]\)"
  382. } elseif {$sticky == "1"} {
  383. set bywho "$handle\(STICKY\)"
  384. } else {
  385. set bywho $handle
  386. }
  387. if {$expire != "0"} {
  388. set expire [return_time_2 $getlang [expr $expire - [unixtime]]]
  389. blacktools:tell $nick $host $hand $chan $chan1 sb.4 "$id $mask $bywho $created $expire $breason"
  390. } else {
  391. set expire $black(say.$getlang.banlist.13)
  392. blacktools:tell $nick $host $hand $chan $chan1 sb.9 "$id $mask $bywho $created $expire $breason"
  393. }
  394. }
  395. }
  396. }
  397. if {[expr $local_bans + $gl_bans] > 0} {
  398. return
  399. } else {
  400. set gl_bans 0
  401. set local_bans 0
  402. }
  403. foreach b [banlist $chan] {
  404. set mask [lindex $b 0]
  405. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  406. set local_bans [expr $local_bans + 1]
  407. }
  408. }
  409. if {$gl == "1"} {
  410. foreach b [banlist] {
  411. set mask [lindex $b 0]
  412. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  413. set gl_bans [expr $gl_bans + 1]
  414. }
  415. }
  416. if {[expr $local_bans + $gl_bans] == "0"} {
  417. if {$entry == "2"} {
  418. blacktools:tell $nick $host $hand $chan $chan1 sb.11 $show_bhost
  419. } else {
  420. blacktools:tell $nick $host $hand $chan $chan1 sb.2 $show_bhost
  421. }
  422. return
  423. }
  424. if {[expr $local_bans + $gl_bans] > 10} {
  425. blacktools:tell $nick $host $hand $chan $chan1 sb.5 "none"
  426. return
  427. }
  428. } else {
  429. if {$local_bans == "0"} {
  430. if {$entry == "2"} {
  431. blacktools:tell $nick $host $hand $chan $chan1 sb.11 $show_bhost
  432. } else {
  433. blacktools:tell $nick $host $hand $chan $chan1 sb.2 $show_bhost
  434. }
  435. return
  436. }
  437. if {$local_bans > 10} {
  438. blacktools:tell $nick $host $hand $chan $chan1 sb.5 "none"
  439. return
  440. }
  441. }
  442. if {$gl_bans > "0"} {
  443. foreach b [banlist] {
  444. set mask [lindex $b 0]
  445. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  446. set mask [lindex $b 0]
  447. set expire [lindex $b 2]
  448. set created [lindex $b 3]
  449. set breason [split [lindex $b 1]]
  450. set bywho [split [lindex $b 5]]
  451. set created [clock format $created -format %D-%H:%M:%S]
  452. if {$expire != "0"} {
  453. set expire [return_time_2 $getlang [expr $expire - [unixtime]]]
  454. blacktools:tell $nick $host $hand $chan $chan1 sb.3 "- $mask $bywho $created $expire $breason"
  455. } else {
  456. set expire "NEVER"
  457. blacktools:tell $nick $host $hand $chan $chan1 sb.10 "- $mask $bywho $created $expire $breason"
  458. }
  459. }
  460. }
  461. }
  462. if {$local_bans > "0"} {
  463. foreach b [banlist $chan] {
  464. set mask [lindex $b 0]
  465. if {[string match -nocase $mask $bhost] || [string match -nocase $bhost $mask]} {
  466. set mask [lindex $b 0]
  467. set expire [lindex $b 2]
  468. set created [lindex $b 3]
  469. set breason [split [lindex $b 1]]
  470. set bywho [split [lindex $b 5]]
  471. set created [clock format $created -format %D-%H:%M:%S]
  472. if {$expire != "0"} {
  473. set expire [return_time_2 $getlang [expr $expire - [unixtime]]]
  474. blacktools:tell $nick $host $hand $chan $chan1 sb.4 "- $mask $bywho $created $expire $breason"
  475. } else {
  476. set expire "NEVER"
  477. blacktools:tell $nick $host $hand $chan $chan1 sb.9 "- $mask $bywho $created $expire $breason"
  478. }
  479. }
  480. }
  481. }
  482. }
  483. ################################### banlist ###################################
  484. proc banlist:process {nick host hand chan chan1 user type cmd next} {
  485. global botnick black
  486. set cmd_status [btcmd:status $chan $hand "banlist" 0]
  487. if {$cmd_status == "1"} {
  488. return
  489. }
  490. set i 0
  491. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  492. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  493. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  494. return
  495. }
  496. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  497. return
  498. }
  499. if {$user == ""} {
  500. switch $type {
  501. 0 {
  502. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $cmd
  503. }
  504. 1 {
  505. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $cmd
  506. }
  507. 2 {
  508. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $cmd
  509. }
  510. }
  511. return 0
  512. }
  513. if {[matchattr $hand nm] && [string equal -nocase "global" $user]} {
  514. set gl "1"
  515. banlist:getbans $nick $host $hand $chan $chan1 $user "" $type $next $gl [blacktools:banlist:gl] ""
  516. return
  517. }
  518. if {[string match -nocase "all" $user]} {
  519. set gl ""
  520. set user ""
  521. banlist:getbans $nick $host $hand $chan $chan1 $user "" $type $next $gl [blacktools:banlist $chan] ""
  522. return
  523. }
  524. if {[string match -nocase "other" $user]} {
  525. set gl ""
  526. set user ""
  527. banlist:getbans $nick $host $hand $chan $chan1 $user "" $type $next $gl [banlist $chan] "2"
  528. return
  529. }
  530. if {[onchan $user $chan] && ![validuser $user]} {
  531. set handle $user
  532. set user [nick2hand $user]
  533. } else {
  534. set handle ""
  535. }
  536. if {![validuser $user] && (![string equal -nocase "all" $user])} {
  537. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  538. return
  539. }
  540. if {![matchattr $user nmo|OASMN $chan] && (![string equal -nocase "all" $user])} { blacktools:tell $nick $host $hand $chan $chan1 gl.noaccess none
  541. return
  542. }
  543. set gl ""
  544. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  545. set file_temp "temp.$timestamp"
  546. if {![file exists $file_temp]} {
  547. set file [open $file_temp w]
  548. close $file
  549. }
  550. set file [open $file_temp a]
  551. foreach b [blacktools:banlist $chan] {
  552. set bywho [lindex [split $b] 4]
  553. set split_bywho [split $bywho ":"]
  554. set handz [join [lindex [split $split_bywho] 0]]
  555. set type [lindex [split $split_bywho] 1]
  556. if {[string equal -nocase $handz $user]} {
  557. set id [lindex [split $b] 1]
  558. set mask [lindex [split $b] 3]
  559. set expire [lindex [split $b] 5]
  560. set created [lindex [split $b] 6]
  561. set sticky [lindex [split $b] 7]
  562. set breason [lrange [split $b] 9 end]
  563. if {$type != ""} {
  564. puts $file "$id $mask $expire $created $bywho $sticky [join $breason]"
  565. } else {
  566. puts $file "$id $mask $expire $created $bywho $sticky [join $breason]"
  567. }
  568. }
  569. }
  570. close $file
  571. set file [open $file_temp r]
  572. set w [read -nonewline $file]
  573. close $file
  574. set data [split $w "\n"]
  575. banlist:getbans $nick $host $hand $chan $chan1 $user $handle $type $next $gl $data "1"
  576. file delete $file_temp
  577. }
  578. proc banlist:remain {nick host hand count chan chan1 type gl user userb prv} {
  579. global black lastbind botnick
  580. if {$count == "0"} { return }
  581. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  582. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  583. set split_lastbind [split $lastbind ""]
  584. set charbind [lindex $split_lastbind 0]
  585. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  586. set charbind ""
  587. }
  588. set firstchar [lindex $black(cmdchar) 0]
  589. if {[string equal $lastbind "*"]} { set charbind "prv" }
  590. if {[string equal -nocase "**" $lastbind]} { set charbind "$botnick " }
  591. if {[string equal -nocase "***" $lastbind]} { set charbind "$host" }
  592. if {$charbind == ""} {
  593. set charbind $firstchar
  594. if {[validuser $hand]} {
  595. set getchar [getuser $hand XTRA MYCHAR]
  596. if {$getchar != ""} {
  597. set charbind $getchar
  598. }
  599. }
  600. }
  601. if {$charbind == "prv"} { set charbind "" }
  602. set replace(%char%) $charbind
  603. set replace(%counter%) $count
  604. set replace(%user%) $user
  605. set replace(%chan%) $chan
  606. if {$gl == "1"} {
  607. set msg [black:color:set $hand $black(say.$getlang.banlist.3)]
  608. }
  609. if {$userb == "1"} {
  610. set msg [black:color:set $hand $black(say.$getlang.banlist.8)]
  611. }
  612. if {$user == ""} {
  613. set msg [black:color:set $hand $black(say.$getlang.banlist.14)]
  614. }
  615. if {$userb == "2"} {
  616. set msg [black:color:set $hand $black(say.$getlang.banlist.15)]
  617. }
  618. if {$prv == "prv"} {
  619. set msg [black:color:set $hand $black(say.$getlang.banlist.14)]
  620. if {$userb == "2"} {
  621. set msg [black:color:set $hand $black(say.$getlang.banlist.15)]
  622. }
  623. if {$gl == "1"} {
  624. set msg [black:color:set $hand $black(say.$getlang.banlist.3)]
  625. }
  626. puthelp "PRIVMSG $nick :[string map [array get replace] $msg]"
  627. return
  628. }
  629. switch $type {
  630. 0 {
  631. puthelp "NOTICE $nick :[string map [array get replace] $msg]"
  632. }
  633. 1 {
  634. puthelp "PRIVMSG $chan1 :[string map [array get replace] $msg]"
  635. }
  636. 2 {
  637. puthelp "PRIVMSG $nick :[string map [array get replace] $msg]"
  638. }
  639. }
  640. }
  641. proc banlist:getbans {nick host hand chan chan1 user handle type next gl banlist userb} {
  642. global black
  643. set show_user $user
  644. set show_handle $handle
  645. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  646. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  647. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  648. if {$getmethod == ""} { set getmethod "0" }
  649. if {[string equal -nocase $next "-next"]} {
  650. if {[info exists black(morebans:$chan:$hand)]} {
  651. if {$black(morebans:$chan:$hand) >= $black(modul:nr:entries)} {
  652. for {set i $black(showbans:$chan:$hand)} { $i < [expr $black(showbans:$chan:$hand) + $black(modul:nr:entries)] } { incr i } {
  653. set current_ban [lindex $banlist $i]
  654. show:bans $nick $host $hand $chan $chan1 $gl $current_ban $userb
  655. }
  656. set black(morebans:$chan:$hand) [expr $black(morebans:$chan:$hand) - $black(modul:nr:entries)]
  657. banlist:remain $nick $host $hand $black(morebans:$chan:$hand) $chan $chan1 $getmethod $gl $user $userb $host
  658. set black(showbans:$chan:$hand) [expr $black(showbans:$chan:$hand) + $black(modul:nr:entries)]
  659. } else {
  660. if {$black(morebans:$chan:$hand) < 1} {
  661. return
  662. }
  663. for {set i $black(showbans:$chan:$hand)} { $i <= [expr $black(showbans:$chan:$hand) + $black(morebans:$chan:$hand)]} { incr i } {
  664. set current_ban [lindex $banlist $i]
  665. show:bans $nick $host $hand $chan $chan1 $gl $current_ban $userb
  666. }
  667. set black(morebans:$chan:$hand) [expr $black(morebans:$chan:$hand) - $black(showbans:$chan:$hand)]
  668. }
  669. foreach tmr [utimers] {
  670. if {[string match -nocase "*banlist:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  671. killutimer [lindex $tmr 2]
  672. }
  673. }
  674. utimer 30 [list banlist:unset:more $chan $hand]
  675. if {$black(morebans:$chan:$hand) < 1} {
  676. blacktools:tell $nick $host $hand $chan $chan1 banlist.4 none
  677. }
  678. }
  679. return
  680. }
  681. set black(cbanlist:$chan:$hand) [llength $banlist]
  682. set black(showbans:$chan:$hand) 0
  683. if {$black(cbanlist:$chan:$hand) > $black(modul:nr:entries)} {
  684. if {$gl == "1"} {
  685. blacktools:tell $nick $host $hand $chan $chan1 banlist.2 "$black(cbanlist:$chan:$hand)"
  686. }
  687. if {$user == ""} {
  688. blacktools:tell $nick $host $hand $chan $chan1 banlist.6 "$black(cbanlist:$chan:$hand)"
  689. }
  690. if {$userb == "1" && $handle != ""} {
  691. blacktools:tell $nick $host $hand $chan $chan1 banlist.7 "$black(cbanlist:$chan:$hand) $show_user\($show_handle\)"
  692. }
  693. if {$userb == "1" && $handle == ""} {
  694. blacktools:tell $nick $host $hand $chan $chan1 banlist.7 "$black(cbanlist:$chan:$hand) $show_user"
  695. }
  696. set black(morebans:$chan:$hand) [expr $black(cbanlist:$chan:$hand) - $black(modul:nr:entries)]
  697. for {set i 0} { $i < $black(modul:nr:entries) } { incr i } {
  698. set current_ban [lindex $banlist $i]
  699. show:bans $nick $host $hand $chan $chan1 $gl $current_ban $userb
  700. }
  701. set black(showbans:$chan:$hand) [expr $black(showbans:$chan:$hand) + $black(modul:nr:entries)]
  702. if {$black(morebans:$chan:$hand) > 0} {
  703. banlist:remain $nick $host $hand $black(morebans:$chan:$hand) $chan $chan1 $getmethod $gl $user $userb $host
  704. }
  705. foreach tmr [utimers] {
  706. if {[string match -nocase "*banlist:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  707. killutimer [lindex $tmr 2]
  708. }
  709. }
  710. utimer 60 [list banlist:unset:more $chan $hand]
  711. } else {
  712. if {$gl == "1"} {
  713. blacktools:tell $nick $host $hand $chan $chan1 banlist.2 "$black(cbanlist:$chan:$hand)"
  714. }
  715. if {$user == ""} {
  716. blacktools:tell $nick $host $hand $chan $chan1 banlist.6 "$black(cbanlist:$chan:$hand)"
  717. }
  718. if {$userb == "1" && $handle != ""} {
  719. blacktools:tell $nick $host $hand $chan $chan1 banlist.7 "$black(cbanlist:$chan:$hand) $show_user\($show_handle\)"
  720. }
  721. if {$userb == "1" && $handle == ""} {
  722. blacktools:tell $nick $host $hand $chan $chan1 banlist.7 "$black(cbanlist:$chan:$hand) $show_user"
  723. }
  724. for {set i 0} { $i < $black(modul:nr:entries) } { incr i } {
  725. set current_ban [lindex $banlist $i]
  726. show:bans $nick $host $hand $chan $chan1 $gl $current_ban $userb
  727. }
  728. blacktools:tell $nick $host $hand $chan $chan1 banlist.4 none
  729. }
  730. }
  731. proc banlist:unset:more {chan hand} {
  732. global black
  733. if {[info exists black(morebans:$chan:$hand)]} {
  734. unset black(morebans:$chan:$hand)
  735. }
  736. if {[info exists black(cbanlist:$chan:$hand)]} {
  737. unset black(cbanlist:$chan:$hand)
  738. }
  739. if {[info exists black(showbans:$chan:$hand)]} {
  740. unset black(showbans:$chan:$hand)
  741. }
  742. }
  743. proc show:bans {nick host hand chan chan1 gl b userb} {
  744. global black
  745. if {$b == ""} { return }
  746. set never_expire 0
  747. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  748. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  749. if {$userb == "1"} {
  750. set id [lindex [split $b] 0]
  751. set mask [lindex [split $b] 1]
  752. set expire [lindex [split $b] 2]
  753. set created [lindex [split $b] 3]
  754. set bywho [lindex [split $b] 4]
  755. set sticky [lindex [split $b] 5]
  756. set breason [lrange [split $b] 6 end]
  757. set breason [join [encoding convertfrom utf-8 $breason]]
  758. } elseif {$userb == "2"} {
  759. set id "-"
  760. set mask [lindex $b 0]
  761. set expire [lindex $b 2]
  762. set created [lindex $b 3]
  763. set breason [split [lindex $b 1]]
  764. set breason [join [encoding convertfrom utf-8 $breason]]
  765. set bywho [split [lindex $b 5]]
  766. if {[isbansticky [lindex $b 0] $chan]} {
  767. set sticky 1
  768. } else {
  769. set sticky 0
  770. }
  771. } else {
  772. set id [lindex [split $b] 1]
  773. set mask [lindex [split $b] 3]
  774. set expire [lindex [split $b] 5]
  775. set bywho [lindex [split $b] 4]
  776. set created [lindex [split $b] 6]
  777. set sticky [lindex [split $b] 7]
  778. set breason [lrange [split $b] 9 end]
  779. set breason [join [encoding convertfrom utf-8 $breason]]
  780. }
  781. set split_bywho [split $bywho ":"]
  782. set handle [lindex $split_bywho 0]
  783. set type [lindex $split_bywho 1]
  784. if {$type != ""} {
  785. set type "BAN([join [encoding convertfrom utf-8 $type]])"
  786. set bywho "$handle"
  787. } elseif {$sticky == "1"} {
  788. set type "BAN(STICK)"
  789. set bywho "$handle"
  790. } else {
  791. set bywho $handle
  792. set type "BAN"
  793. }
  794. if {$expire != "0"} {
  795. set expire [return_time_2 $getlang [expr $expire - [unixtime]]]
  796. } else {
  797. set expire $black(say.$getlang.banlist.13)
  798. set never_expire 1
  799. }
  800. set created [clock format $created -format %D-%H:%M:%S]
  801. if {$never_expire == "0"} {
  802. if {$userb == "1"} {
  803. blacktools:tell $nick $host $hand $chan $chan1 banlist.9 "$id $type $mask $created $expire $breason"
  804. return
  805. }
  806. blacktools:tell $nick $host $hand $chan $chan1 banlist.5 "$id $type $mask $bywho $created $expire $breason"
  807. } else {
  808. if {$userb == "1"} {
  809. blacktools:tell $nick $host $hand $chan $chan1 banlist.12 "$id $type $mask $created $expire $breason"
  810. return
  811. }
  812. blacktools:tell $nick $host $hand $chan $chan1 banlist.11 "$id $type $mask $bywho $created $expire $breason"
  813. }
  814. }
  815. ################################ w ####################################
  816. proc w:process {wnick nick hand host chan chan1 type} {
  817. global botnick black
  818. set cmd_status [btcmd:status $chan $hand "w" 0]
  819. if {$cmd_status == "1"} {
  820. return
  821. }
  822. set handle [nick2hand $wnick]
  823. set show_wnick $wnick
  824. set getlang [string tolower [setting:get $chan lang]]
  825. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  826. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  827. return
  828. }
  829. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  830. return
  831. }
  832. if {$wnick == ""} {
  833. switch $type {
  834. 0 {
  835. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "w"
  836. }
  837. 1 {
  838. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "w"
  839. }
  840. 2 {
  841. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "w"
  842. }
  843. }
  844. return 0
  845. }
  846. if {![validchan $chan]} {
  847. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  848. return
  849. }
  850. if {![botisop $chan] && ![setting:get $chan xonly]} {
  851. blacktools:tell $nick $host $hand $chan $chan1 gl.noop none
  852. return
  853. }
  854. if {![onchan $wnick $chan]} {
  855. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $show_wnick
  856. return
  857. }
  858. if {![onchan $botnick $chan]} {
  859. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  860. return
  861. }
  862. if {[isbotnick $wnick]} {
  863. return
  864. }
  865. if {[matchattr $handle $black(exceptflags) $chan]} {
  866. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  867. return
  868. }
  869. set getreason [setting:get $chan w-reason]
  870. if {$getreason == ""} {
  871. set getlang [string tolower [setting:get $chan lang]]
  872. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  873. set getreason $black(say.$getlang.w.5)
  874. set len [llength $getreason]
  875. set random [expr int(rand()*$len)]
  876. set getreason [lindex $getreason $random]
  877. }
  878. if {[setting:get $chan showhandle]} {
  879. set reason "($hand) $getreason"
  880. } else { set reason "$getreason"
  881. }
  882. set getcount [setting:get $chan kickcount]
  883. set kcount [expr $getcount +1]
  884. setting:set $chan kickcount $kcount
  885. set counts [getuser $hand XTRA KICKS($chan)]
  886. if {$counts == ""} { set counts 0 }
  887. set counts [expr $counts + 1]
  888. setuser $hand XTRA KICKS($chan) $counts
  889. set counts [getuser $hand XTRA KICKS_TODAY($chan)]
  890. if {$counts == ""} { set counts 0 }
  891. set counts [expr $counts + 1]
  892. setuser $hand XTRA KICKS_TODAY($chan) $counts
  893. if {[setting:get $chan showcount]} {
  894. set reason "$reason - $kcount -"
  895. } else {
  896. set reason "$reason"
  897. }
  898. if {[setting:get $chan xtools] || [setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  899. putserv "PRIVMSG $black(chanserv) :kick $chan $wnick $reason"
  900. } else {
  901. putserv "KICK $chan $wnick :$reason"
  902. }
  903. puthelp "PRIVMSG $wnick :[black:color:set $hand $black(say.$getlang.w.6)]"
  904. }
  905. ################################### k #################################
  906. proc k:process {knick nick hand host reason chan chan1 type} {
  907. global botnick black
  908. set cmd_status [btcmd:status $chan $hand "k" 0]
  909. if {$cmd_status == "1"} {
  910. return
  911. }
  912. set handle [nick2hand $knick]
  913. set found_host ""
  914. set kick_host 0
  915. set found_access ""
  916. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  917. return
  918. }
  919. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  920. return
  921. }
  922. if {$knick == ""} {
  923. switch $type {
  924. 0 {
  925. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "k"
  926. }
  927. 1 {
  928. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "k"
  929. }
  930. 2 {
  931. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "k"
  932. }
  933. }
  934. return
  935. }
  936. if {![validchan $chan]} {
  937. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  938. return
  939. }
  940. if {![botisop $chan] && ![setting:get $chan xonly]} {
  941. blacktools:tell $nick $host $hand $chan $chan1 gl.noop none
  942. return
  943. }
  944. if {![onchan $botnick $chan]} {
  945. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  946. return
  947. }
  948. if {[string match -nocase "*!*" $knick]} {
  949. set kick_host 1
  950. set finduser [finduser $knick]
  951. foreach user [chanlist $chan] {
  952. set gethand [nick2hand $user]
  953. set gethost "$user![getchanhost $user $chan]"
  954. if {[string match -nocase $knick $gethost]} {
  955. if {[matchattr $gethand $black(exceptflags) $chan]} {
  956. lappend found_access $user
  957. continue
  958. }
  959. lappend found_host $user
  960. }
  961. }
  962. }
  963. if {[matchattr $handle $black(exceptflags) $chan]} {
  964. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  965. return
  966. }
  967. if {$found_access != ""} {
  968. blacktools:tell $nick $host $hand $chan $chan1 k.2 $found_access
  969. return
  970. }
  971. if {![onchan $knick $chan] && $kick_host == "0"} {
  972. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $knick
  973. return
  974. }
  975. if {$kick_host == "1"} {
  976. if {$found_host == ""} {
  977. blacktools:tell $nick $host $hand $chan $chan1 k.1 none
  978. return
  979. }
  980. }
  981. if {[isbotnick $knick]} {
  982. return
  983. }
  984. if {$reason == ""} {
  985. if {[setting:get $chan k-reason] != ""} {
  986. set reason [join [setting:get $chan k-reason]]
  987. }
  988. }
  989. if {$reason == ""} {
  990. set getlang [string tolower [setting:get $chan lang]]
  991. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  992. set reason1 "$black(say.$getlang.k.5)"
  993. set len [llength $reason1]
  994. set random [expr int(rand()*$len)]
  995. set reason1 [lindex $reason1 $random]
  996. } else { set reason1 "$reason" }
  997. if {[setting:get $chan showhandle]} {
  998. set reason "($hand) $reason1"
  999. } else { set reason "$reason1"
  1000. }
  1001. set getcount [setting:get $chan kickcount]
  1002. set kcount [expr $getcount +1]
  1003. setting:set $chan kickcount $kcount
  1004. set counts [getuser $hand XTRA KICKS($chan)]
  1005. if {$counts == ""} { set counts 0 }
  1006. set counts [expr $counts + 1]
  1007. setuser $hand XTRA KICKS($chan) $counts
  1008. set counts [getuser $hand XTRA KICKS_TODAY($chan)]
  1009. if {$counts == ""} { set counts 0 }
  1010. set counts [expr $counts + 1]
  1011. setuser $hand XTRA KICKS_TODAY($chan) $counts
  1012. if {[setting:get $chan showcount]} {
  1013. set reason "$reason - $kcount -"
  1014. } else {
  1015. set reason "$reason"
  1016. }
  1017. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  1018. if {$found_host != ""} {
  1019. foreach f $found_host {
  1020. putserv "PRIVMSG $black(chanserv) :kick $chan $f $reason"
  1021. }
  1022. } else {
  1023. putserv "PRIVMSG $black(chanserv) :kick $chan $knick $reason"
  1024. }
  1025. } else {
  1026. if {$found_host != ""} {
  1027. foreach f $found_host {
  1028. putserv "KICK $chan $f :$reason"
  1029. }
  1030. } else {
  1031. putserv "KICK $chan $knick :$reason"
  1032. }
  1033. }
  1034. }
  1035. ################################## BanSTATS ################################
  1036. proc topbans:reset {chan} {
  1037. global black
  1038. if {![validchan $chan]} { return }
  1039. foreach user [userlist] {
  1040. set counts [getuser $user XTRA BANS($chan)]
  1041. set counts_k [getuser $user XTRA KICKS($chan)]
  1042. if {$counts == ""} {
  1043. continue
  1044. } else {
  1045. setuser $user XTRA BANS($chan) 0
  1046. setuser $user XTRA BANS_TODAY($chan) 0
  1047. }
  1048. if {$counts_k == ""} {
  1049. continue
  1050. } else {
  1051. setuser $user XTRA KICKS($chan) 0
  1052. setuser $user XTRA KICKS_TODAY($chan) 0
  1053. }
  1054. }
  1055. foreach user [userlist $chan] {
  1056. set counts [getuser $user XTRA BANS($chan)]
  1057. set counts_k [getuser $user XTRA KICKS($chan)]
  1058. if {$counts == ""} {
  1059. continue
  1060. } else {
  1061. setuser $user XTRA BANS($chan) 0
  1062. setuser $user XTRA BANS_TODAY($chan) 0
  1063. }
  1064. if {$counts_k == ""} {
  1065. continue
  1066. } else {
  1067. setuser $user XTRA KICKS($chan) 0
  1068. setuser $user XTRA KICKS_TODAY($chan) 0
  1069. }
  1070. }
  1071. }
  1072. proc banstats:process {nick host hand chan chan1 cmd type next} {
  1073. global botnick black
  1074. set counter 0
  1075. set cmd_status [btcmd:status $chan $hand "banstats" 0]
  1076. if {$cmd_status == "1"} {
  1077. return
  1078. }
  1079. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  1080. return
  1081. }
  1082. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  1083. return
  1084. }
  1085. if {$chan == ""} {
  1086. if {$type == "0"} {
  1087. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "banstats"
  1088. }
  1089. if {$type == "1"} {
  1090. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "banstats"
  1091. }
  1092. if {$type == "2"} {
  1093. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "banstats"
  1094. }
  1095. }
  1096. if {![validchan $chan]} {
  1097. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  1098. return
  1099. }
  1100. if {$cmd == "total"} {
  1101. set bans "BANS($chan)"
  1102. } else {
  1103. set bans "BANS_TODAY($chan)"
  1104. }
  1105. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  1106. set temp "$black(tempdir)/topbans_temp.$timestamp"
  1107. if {[string equal -nocase $cmd "reset"]} {
  1108. set reset [topbans:reset $chan]
  1109. blacktools:tell $nick $host $hand $chan $chan1 topbans.8 none
  1110. return
  1111. }
  1112. array set topbanslist [list]
  1113. foreach u [userlist] {
  1114. set totalbans [getuser $u XTRA $bans]
  1115. if {$totalbans != "" && $totalbans != "0"} {
  1116. lappend topbanslist($totalbans) $u
  1117. }
  1118. }
  1119. foreach u [userlist $chan] {
  1120. if {[matchattr $u $black(localflags) $chan]} {
  1121. set totalbans [getuser $u XTRA $bans]
  1122. if {$totalbans != "" && $totalbans != "0"} {
  1123. lappend topbanslist($totalbans) $u
  1124. }
  1125. }
  1126. }
  1127. set tempwrite [open $temp w]
  1128. foreach u [lsort -integer -decreasing [array names topbanslist]] {
  1129. set counter [expr $counter + 1]
  1130. puts $tempwrite "[join $topbanslist($u) ","] $u $counter"
  1131. }
  1132. close $tempwrite
  1133. set file [open $temp "r"]
  1134. set w [read -nonewline $file]
  1135. close $file
  1136. set data [split $w "\n"]
  1137. file delete $temp
  1138. if {$data == ""} {
  1139. if {$cmd == "total"} {
  1140. blacktools:tell $nick $host $hand $chan $chan1 topbans.10 none
  1141. } else {
  1142. blacktools:tell $nick $host $hand $chan $chan1 topbans.14 none
  1143. }
  1144. return
  1145. }
  1146. if {$cmd == "total"} {
  1147. module:getinfo $nick $host $hand $chan $chan1 $type $data "topbans:total" "0" $next
  1148. } else {
  1149. module:getinfo $nick $host $hand $chan $chan1 $type $data "topbans" "0" $next
  1150. }
  1151. }
  1152. ##############
  1153. #########################################################################
  1154. ## END ##
  1155. #########################################################################