View previous topic :: View next topic |
Author |
Message |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Sun Jan 08, 2023 8:41 pm Post subject: check if nick is still on channel before kicking |
|
|
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: |
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, |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Mon Jan 09, 2023 4:21 pm Post subject: |
|
|
i gave it a try and came of with this it seems to work but im not sure if its done proper
Code: |
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
}
|
|
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1145 Location: France
|
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 831 Location: Tennessee, USA
|
Posted: Mon Jan 09, 2023 7:27 pm Post subject: enforceBans |
|
|
maybe...
Code: |
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
. |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Tue Jan 10, 2023 2:54 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Tue Jan 10, 2023 3:02 am Post subject: |
|
|
i tried editing it to this :
Code: |
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 |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 831 Location: Tennessee, USA
|
Posted: Tue Jan 10, 2023 4:32 am Post subject: |
|
|
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
. |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Tue Jan 10, 2023 5:59 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3775 Location: Mint Factory
|
Posted: Tue Jan 10, 2023 12:49 pm Post subject: |
|
|
If for whatever reason lsort doesn't work for you then try with dict, here's an example:
Code: |
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: |
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. |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Tue Jan 10, 2023 3:47 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
simo Revered One
Joined: 22 Mar 2015 Posts: 1047
|
Posted: Tue Jan 10, 2023 4:43 pm Post subject: |
|
|
ive tested again and original code seems to work fine now SpiKe^^ thanks much apreciated |
|
Back to top |
|
 |
|