#Chapter 8.7 Example Script v1.2 by _SunMar_.
#This script is part of the TCL Guide by Marijn van Zon
#which can be found on http://www.suninet.nl/.

#Objective: write a script that voices everyone who joins one
#of the two channels which are set in the beginning of the
#script in the same list and says "Welcome $nick!" in every
#channel, plus a different greeting for 2 nicks which can
#support 2 lines.

#Set the auto-voice channels here.
set channels "#eggdrop #tcl"

#Set the greeting nicks here in the form of "<nickname>|<first line>|[second line]".
set greeting(one) "_SunMar_|Oh my God, _SunMar_ has returned!"
set greeting(two) "_SunAway_|You are joining a channel while you are away?!|That's weird."

#The script

#This is to make it an "official" list
set channels [split $channels]

#This is to make it an "official" list and put the nick and
#the two lines of the greeting in their own objects.
set greeting(one) [split $greeting(one) |]
set greeting(two) [split $greeting(two) |]

bind join - * join:voice_and_greet
proc join:voice_and_greet { nick host hand chan } {
  global channels greeting
  if {$chan == [lindex $channels 0] || $chan == [lindex $channels 1]} {
    pushmode $chan +v $nick
  }
  if {$nick == [lindex $greeting(one) 0]} {
    puthelp "PRIVMSG $chan :[lindex $greeting(one) 1]"
    if {[lindex $greeting(one) 2] != ""} {
      puthelp "PRIVMSG $chan :[lindex $greeting(one) 2]"
    }
  } elseif {$nick == [lindex $greeting(two) 0]} {
    puthelp "PRIVMSG $chan :[lindex $greeting(two) 1]"
    if {[lindex $greeting(two) 2] != ""} {
      puthelp "PRIVMSG $chan :[lindex $greeting(two) 2]"
    }
  } else {
    puthelp "PRIVMSG $chan :Welcome $nick!"
  }
  return 0
}

