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.

Pub string match - simple command, silly problem.

Help for those learning Tcl or writing their own scripts.
Post Reply
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Pub string match - simple command, silly problem.

Post by cleaner »

Hello,

Can anybody help me fix it ?

I don't know what is wrong with this...

I mean that good function "!xxx ccc" show 2 responses:

Code: Select all

15:14:45 <A>  good
15:14:46 <A>  bad
The: "!xxx ccc", as only to show: "good".

Code: Select all

bind pub -|- !xxx pub_do_ccc

proc pub_do_ccc {nick host handle channel text} {


if {[string match -nocase "ccc" [string trim $text]]} {
	putserv "PRIVMSG $channel : good"
}elseif {[string match -nocase "ccc1" [string trim $text]]} {
	putserv "PRIVMSG $channel : good1"
}elseif {[string match -nocase "ccc2" [string trim $text]]} {
	putserv "PRIVMSG $channel : good2"
}
   putserv "PRIVMSG $channel : bad" 

}
t
tsukeh
Voice
Posts: 31
Joined: Thu Jan 20, 2005 6:22 am

Post by tsukeh »

Code: Select all

bind pub -|- !xxx pub_do_ccc

proc pub_do_ccc {nick host handle channel text} {
 set text [string trim $text]
 if {[string match -nocase "ccc" $text]} {
   putserv "PRIVMSG $channel : good"
 } elseif {[string match -nocase "ccc1" $text]} {
   putserv "PRIVMSG $channel : good1"
 } elseif {[string match -nocase "ccc2" $text]} {
   putserv "PRIVMSG $channel : good2"
 } else {
   putserv "PRIVMSG $channel : bad"
 }
}
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Post by cleaner »

Thanks :)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind pub -|- !xxx pub_do_ccc

proc pub_do_ccc {nick host handle channel text} {
  switch -- [string tolower [string trim $text]] {
    "ccc" { putserv "PRIVMSG $channel :good" }
    "ccc1" { putserv "PRIVMSG $channel :good1" }
    "ccc2" { putserv "PRIVMSG $channel :good2" }
    default { putserv "PRIVMSG $channel :bad" }
  }
}
There are many ways to accomplish this, but the faster method is usually preferred. The command "switch" is probably faster than nesting if's and else's in this case.
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Post by cleaner »

Thanks, I think that I most rewrite some scripts hehe :).
Post Reply