BT.antispam.tcl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################## ANTISPAM TCL #############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. proc antispam:protect {nick host hand arg} {
  17. global botnick black
  18. set handle [nick2hand $nick]
  19. set channels ""
  20. foreach chans [channels] {
  21. if {[setting:get $chans antispam]} {
  22. set found_spam ""
  23. set text [color:filter $arg]
  24. set text [check:except $text $chans $black(spamword) $black(spamwordexcept) "ANTISPAM"]
  25. set check_word [check:file:word $chans $text "ANTISPAM"]
  26. if {$check_word == ""} {
  27. continue
  28. } else {
  29. set found_spam $check_word
  30. }
  31. set chan1 $chans
  32. if {![validchan $chans]} { return }
  33. if {[matchattr $handle $black(exceptflags) $chans]} { return }
  34. set bl_protect [blacktools:protect $nick $chans]
  35. if {$bl_protect == "1"} { return }
  36. if {[onchan $nick $chans]} {
  37. if {![botisop $chans] && ![setting:get $chans xonly]} { return }
  38. if {[isbotnick $nick]} { return }
  39. lappend channels $chans
  40. if {[link:status $chans] == "1"} {
  41. foreach c [link:chan:get $chans] {
  42. lappend channels $c
  43. }
  44. }
  45. }
  46. }
  47. }
  48. if {$channels != ""} {
  49. antispam:act:ban [join $channels] 0 $nick $host $found_spam
  50. }
  51. }
  52. proc antispam:act:ban {channels num nick host found_spam} {
  53. global black
  54. set chan [join [lindex [split $channels] $num]]
  55. set inc 0
  56. if {$chan == ""} {
  57. return
  58. }
  59. if {[onchan $nick $chan]} {
  60. blacktools:banner:2 $nick "ANTISPAM:$found_spam" $chan $chan $host "0" ""
  61. who:chan $chan
  62. }
  63. set inc [expr $num + 1]
  64. if {[lindex $channels $inc] != ""} {
  65. utimer 5 [list antispam:act:ban $channels $inc $nick $host $found_spam]
  66. }
  67. }
  68. proc antispam:protect:msg {nick host hand chan} {
  69. global black
  70. if {![validchan $chan]} { return }
  71. if {[setting:get $chan antispam]} {
  72. if {[isbotnick $nick]} { return }
  73. if {[info exists black(turnOnFlood:$chan)]} {
  74. return
  75. }
  76. if {[setting:get $chan spamjoinmessage]} {
  77. if {[matchattr $hand $black(exceptflags) $chan]} { return }
  78. set getmsg [setting:get $chan antispam-message]
  79. if {$getmsg == ""} {
  80. set getlang [string tolower [setting:get $chan lang]]
  81. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  82. set getmsg $black(say.$getlang.antispam.2)
  83. }
  84. set replace(%nick%) $nick
  85. set replace(%chan%) $chan
  86. set text [black:color:set "" $getmsg]
  87. set reply [join $text]
  88. set reply [string map [array get replace] $reply]
  89. puthelp "PRIVMSG $nick :$reply"
  90. }
  91. }
  92. }
  93. proc antispam:protect:cycle {channels} {
  94. global black
  95. set chans ""
  96. foreach chan $channels {
  97. if {![channel get $chan inactive]} {
  98. lappend chans $chan
  99. }
  100. }
  101. if {$chans != ""} {
  102. antispam:act $chans 0
  103. }
  104. }
  105. proc antispam:act {channels counter} {
  106. global black
  107. set notcycle 0
  108. set chan [join [lindex [split $channels] $counter]]
  109. set cc [expr $counter + 1]
  110. if {[info exists black(lastaction:$chan)]} {
  111. set total_anunt 0
  112. set unixtime [unixtime]
  113. if {[setting:get $chan antispam-scantime] != ""} {
  114. set return_time [time_return_minute [setting:get $chan antispam-scantime]]
  115. } else {
  116. set return_time [time_return_minute $black(spamcycle)]
  117. }
  118. set time [expr [expr [expr $return_time * $black(entry:shown)] * 60] + $unixtime]
  119. if {[expr $unixtime - $black(lastaction:$chan)] > [expr $time - $unixtime]} {
  120. set notcycle 1
  121. }
  122. } else { set notcycle 1 }
  123. if {$notcycle != "1"} {
  124. set getlang [string tolower [setting:get $chan lang]]
  125. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  126. set reason $black(say.$getlang.antispam.11)
  127. set len [llength $reason]
  128. set random [expr int(rand()*$len)]
  129. set reason [lindex $reason $random]
  130. set text [black:color:set "" $reason]
  131. set reply [join $text]
  132. putserv "PART $chan :$reply"; putserv "JOIN $chan"
  133. }
  134. if {[lindex $channels $cc] == ""} {
  135. return
  136. } else {
  137. utimer 10 [list antispam:act $channels $cc]
  138. }
  139. }
  140. proc antispam:module {nick host hand chan arg} {
  141. global black lastbind
  142. set type 0
  143. set chan1 "$chan"
  144. set why [lindex [split $arg] 0]
  145. set antisp [join [lrange [split $arg] 1 end]]
  146. set number [lindex [split $arg] 1]
  147. if {[regexp {^[&#]} $why] && [matchattr $hand nmo|M $why]} {
  148. set chan "$why"
  149. set why [lindex [split $arg] 1]
  150. set antisp [join [lrange [split $arg] 2 end]]
  151. set number [lindex [split $arg] 2]
  152. }
  153. set return [blacktools:mychar $lastbind $hand]
  154. if {$return == "0"} {
  155. return
  156. }
  157. prot:module:process $nick $host $hand $chan $chan1 $why $badh $type $number "antispam"
  158. }
  159. ##############
  160. #########################################################################
  161. ## END ##
  162. #########################################################################