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.

check if nick is still on channel before kicking

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: 1090
Joined: Sun Mar 22, 2015 2:41 pm

check if nick is still on channel before kicking

Post by simo »

greetingz gentz,

i'm wondering how to edit this code in the kick proc to check if nick(s) are still in channel before executing the kick command(s) as we use a timer, let me post the code:

Code: Select all


namespace eval enforceBans {

   set enforce(max) "4"

   set enforce(reason_single) "Please respect the network rules, thank you."
   set enforce(reason_multi) "Please respect the network rules, thank you."

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

   proc enforce {nick uhost hand chan mc ban} {
      variable kickList
      if {[matchaddr $ban $::botname]} { 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 300 [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 ""
        }
         after 2000 [list putnow "KICK $chan $nicks :$reason"]
      }
      return 0
   }
}


thanks in advance gentz,
s
simo
Revered One
Posts: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i gave it a try and came of with this it seems to work but im not sure if its done proper

Code: Select all


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

  foreach nickx $kickList($chan) { if {[onchan $nickx $chan]} {  set klist $nickx ;  lappend NewKickList($chan) $klist  } }
      set knicks [lsort -unique -dictionary $NewKickList($chan)]
      unset kickList($chan)
      unset NewKickList($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 ""
        }
         after 2000 [list putnow "KICK $chan $nicks :$reason"]
      }
      return 0
   }


User avatar
CrazyCat
Revered One
Posts: 1252
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

This doesn't really solve your problem as the kick occures each 2s.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

enforceBans

Post by SpiKe^^ »

maybe...

Code: Select all

namespace eval enforceBans {  variable enforce  ;  variable kickList

   set enforce(max) "4"

   set enforce(reason_single) "Please respect the network rules, thank you."
   set enforce(reason_multi) "Please respect the network rules, thank you."

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

   proc enforce {nick uhost hand chan mc ban} {
      variable kickList
      if {[matchaddr $ban $::botname]} { 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 2300 [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)]} {

         if {[info exists kickList($chan)]} {  unset kickList($chan)  }

         return 0
      }


      foreach k [lsort -unique -dictionary $kickList($chan)] {
         if {[onchan $k $chan]} {  lappend knicks $k  }
      }
      unset kickList($chan)

      if {![info exists knicks]} {  return 0  }


      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 ""
        }


        putnow "KICK $chan $nicks :$reason"

      }
      return 0
   }
}

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: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks for the reply CrazyCat and SpiKe^^

yes i overlooked the duplicate timers to kick thanks for correcting CrazyCat

i tried your posted code and it didnt seem to Trigger SpiKe^^ and i didnt get any errors
s
simo
Revered One
Posts: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i tried editing it to this :

Code: Select all


      foreach k "[lsort -unique -dictionary $kickList($chan)]" {
         if {[onchan $k $chan]} {  lappend knicks $k  }
      }

it seems to have fixed it but not sure if i edited it proper tho
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

No, it was "proper" as I posted it originally.
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: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Using the original one you posted didn't seem to trigger SpiKe i will try again later when im on pc and report again hopefully thanks SpiKe
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If for whatever reason lsort doesn't work for you then try with dict, here's an example:

Code: Select all

foreach ele $myList {dict set tmp $ele myList}
set unique [dict keys $tmp]
I would switch back to the original 'enforce:kick' and use a helper function instead:

Code: Select all

proc filter:kick {chan} {
	if {![botisop $chan] || ![info exists kickList($chan)]} return
	foreach ele $kickList($chan) {dict set tmp $ele kickList($chan)}
	set kickList($chan) [dict keys $tmp]
	enforce:kick $chan
}
and call filter:kick in the after line instead of the enforce:kick.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks for your reply caesar ive tried your suggestion as well and for some reason it doesnt seem to trigger and i didnt get any error in PL
s
simo
Revered One
Posts: 1090
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

ive tested again and original code seems to work fine now SpiKe^^ thanks much apreciated
Post Reply