# whois.tcl (23/03/05)
#
# Credits: http://www.scriptkitties.com/
#          DaNumber8-WhoStuffHandler
#
# Directs /WHOIS output to the current tab/window.
# Format is a lot more readable.
#
# Installation: Copy the file into your xchat data folder.
#               Windows XP: C:\Documents and Settings\<user name>\Application Data\X-Chat 2
#               Linux     : <account name>/.xchat2
# To load: /reload
#
# Enhancements/Additions: Alchera (ballarat at ballarat dot us)
#

# RPL_AWAY
on 301 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold][color 4]      AWAY[reset]: [string trim [join [lrange $whodata 1 end]] ":"]"
  complete EAT_ALL
}

# RPL_WHOISREGNICK
on 307 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold][color 4]REGISTERED[reset]: This is a registered nick."
  complete EAT_ALL
}

# RPL_WHOISHELPOP
on 310 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold][color 4]    HelpOP[reset]: [lindex $whodata 0] is available for help."
  complete EAT_ALL
}

# RPL_WHOISUSER
on 311 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold]=============== [lindex $whodata 0] whois response ===============[reset]"
  print "---\t[bold]  RealName[reset]: [string range [lrange $whodata 4 end] 1 end]"
  print "---\t[bold]      User[reset]: [lindex $whodata 1]"
  print "---\t[bold]ServerHost[reset]: [lindex $whodata 2]"
  complete EAT_ALL
}

# RPL_WHOISSERVER
on 312 mywhois {
	set whodata [split $_rest " "]
	print "---\t[bold]    Server[reset]: [lindex $whodata 1]"
  complete EAT_ALL
}

# RPL_WHOISOPERATOR
on 313 mywhois {
	set whodata [split $_rest " "]
	print "---\t[bold][color 4]     IrcOP[reset]: [lindex $whodata 0] [string trim [lrange $whodata 1 end] :]"
  complete EAT_ALL
}
# RPL_WHOISIDLE
on 317 mywhois {
  set whodata [split $_rest " "]
  set idle [clock format [expr 25200+[lindex $whodata 1]] -format "%T"]
  print "---\t[bold]      Idle\[reset]: $idle, [bold]Signon[reset]: [clock format [lindex $whodata 2] -format "%a, %b %d %T"]"
  complete EAT_ALL
}

# RPL_ENDOFWHOIS
on 318 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold]=============== [lindex $whodata 0]      whois end ===============[reset]"
  complete EAT_ALL
}

# RPL_WHOISCHANNELS
on 319 mywhois {
  set whodata [split [string trim $_rest] " "]
  print "---\t[bold]Channel\(s\)[reset]: [string range [lrange $whodata 1 end] 1 end]"
  complete EAT_ALL
}

# RPL_WHOISSPECIAL
on 320 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold]            [lindex $whodata 0] [string range [lrange $whodata 1 end] 1 end]"
  complete EAT_ALL
}

# RPL_WHOISBOT
on 335 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold][color 4]       BOT\017: [string range [lrange $whodata 1 end] 1 end]"
  complete EAT_ALL
}

# RPL_WHOISHOST
on 378 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold]  RealHOST[reset]: [lindex $whodata 0] is connecting from [host]"
  complete EAT_ALL
}

# ERR_NOSUCHNICK 
on 401 mywhois {
  set whodata [split $_rest " "]
  print "---\t[bold][color 4]ERROR[reset]: [lindex $whodata 0][lrange $whodata 1 end]"
  complete EAT_ALL
}

proc color { {arg {}} } {
  return "\003$arg"
}

proc bold { } {
  return "\002"
}

proc reset { } {
  return "\017"
}

