Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sun Jan 08, 2023 8:41 pm
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,
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Mon Jan 09, 2023 4:21 pm
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
}
CrazyCat
Revered One
Posts: 1251 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Mon Jan 09, 2023 7:15 pm
This doesn't really solve your problem as the kick occures each 2s.
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Mon Jan 09, 2023 7:27 pm
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
}
}
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Jan 10, 2023 2:54 am
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
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Jan 10, 2023 3:02 am
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
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Tue Jan 10, 2023 4:32 am
No, it was "proper" as I posted it originally.
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Jan 10, 2023 5:59 am
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
caesar
Mint Rubber
Posts: 3776 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Tue Jan 10, 2023 12:49 pm
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.
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Jan 10, 2023 3:47 pm
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
simo
Revered One
Posts: 1091 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Jan 10, 2023 4:43 pm
ive tested again and original code seems to work fine now SpiKe^^ thanks much apreciated