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.

HELP! Bind pubm + match two variables !

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

HELP! Bind pubm + match two variables !

Post by cleaner »

Hello!

I have problem with script. I dont know what is better, something like this:

1)

Code: Select all

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: Select all

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: Select all

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: Select all

proc pub_do_answer {nick uhost hand channel txt} {
  global botnick
  if {[regexp (xxx|yyy) [string trim $txt]]} {
	putserv "PRIVMSG $channel :entered ok"
  }
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Neither is good/better... Use this instead:

Code: Select all

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
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Post by cleaner »

nml375,

Thanks for answer and helping.

This 2nd thing:

I mean that, when I write in channel:
ex:

Code: Select all

word1
and also

Code: Select all

worddd1
Bot will do same command.

I was trying to fix exec, but i think i have got it:

Code: Select all

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? ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

...
if {[string match "*word1*" $text] || [string match "*word2*" $text]} {
...
NML_375
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Post by cleaner »

Last question,

What will be better?

My regexp or your string match?

||
\/

Code: Select all

...
if {[string match "*word1*" $text] || [string match "*word2*" $text]} {
...
[/quote]
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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).
c
cleaner
Voice
Posts: 15
Joined: Mon Apr 13, 2009 6:35 pm

Post by cleaner »

Thanks for explain :).

You guys are very helpfull!
Post Reply