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.

combining if text

Help for those learning Tcl or writing their own scripts.
Post Reply
g
gembels
Voice
Posts: 26
Joined: Sat Jul 07, 2012 9:31 pm

combining if text

Post by gembels »

hi,

How to make

if ($text = *.id) { echo x } else { echo z }; in tcl ?

everyting they do !whois domain.id go to first x and else goto z

thanks
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

In tcl, that would be something along these lines:

Code: Select all

if {test} {
  code if test is TRUE
} {
  code if test is FALSE
}
In order to do string comparisons, the simplest approach would be to use the string command with the match option:

Code: Select all

string match "*.id" $text
In order to evaluate and test the string match command, we need to use command substitutions, which is done using brackets [ ]

Code: Select all

if {[string match "*.id" $text]} {
  ...
} {
  ...
}
Printing text to stdout is done using the puts command, though that won't make much sense with eggdrops. In order to send text to the irc server, you can use the puthelp and putserv commands; if you'd rather like to log the message, use putlog for that:

Code: Select all

if {[string match "*.id" $text]} {
  puthelp "PRIVMSG #Somechannel :The string \"${text}\" matches!"
} {
  putlog "The string \"${text}\" does not match the test!"
}
Next, in order to use this with a public trigger, we need a binding, and place the above code in a proc:

Code: Select all

bind pub !whois - pubWhois

proc pubWhois {nick host handle channel text} {
  if {[string match "*.id" $text]} {
    puthelp "PRIVMSG #Somechannel :The string \"${text}\" matches!"
  } {
    putlog "The string \"${text}\" does not match the test!"
  }
}
NML_375
Post Reply