| View previous topic :: View next topic |
| Author |
Message |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Thu Apr 30, 2009 9:20 am Post subject: Pub string match - simple command, silly problem. |
|
|
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: | 15:14:45 <A> good
15:14:46 <A> bad |
The: "!xxx ccc", as only to show: "good".
| Code: |
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"
} |
|
|
| Back to top |
|
 |
tsukeh Voice
Joined: 20 Jan 2005 Posts: 31
|
Posted: Thu Apr 30, 2009 9:48 am Post subject: |
|
|
| Code: |
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"
}
}
|
|
|
| Back to top |
|
 |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Thu Apr 30, 2009 10:05 am Post subject: |
|
|
Thanks  |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu Apr 30, 2009 5:36 pm Post subject: |
|
|
| Code: | 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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Fri May 01, 2009 11:15 am Post subject: |
|
|
Thanks, I think that I most rewrite some scripts hehe . |
|
| Back to top |
|
 |
|