Code: Select all
% set elements [list 1 2 3 4 5]
1 2 3 4 5
% foreach ele $elements { if {$ele == 3} { return } else { puts $ele } }
1
2
% foreach ele $elements { if {$ele == 3} { continue } else { puts $ele } }
1
2
4
5
Notice the difference in using
return and
continue?
You are aware that the && in:
Code: Select all
if {![botisop $c] && [isbotnick $n] && [isop $n $c] && [ishalfop $n $c] && [matchattr [nick2hand $n] $accessFlags $c]} {return}
means if bot is channel operator in channel AND bot is the nick AND nick is channel operator AND nick is halfop AND nick's user matches the global|channel flags you said THEN
return. You should use || that means OR not && that means AND. For example:
Code: Select all
% foreach ele $elements { if {$ele == 3 && $ele == 5} { continue } else { puts $ele } }
1
2
3
4
5
% foreach ele $elements { if {$ele == 3 || $ele == 5} { continue } else { puts $ele } }
1
2
4
Notice the difference? he wants to exclude ANY of the matching cases, not the case that would match ALL of the tests.
Here's my take on this. Did some limited testing and works fine. I used putkick as it puts multiple names in the same line thus doesn't flood the server with multiple requests to kick a single member per line.
Code: Select all
namespace eval enforceBans {
# How many members can be kicked in the same line
set enforce(max) "6"
# Define the reason. Notice the %ban that will be replaced with the actual mask.
# You can use %nick as well and will also be replaced with the actual name of the user who set the ban.
set enforce(reason) "Ban %ban set in %chan matches your host. You are banned!"
bind mode - "% +b" [namespace current]::enforce
proc enforce {nick uhost hand chan mc ban} {
variable enforce
foreach c [channels] {
if {![botisop $c]} continue
foreach n [lreplace [chanlist $c] 0 0] {
if {![string match -nocase $ban $n![getchanhost $n $c]]} continue
if {[isop $n $c] || [ishalfop $n $c] || [matchattr [nick2hand $n] "fnmo|fnmo" $c]} continue
lappend kickList($c) $n
}
}
foreach c [array names kickList] {
set len [llength $kickList($c)]
if {![string equal -nocase $c $chan]} {
pushmode $c +b $ban
}
while {$len > 0} {
if {$len > $enforce(max)} {
set users [join [lrange $kickList($c) 0 [expr {$enforce(max) - 1}]] ,]
set kickList($c) [lrange $kickList($c) $enforce(max) end]
incr len - $enforce(max)
} else {
set users [join $kickList($c) ,]
set len 0
}
set reason [string map [list "%chan" $chan "%ban" $ban "%nick" $nick] $enforce(reason)]
putkick $c $users $reason
}
}
}
}
When setting X bans on the same line the bot will trigger a
bind mode - "% +b" proc X times for each ban mask, but will trigger a
mode - "% -b" proc only once per 6 bans (or whatever is the max amount of bans per line the server you are connected allows) when removing bans. Honestly I fail to understand the logic behind this difference.
Once the game is over, the king and the pawn go back in the same box.