Hi, this script is working fine but when caps are in the middle of the text, then it doesn't work, but if text starts with caps its works fine
like
hmmmm HELLOOOOO HOW ARE YOU (doesn't work)
but
HELLOOOOO HOW ARE YOU (worked)
i think it counts spaces too, i will appreciate if someone can help me to fix this
proc check_caps {text} {
set i [string length $text]
set caps 0.0
for {set x 0} {$x<$i} {incr x} {
set cc [string index $text $x]
if {[string match {[A-Z]} $cc]} {set caps [expr $caps+1]}
if {[string match " " $cc]} {incr i -1}
}
return [list [expr int($caps/$i*100)]]
}
proc caps_test {nick user hand chan text} {
global channel bantime botnick
set stati [chattr $hand]
set pperc [check_caps $text]
set perc [lindex $pperc 0]
if {$perc>65 && [string length $text]>15} {
The reason "hmmmm HELLOOOOO HOW ARE YOU" isn't working is that it's reading it as 65% caps and the script's caps threshold is 65%. It has nothing to do with having caps in the middle of the text.
If you want it to be stricter, reduce the 65 to something like 30.
I don't understand what you wanted to do about spaces.
The only real programming error is the "incr i -1". It should use a different variable, because that is making it not read in the last few chars of the string, and the caps percent gets messed up (too low).
Just a note, even though it pretty much works, that's some really ugly code heh. I'd rewrite it if I were you.
Yeah, rewrite the code, it looks awfull :/
Regular expressions are a perfect thing to use in such cases:
regexp -all \[A-Z\] $text
will return the number of uppercase letters in variable $text.
Ignorant and lazy people will save 30 minutes by chosing simple config file. Smart ones will save 3000 minutes of *everyone's* time by opting for complete config file.