This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

repeat tcl with warning with error

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

repeat tcl with warning with error

Post by simo »

greetingz gentz,

ive been trying this edited version of an anti repeat lines and anti repeat chars tcl with warnings added wich doesnt seem work as expected gettin this error:
Tcl error [::repeatf::repeatpubm]: can't read "warn(max)": no such element in array

Code: Select all

    
 proc string2pattern {str} { regsub -all -- {(\[|\]|\\|\?|\*)} $str {\\\1} } 



namespace eval ::repeatf {

	bind pubm - * [namespace current]::repeatpubm

	variable following
	variable repeatf
	variable warn

	set repeatf(wmsg) "Warning: You've triggered %type repeating protection, stop repeating."

          #.chanset #channel ap:repeatc 25 30 w:k:kb 2
          #.chanset * ap:repeatl 2:10 60 k:kb 2

	#setudef flag antirepeat
	setudef str ap:repeatc
	variable defrepeatc {25 30 w:k:kb 2}
	setudef str ap:repeatl
	variable defrepeatl {2:10 60 k:kb 2}

bind ctcp - ACTION [namespace current]::anti_char-repeat:action
 

proc anti_char-repeat:action {n u h d k t} {
 if {[isbotnick $d] || [isop $n $d] || [ishalfop $n $d] || [matchattr [nick2hand $n] ofn|ofn $d]} { return 0 }
  repeatpubm $n $u $h $d $t
}

	proc repeatpubm {nick uhost hand chan arg} {
    if {[isvoice $nick $chan] || [isbotnick $chan] || [isop $nick $chan] || [ishalfop $nick $chan] || [matchattr [nick2hand $nick] ofn|ofn $chan]} { return 0 }
	set users [list]
	set umasks [list]
		variable repeatf
		#if {![channel get $chan antirepeat]} {return 1}
		variable defrepeatc
		variable defrepeatl
         variable warn
		if {[string is space [channel get $chan ap:repeatc]]} {channel set $chan ap:repeatc $defrepeatc}
		if {[string is space [channel get $chan ap:repeatl]]} {channel set $chan ap:repeatl $defrepeatl}

		foreach {off btime pmeth btype} [set cgot [split [channel get $chan ap:repeatl]]] {break}
		foreach {o s} [cgsplit $off] {break}
		set arg [string map {\017 {}} [stripcodes bcruag $arg]]
		if {![invalid:apf $o $s]} {
			if {[set ts [follow $s rpt:[md5 [string tolower $uhost:$arg:$chan]] $o]] != -1} {
				set kmsg "$o repeats in $ts secs"
				set wmsg [string map {%type text} $repeatf(wmsg)] ; set reptype repeatl
			}
		}
		if {![info exists kmsg]} {
			set cgotc [split [channel get $chan ap:repeatc]]
			if {[string is integer [set i [lindex $cgotc 0]]] && $i > 0} {
				set cl "abcdefghijklmnopqrstuvwxyz0123456789?!@#$%^&.-_=)([]{}\\\/~`*|,<'>"
				for {set c 0} {$c < [string length $cl]} {incr c} {
		if {[string match -nocase *[string2pattern [string repeat [string index $cl $c] $i]]* $arg]} {
						foreach {btime pmeth btype} [lrange $cgotc 1 end] {break}
						set kmsg "${i}+ consecutive [string index $cl $c]'s"
						set wmsg [string map {%type letter} $repeatf(wmsg)] ; set reptype repeatc ; break
					}
				}
			}
		}
		if {[info exists kmsg]} {

				set chost [getchanhost $nick $chan]
                  regsub -all -- ~ $chost "" chost


  if {![info exists warn($uhost)]} {
    set warn($uhost) 1
    utimer $warn(reset) [list [namespace current]::action:reset $uhost]
  } else {  incr warn($uhost)  }


  if {$warn($uhost) > $warn(max)} {
 
    	     if {[string match -nocase "*@*irccloud*" [maskhost $nick!$chost 2]] || [string match -nocase "*@*kiwiirc*" [maskhost $nick!$chost 2]] || [string match -nocase "*@*mibbit*" [maskhost $nick!$chost 2]]} {  
                   set ident  [lindex [split $chost @] 0]
                   set xbmaskx [string map {sid id uid id} $ident]
                    set bmask  *!*[string tolower $xbmaskx ]@*
                    pushmode $chan +b $bmask
         } else {  pushmode $chan +b "*!*@[maskhost $nick!$chost 2]"  }

    putquick "kick $chan $nick dont repeat please thank you..."
  } else {
    putserv "PRIVMSG $chan :Warning $warn($uhost): No Action Please"
           }
		}
 		return 1
}

proc action:reset {uhost} {
  variable warn
  if {[info exists warn($uhost)]} {  unset warn($uhost)  }
}

 proc cgsplit off {
		foreach {o s} [split $off :] {break}
		expr {([info exists o]&&[info exists s])?[list $o $s]:{0 0}}
	}

	proc invalid:apf {o s} {
		expr {![string is integer -strict $o] || $o <= 0 || ![string is double -strict $s] || $s <= 0}
	}

	proc follow {s fv pun {v 1} {ty 0}} {
		variable following
		if {![info exists following($fv)]} {
			set o $v
			set t [clock clicks -milliseconds]
		} {
			foreach {o t} $following($fv) {break}
			incr o $v
		}
		if {[set z [expr {([clock clicks -milliseconds]-$t)/1000.}]] >= $s} {
			set o $v
			set t [clock clicks -milliseconds]
		}
		set following($fv) [list $o $t]
		if {$o >= $pun} {if {!$ty} {followrem following($fv)} ; return [expr {$z>=$s?0.0:$z}]}
		return -1
	}

	proc followrem fv {
		upvar [namespace current]::$fv f
		if {[info exists f]} {unset f}
	}
}
 
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Where is defined warn(max) ? Not in this part of script
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CrazyCat overlooked that and warn reset as well that seemed to fix it
Post Reply