egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

repeat tcl with warning with error

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 969

PostPosted: Mon Sep 26, 2022 9:08 am    Post subject: repeat tcl with warning with error Reply with quote

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:

Quote:

Tcl error [::repeatf::repeatpubm]: can't read "warn(max)": no such element in array



Code:

   
 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}
   }
}
 
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1057
Location: France

PostPosted: Mon Sep 26, 2022 9:34 am    Post subject: Reply with quote

Where is defined warn(max) ? Not in this part of script
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 969

PostPosted: Mon Sep 26, 2022 11:32 am    Post subject: Reply with quote

thanks CrazyCat overlooked that and warn reset as well that seemed to fix it
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber