#by wiebe @ QuakeNet



#help whoami msg
bind msgm fvlomn|fvlomn "help whoami" c_whoami:help:msg

proc c_whoami:help:msg { nick uhost handle text } {
  lappend output "Usage: whoami"
  lappend output "Shows your account name, global access level, channel list and the date/time you last joined."
  lappend output "Where \002a\002=auto-op \002b\002=bot \002d\002=deny-op \002f\002=friend \002g\002=auto-voice \002k\002=auto-kickban \002l\002=halfop \002m\002=master \002n\002=owner \002o\002=op \002p\002=party-line \002q\002=deny-voice \002r\002=deny-halfop \002u\002=unshared \002v\002=voice \002y\002=auto-halfop"
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#whoami msg
bind msg fvlomn|fvlomn whoami c_whoami:msg

proc c_whoami:msg { nick uhost handle text } {
  lappend output "You are $handle and known on the following channels:"
  set flags [chattr $handle]
  set result 0
  if { ![string equal $flags -] } { lappend output "You have global flags: $flags" }
  foreach chan [lsort [channels]] {
    if { [haschanrec $handle $chan] } {
      set flags [lindex [split [chattr $handle $chan] |] 1]
      if { ![string equal $flags -] } {
        set space1 [string repeat " " [expr 30 - [string length $chan]]]
        set laston [getuser $handle LASTON $chan]
        if { [string equal $laston 0] } { set laston "" }
        set lastondate ""
        if { ![string equal $laston ""] } { set lastondate [clock format $laston -format %d/%m/%y] }
        set date [clock format [unixtime] -format %d/%m/%y]
        if { [string equal $lastondate $date] } {
          set laston [clock format $laston -format %H:%M]
        } elseif { ![string equal $laston ""] } {
          set laston [clock format $laston -format %d/%m/%y]
        } else {
          set laston never
        }
        set space2 [string repeat " " [expr 15 - [string length $flags]]]
        set result 1
        lappend output "$chan$space1$flags$space2$laston"
      } else { delchanrec $handle $chan }
    }
  }
  if { !$result } {
    lappend output "You are not known on any channels."
  } else {
    lappend output "End of list."
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}

