Sfoglia il codice sorgente

Update BT.antichanflood.tcl

added to namespace
improvements
BLaCkShaDoW 1 anno fa
parent
commit
d7d29686d3
1 ha cambiato i file con 43 aggiunte e 34 eliminazioni
  1. 43 34
      BlackTools/Protections/BT.antichanflood.tcl

+ 43 - 34
BlackTools/Protections/BT.antichanflood.tcl

@@ -14,41 +14,50 @@
 ##					                               ##
 #########################################################################
 
-proc antifloodchan:protect {nick host hand chan arg} {
-global black
-if {![validchan $chan]} { return }
-	set handle [nick2hand $nick]
-if {![botisop $chan] && ![setting:get $chan xonly]} { return }
-if {[matchattr $handle $black(exceptflags) $chan]} { return }
-if {[isbotnick $nick]} { return  }
-	set bl_protect [blacktools:protect $nick $chan]
-if {$bl_protect == "1"} { return }
-	set getset [setting:get $chan chanflood]
-if {$getset == ""} { set getset "$black(antichanfloodrepeats)" }
-	set number [scan $getset %\[^:\]]
-	set time [scan $getset %*\[^:\]:%s]
-if {![info exists black(repeat:$host:$chan:flood)]} { 
-	set black(repeat:$host:$chan:flood) 0 
-}
-foreach tmr [utimers] {
-if {[string match "*chanflood:unset $host $chan*" [join [lindex $tmr 1]]]} {
-	killutimer [lindex $tmr 2]
-	}
-}
-	incr black(repeat:$host:$chan:flood)
-	utimer $time [list chanflood:unset $host $chan]
-if {$black(repeat:$host:$chan:flood) >= $number} {
-	blacktools:banner:1 $nick "ANTICHANFLOOD" $chan $host [get:banmethod "antichanflood" $chan] [link:chan:get $chan]
-	chanflood:unset $host $chan
-	return 1
-	}
-}
+namespace eval antifloodchan {
+    variable black
+
+    proc protect {nick host hand chan arg} {
+        variable black
+        if {![validchan $chan]} { return }
+        set handle [nick2hand $nick]
+        if {![botisop $chan] && ![setting:get $chan xonly]} { return }
+        if {[matchattr $handle $black(exceptflags) $chan]} { return }
+        if {[isbotnick $nick]} { return }
+        
+        set bl_protect [blacktools:protect $nick $chan]
+        if {$bl_protect == "1"} { return }
+
+        set getset [setting:get $chan chanflood]
+        if {$getset == ""} { set getset "$black(antichanfloodrepeats)" }
+
+        regexp {(\d+):(\d+)} $getset -> number time
+        if {![info exists black(repeat:$host:$chan:flood)]} { 
+            set black(repeat:$host:$chan:flood) 0 
+        }
+
+        foreach tmr [utimers] {
+            if {[string match "*antifloodchan::unset $host $chan*" [join [lindex $tmr 1]]]} {
+                killutimer [lindex $tmr 2]
+            }
+        }
+
+        incr black(repeat:$host:$chan:flood)
+        utimer $time [list antifloodchan::unset $host $chan]
+
+        if {$black(repeat:$host:$chan:flood) >= $number} {
+            blacktools:banner:1 $nick "ANTICHANFLOOD" $chan $host [get:banmethod "antichanflood" $chan] [link:chan:get $chan]
+            antifloodchan::unset $host $chan
+            return 1
+        }
+    }
 
-proc chanflood:unset {host chan} {
-	global black
-if {[info exists black(repeat:$host:$chan:flood)]} { 
-	unset black(repeat:$host:$chan:flood)
-	}
+    proc unset {host chan} {
+        variable black
+        if {[info exists black(repeat:$host:$chan:flood)]} { 
+            unset black(repeat:$host:$chan:flood)
+        }
+    }
 }
 
 ##############