I am using a channel join/kick counter in a bot I have loaned and the script is having dramas with the channel name. I've tried a few things and still cannot resolve the problem.
Code: Select all
proc dcounter_join {nick host hand chan} {
global dcounter
set chan [string tolower $chan] ; set counter 0
if {[isvalidchan $chan] == 1} {return 0}
if {[isbotnick $nick] || [matchattr $hand b]} {return}
set fx [open $dcounter(joinfile) r] ; set fx2 [open $dcounter(tmpfile) w]
while {![eof $fx]} {
set tmp [gets $fx]
if {$tmp != ""} {
if {[lindex $tmp 0] == "$chan"} {set counter [expr [lindex $tmp 1] +1] ; puts $fx2 "$chan $counter"} else {puts $fx2 $tmp}
}
}
if {$counter == 0} {set counter 1 ; puts $fx2 "$chan $counter"}
close $fx ; close $fx2
exec rm -f $dcounter(joinfile) ; exec mv $dcounter(tmpfile) $dcounter(joinfile)
if {$dcounter(njoin) == 1} {puthelp "NOTICE $nick :Vous êtes la [convert $counter] personne à joindre $chan."}
return 0
}
proc dcounter_kick {nick host hand chan target reason} {
global dcounter
set chan [string tolower $chan] ; set counter 0
if {[isvalidchan $chan] == 1} {return 0}
set fx [open $dcounter(kickfile) r] ; set fx2 [open $dcounter(tmpfile) w]
while {![eof $fx]} {
set tmp [gets $fx]
if {$tmp != ""} {
if {[lindex $tmp 0] == "$chan"} {set counter [expr [lindex $tmp 1] +1] ; puts $fx2 "$chan $counter"} else {puts $fx2 $tmp}
}
}
if {$counter == 0} {set counter 1 ; puts $fx2 "$chan $counter"}
close $fx ; close $fx2
exec rm -f $dcounter(kickfile) ; exec mv $dcounter(tmpfile) $dcounter(kickfile)
if {$dcounter(nkick) == 1} {puthelp "NOTICE $target :Vous êtes la [convert $counter] personne kicker de $chan"}
if {$dcounter(nonotice) == 1} {puthelp "NOTICE @$chan :$target est la [convert $counter] personne à être kicker de $chan"}
return 0
}
proc dcounter_see {nick host hand chan text} {
global dcounter
set chan [string tolower $chan] ; set joins 0 ; set kicks 0
if {[isvalidchan $chan] == 1} {puthelp "NOTICE $nick :I don't save join/kick stats for this channel" ; return 0}
set fx1 [open $dcounter(joinfile) r] ; set fx2 [open $dcounter(kickfile) r]
while {![eof $fx1]} {
set tmp [gets $fx1]
if {$chan == "[lindex $tmp 0]"} {set joins [lindex $tmp 1] ; break}
}
while {![eof $fx2]} {
set tmp [gets $fx2]
if {$chan == "[lindex $tmp 0]"} {set kicks [lindex $tmp 1] ; break}
}
puthelp "NOTICE $nick :$chan have $joins joins and $kicks kicks"
return 0
}
The problem is the saved join/kick data files have never ending lines of #x? 1 (in this particular case).
Except for channels with unusual characters in their name this script works perfectly for any channel a bot is in.
Any assistance will be greatly appreciated.
*Edited*