Here's the code that does it:
Code: Select all
proc bMotionChooseRandomBot { channel } {
putloglev 1 * "bMotion: checking $channel"
global botnick
set bots [chanlist $channel]
set botslist [list]
foreach bot $bots {
set handle [nick2hand $bot $channel]
putloglev 1 * "bMotion: checking $bot ($handle)"
if [matchattr [nick2hand $bot $channel] b&K $channel] {
lappend botslist $bot
}
}
set bots $botslist
putloglev 1 * "bMotion: found [llength $bots] bots in $channel, $bots"
if {[llength $bots] == 0} {
return ""
}
set rbot $botnick
while {$rbot == $botnick} {
set rbot [lindex $bots [rand [llength $bots]]]
}
return $rbot
}
Before anyone has a go at me for messy code or anything, it was a lot cleaner before I started throwing debug stuff in
Indeed, it was just pretty much [chanlist $channel b&K] when I started
The output from this immediately after a .rehash is:
Code: Select all
[14:11] bMotion: checking #___
[14:11] bMotion: checking NoTopic (*)
[14:11] bMotion: checking JamesOff (JamesOff)
[14:11] bMotion: checking MonicaOff (*)
[14:11] bMotion: checking KipAway (*)
[14:11] bMotion: found 0 bots in #___,
If I do a .channel and run the code again:
Code: Select all
[14:12] bMotion: checking #___
[14:12] bMotion: checking NoTopic (NoTopic)
[14:12] bMotion: checking JamesOff (JamesOff)
[14:12] bMotion: checking MonicaOff (MonicaOff)
[14:12] bMotion: checking KipAway (TurboKip)
[14:12] bMotion: found 1 bots in #___, MonicaOff
(Which is right, Monica's the bot I wanted it to find.)
Since this definitely seems to be the cause of the problem, I'll switch it all back to [chanlist $channel b|K] I think.
My investigations did include a putlog [chanlist $channel] and far too many .tcl putlog's from the bot, like this:
Code: Select all
.rehash
<snip>
.tcl putlog [chanlist #___]
[14:16] NoTopic JamesOff MonicaOff KipAway
.tcl putlog [chanlist #___b]
<nothing>
.channel #___
<snip>
.tcl putlog [chanlist #___ b]
[14:18] NoTopic MonicaOff
The problem is DEFINITELY .rehash screwing up the internal list chanlist uses
