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.

ban enforce doesnt stack kicks

Help for those learning Tcl or writing their own scripts.
Post Reply
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

ban enforce doesnt stack kicks

Post by simo »

i took this code caesar wrote from another post to enforce bans to kick in stack
only to find it doesnt seem to stack it sends all found banned nicks to be kicked seperate

Code: Select all

namespace eval enforceBans {

   set enforce(max) "4"

   set enforce(reason) "Ban %ban set in %from matches your host. You are banned!"
 
   bind mode - "% +b" [namespace current]::enforce

   proc enforce {nick uhost hand chan mc ban} {
      variable enforce
      set reason [string map [list "%from" $chan "%ban" $ban "%who" $nick] $enforce(reason)]
      if {![botisop $chan]} { return 0 }
      set ban [string map {"\\" "\\\\" "\[" "\\["} $ban]
       if {[matchstr "*@*mibbit*" "$ban"]} { return 0 }
       if {[string match -nocase $ban $::botname]} { return }
         foreach n [chanlist $chan] {
            if {![matchaddr $ban $n![getchanhost $n $chan]]} continue
            if {[isop $n $chan] || [ishalfop $n $chan] || [matchattr [nick2hand $n] "fnmo|fnmo" $chan]} continue
          if {[onchan $n $chan]} { lappend kickList($chan) $n }
         }
      if {[llength $kickList($chan)]  > 2} { return }
         if {[info exists kickList($chan)]} {
         set kickList($chan) [lsort -dictionary $kickList($chan)]
            set len [llength $kickList($chan)]
            while {$len > 0} {
               if {$len > $enforce(max)} {
                  set users [join [lrange $kickList($chan) 0 [expr {$enforce(max) - 1}]] ,]
                  set kickList($chan) [lrange $kickList($chan) $enforce(max) end]
                  incr len -$enforce(max)
               } else {
                  set users [join $kickList($chan) ,]
                  set len 0
               }
             after [expr {2*1000*1}] [list putnow "kick $chan $users $reason"]
            }
         }
      }
   }
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i cant figure why it doesnt stack the nicks to kick
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Short question: does your server accept multiple kicks in a single line ?
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

yes dalnet does 4 and inspircd 20
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i tried with this:

Code: Select all

namespace eval enforceBans {

   set enforce(max) "4"

   set enforce(reason) "Ban %ban set in %from matches your host. You are banned!"
 
   bind mode - "% +b" [namespace current]::enforce

   proc enforce {nick uhost hand chan mc ban} {
      variable enforce
      variable kickList
      set reason [string map [list "%from" $chan "%ban" $ban "%who" $nick] $enforce(reason)]
      if {![botisop $chan]} { return 0 }
      set ban [string map {"\\" "\\\\" "\[" "\\["} $ban]
       if {[matchstr "*@*mibbit*" "$ban"]} { return 0 }
       if {[string match -nocase $ban $::botname]} { return }
         foreach n [chanlist $chan] {
            if {![matchaddr $ban $n![getchanhost $n $chan]]} continue
            if {[isop $n $chan] || [ishalfop $n $chan] || [matchattr [nick2hand $n] "fnmo|fnmo" $chan]} continue
          if {[onchan $n $chan]} { lappend kickList($chan) $n }
         }

         if {[info exists kickList($chan)]} {
         set kickList($chan) [lsort -dictionary $kickList($chan)]
            set len [llength $kickList($chan)]
            while {$len > 0} {
               if {$len > $enforce(max)} {
                  set users [join [lrange $kickList($chan) 0 [expr {$enforce(max) - 1}]] ,]
                  set kickList($chan) [lrange $kickList($chan) $enforce(max) end]
                  incr len -$enforce(max)
               } else {
                  set users [join $kickList($chan) ,]
                  set len 0
               }
             after [expr {2*1000*1}] [list putnow "kick $chan $users $reason"]
            }
         }
      }
   }

but it doesnt get rid of the nicks that are already kicked it keeps adding the same nicks
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Code: Select all

namespace eval enforceBans {
   variable enforce  ;  variable kickList

   set enforce(max) "4"

   #set enforce(reason_single) "Ban %ban set in %from matches your host. You are banned!"
   set enforce(reason_multi) "A new ban in %from matches your host. You are banned!"

   bind mode - "% +b" [namespace current]::enforce

   proc enforce {nick uhost hand chan mc ban} {
      variable kickList
      if {[matchaddr $ban $::botname]} { return 0 }
      if {[matchstr "*@*mibbit*" $ban]} { return 0 }

      foreach n [chanlist $chan] {
         if {![matchaddr $ban $n![getchanhost $n $chan]]} { continue }
         if {[isop $n $chan] || [ishalfop $n $chan]} { continue }
         if {[matchattr [nick2hand $n] "fnmo|fnmo" $chan]} { continue }
         lappend klist $n
      }
      if {![info exists klist]} { return 0 }

      if {![info exists kickList($chan)]} {
         set kickList($chan) $klist
         after 2000 [list "[namespace current]::enforce:kick" $chan]

      } else {  lappend kickList($chan) {*}$klist  }

      return 0
   }

   proc enforce:kick {chan} {
      variable enforce
      variable kickList
      if {![botisop $chan] || ![info exists kickList($chan)]} {
         array unset kickList $chan
         return 0
      }

      set knicks [lsort -unique -dictionary $kickList($chan)]
      unset kickList($chan)

      set max $enforce(max)
      set reason [string map [list %from $chan] $enforce(reason_multi)]

      while {[set len [llength $knicks]] > 0} {
        if {$len > $max} {
          set nicks [join [lrange $knicks 0 [expr {$max - 1}]] ","]
          set knicks [lrange $knicks $max end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }
        putquick "KICK $chan $nicks :$reason"
      }
      return 0
   }

}

Last edited by SpiKe^^ on Tue Jan 11, 2022 2:07 pm, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

excellent thanks Spike^^ that seems to do it
Post Reply