Here's the updated and tested code.
Code: Select all
namespace eval NickCase {
set channel "#The-Dungeon"
bind join - * [namespace current]::joined
bind nick - * [namespace current]::nick
proc joined {nick uhost hand chan} {
if {[isbotnick $nick] || ![botisop $chan]} return
variable channel
if {![string match -nocase $chan $channel]} return
if {![string equal $nick [string totitle $nick]]} {
pushmode $chan +v $nick
}
}
proc nick {nick uhost hand chan newnick} {
if {[isbotnick $nick] || ![botisop $chan]} return
variable channel
if {![string match -nocase $chan $channel]} return
set match [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]]
if {[isvoice $nick $chan]} {
if {$match} {
pushmode $chan -v $newnick
}
} else {
if {!$match} {
pushmode $chan +v $newnick
}
}
}
}
The main issue was because of
botisop part in:
Code: Select all
if {[isbotnick $nick] || [botisop $chan]} return
that basically means if the bot is channel operator then it would stop executing anything past this line, when in fact wanted to stop the execution only if the bot wasn't channel operator, hence the ! in front of the
[botisop $chan] in above "updated" code.
The second issue I've discovered is that
string totitle on it's own wasn't enough because it turns SomeNick into Somenick and the previous test:
Code: Select all
if {[string equal $newnick [string totitle $newnick]]} {
basically will test if SomeNick is now equal with Somenick and will fail. So, instead I now take the first letter of the new nick and compare it with the first letter from
string totitle result.
An alternative to:
Code: Select all
set match [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]]
could be:
Code: Select all
set match [expr [regexp -all {[A-Z]} $newnick]]
but in a 1000 iterations test the
string equal one seems slightly faster, even if it's ugly.
Code: Select all
% time {for {set i 0} {$i < 1000} {incr i} { append mylist [regexp -all {[A-Z]} $newnick] }}
1731 microseconds per iteration
% time {for {set i 0} {$i < 1000} {incr i} { append mylist [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]] }}
1425 microseconds per iteration
Once the game is over, the king and the pawn go back in the same box.