| View previous topic :: View next topic |
| Author |
Message |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Wed Apr 29, 2009 10:56 am Post subject: HELP! Bind pubm + match two variables ! |
|
|
Hello!
I have problem with script. I dont know what is better, something like this:
1)
| Code: |
bind pubm -|- * pub_do_ok1
bind pubm -|- * pub_do_ok2
proc pub_do_ok1 {nick uhost hand channel txt} {
global botnick
if {[string match "$botnick*ok1*" [string trim $txt]]} {
putserv "PRIVMSG $channel :ok1"
}
}
proc pub_do_ok2 {nick uhost hand channel txt} {
global botnick
if {[string match "$botnick*ok2*" [string trim $txt]]} {
putserv "PRIVMSG $channel :ok2"
}
}
|
or this:
2)
| Code: |
bind pubm -|- * *
proc pub_do_ok1 {nick uhost hand channel txt} {
global botnick
if {[string match "$botnick*ok1*" [string trim $txt]]} {
putserv "PRIVMSG $channel :ok1"
}
}
proc pub_do_ok2 {nick uhost hand channel txt} {
global botnick
if {[string match "$botnick*ok2*" [string trim $txt]]} {
putserv "PRIVMSG $channel :ok2"
}
}
|
What is ok? 1 / 2?
--------
Also please tell me how to match string with two variables?
I want answer for: xxx, yyy
This isnt working:
| Code: | proc pub_do_answer {nick uhost hand channel txt} {
global botnick
if {[string match (xxx|yyy) [string trim $txt]]} {
putserv "PRIVMSG $channel :entered ok"
}
} |
Thanks in advance!
//EDIT:
Is this ok?
| Code: | proc pub_do_answer {nick uhost hand channel txt} {
global botnick
if {[regexp (xxx|yyy) [string trim $txt]]} {
putserv "PRIVMSG $channel :entered ok"
}
} |
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Apr 29, 2009 11:33 am Post subject: |
|
|
Neither is good/better... Use this instead:
| Code: | bind pubm - * pubm_do_ok
proc pubm_do_ok {nick host handle channel text} {
if {[string match "${::botnick}*ok1*" [string trim $text]]} {
puthelp "PRIVMSG $channel :ok1"
} elseif {[string match "${::botnick}*ok2*" [string trim $text]]} {
puthelp "PRIVMSG $channel :ok2"
}
} |
I'm not sure what you're asking for with "match string with two variables". Think you could elaborate this a little? _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Wed Apr 29, 2009 1:16 pm Post subject: |
|
|
nml375,
Thanks for answer and helping.
This 2nd thing:
I mean that, when I write in channel:
ex:
and also
Bot will do same command.
I was trying to fix exec, but i think i have got it:
| Code: | proc pub_do_xyz {nick uhost hand channel txt} {
global ident
if {[regexp {(.*word1.*|.*worddd1.*)} [string trim $txt]]} {
putserv "PRIVMSG $channel :$nick: Something to say"
}
} |
Then I can write: ddsadaword1czczdsa - and its ok.
And also: dskjfslworddd1dasdjaks.
I am right?  |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Apr 29, 2009 1:41 pm Post subject: |
|
|
Your regular expression could probably be cleaned up alittle..
But as I understand you, your second issue seems identical to the first one?
If either word1 or word2 is within the string, trigger?
Edit:
Sorry, was thinking off track there...
either use a regexp, or something as simple as this:
| Code: | ...
if {[string match "*word1*" $text] || [string match "*word2*" $text]} {
... |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Wed Apr 29, 2009 2:06 pm Post subject: |
|
|
Last question,
What will be better?
My regexp or your string match?
||
\/
| Code: | ...
if {[string match "*word1*" $text] || [string match "*word2*" $text]} {
... | [/quote] |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Apr 29, 2009 2:25 pm Post subject: |
|
|
It's not a matter of which is "better" in this case but rather which is faster. [string match] in most cases works faster than [regexp]. In your case, there's no need to use regexp since you're not using it for complex matching (which would be more difficult to implement using other matching methods). _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
cleaner Voice
Joined: 13 Apr 2009 Posts: 15
|
Posted: Wed Apr 29, 2009 5:40 pm Post subject: |
|
|
Thanks for explain .
You guys are very helpfull! |
|
| Back to top |
|
 |
|