egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HELP! Bind pubm + match two variables !

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
cleaner
Voice


Joined: 13 Apr 2009
Posts: 15

PostPosted: Wed Apr 29, 2009 10:56 am    Post subject: HELP! Bind pubm + match two variables ! Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 29, 2009 11:33 am    Post subject: Reply with quote

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
View user's profile Send private message
cleaner
Voice


Joined: 13 Apr 2009
Posts: 15

PostPosted: Wed Apr 29, 2009 1:16 pm    Post subject: Reply with quote

nml375,

Thanks for answer and helping.

This 2nd thing:

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

and also
Code:
worddd1


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? Wink
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 29, 2009 1:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
cleaner
Voice


Joined: 13 Apr 2009
Posts: 15

PostPosted: Wed Apr 29, 2009 2:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Apr 29, 2009 2:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cleaner
Voice


Joined: 13 Apr 2009
Posts: 15

PostPosted: Wed Apr 29, 2009 5:40 pm    Post subject: Reply with quote

Thanks for explain Smile.

You guys are very helpfull!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber