This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

caps help

Old posts that have not been replied to for several years.
Locked
A
AW

caps help

Post by AW »

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} {

.....kick stuff...

thanks
regards
Aw
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

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.
d
darko``
Op
Posts: 121
Joined: Sun Sep 08, 2002 5:33 pm
Location: Malta

Post by darko`` »

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.
Locked