####################################################
# by wiebe @ QuakeNet
#
####################################################


####################################################
# whoami:help:msg
####################################################
bind msgm fvlomn|fvlomn "help whoami" whoami:help:msgm
proc whoami:help:msgm { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "whoami: usage whoami"
  lappend o "whoami: shows your account name, global access level, channel list and the date/time you last joined."
  lappend o "whois: where   a=auto-op   b=bot   d=deny-op   f=friend   g=auto-voice   k=auto-ban   l=halfop   m=master   n=owner   o=op   p=party-line   q=deny-voice   r=deny-halfop   u=unshared   v=voice   y=auto-halfop"
  if {![string equal [info procs userflag:get] ""]} {
    set r [userflag:get]; if {![string equal $r ""]} { lappend o "whoami: $r" }
  }
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "whoami: " } }
  putcmdlog "($n!$u) !$h! help whoami"
  return 1
}


####################################################
# whoami:msg
####################################################
bind msg fvlomn|fvlomn whoami whoami:msg
proc whoami:msg { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  set o [whoami:whoami $h]
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "whoami: " } }
  return 1
}


####################################################
# whoami:dcc
####################################################
bind dcc -|- whoami2 whoami:dcc
proc whoami:dcc { h i t } {
  set o [whoami:whoami $h]
  lappend o "whoami: where   a=auto-op   b=bot   d=deny-op   f=friend   g=auto-voice   k=auto-ban   l=halfop   m=master   n=owner   o=op   p=party-line   q=deny-voice   r=deny-halfop   u=unshared   v=voice   y=auto-halfop"
  if {![string equal [info procs userflag:get] ""]} {
    set r [userflag:get]; if {![string equal $r ""]} { lappend o "whoami: $r" }
  }
  foreach l $o { putidx $i $l }
  return 1
}


####################################################
# whoami:whoami
####################################################
proc whoami:whoami { h } {
  lappend o "whoami: you are $h and known on the following channels:"
  set f [chattr $h]; set r 0; set c "global flags"
  set x [string repeat " " [expr 30 - [string length $c]]]
  if {![string equal $f "-"]} { lappend o "$c$x$f"  }
  foreach c [channels] {
    if {![haschanrec $h $c]} { continue }
    set f [lindex [split [chattr $h $c] |] 1]
    if {[string equal $f "-"]} { delchanrec $h $c; continue }
    set x [string repeat " " [expr 30 - [string length $c]]]
    set y [string repeat " " [expr 15 - [string length $f]]]
    set l [getuser $h LASTON $c]; set k ""; set r 1
    if {[string equal $l 0]} { set l "" }
    if {![string equal $l ""]} { set k [clock format $l -format %d/%m/%y] }
    set d [clock format [clock seconds] -format %d/%m/%y]
    if {[handonchan $h $c]} { set l now
    } elseif {[string equal $k $d]} { set l [clock format $l -format %H:%M]
    } elseif {![string equal $l ""]} { set l [clock format $l -format %d/%m/%y]
    } else { set l never }
    lappend o "$c$x$f$y$l"
  }
  if {!$r} { lappend o "whoami: you are not known on any channels."
  } else { lappend o "whoami: end of list." }
  return $o
}


set scriptdb(whoami) {
  "provides whoami command"
}

