#by wiebe @ QuakeNet



#help hello msg
bind msgm fvlomn|fvlomn "help hello" c_hello:help:msg

proc c_hello:help:msg { nick uhost handle text } {
  lappend output "Usage: hello \[<nick>\]"
  lappend output "Sends you or the given nick introduction to this bot, only a global master or owner can specify a nick."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#hello msg
bind msg fvlomn|fvlomn hello c_hello:msg

proc c_hello:msg { nick uhost handle text } {
  set target [lindex [split $text] 0]
  if { [string equal $target ""] || [string equal -nocase $target $nick] } {
    lappend output "Hello $nick, I am ${::botnet-nick} and you are known to me as $handle."
    if { [string equal [getuser $handle pass] ""] } {
      lappend output "You have not set a password, please do so now: '/msg $::botnick newpass'"
    }
    lappend output "There are several commands available on this bot, depending on your access."
    lappend output "For public commands: write in the channel '${::botnet-nick} help' - or '/msg $::botnick help <channel>'"
    lappend output "For private commands: '/msg $::botnick help'"
    lappend output "Note: commands available in public and in private differ."
    lappend output "The help function explains each command. For more info '/msg $::botnick help help'"
  } elseif { ![matchattr $handle mn] } {
    lappend output "You are not a global master or owner and can not use this command for other users."
  } elseif { ![onchan $target] } {
    lappend output "User $target is not on any of my channels."
  } elseif { [string equal [nick2hand $target] *] } {
    lappend output "User $target is not known."
  } elseif { [matchattr [nick2hand $target] b] } {
    lappend output "User $target is known as [nick2hand $target], but is a bot."
  } elseif { ![c_hello:check [nick2hand $target]] } {
    lappend output "User $target is known as [nick2hand $target], but does not have any of fvlomn flags anywhere."
  } else {
    lappend output2 "Hello $target, I am ${::botnet-nick} and you are known to me as [nick2hand $target]."
    if { [string equal [getuser [nick2hand $target] pass] ""] } {
      lappend output2 "You have not set a password, please do so now: '/msg $::botnick newpass'"
    }
    lappend output2 "There are several commands available on this bot, depending on your access."
    lappend output2 "For public commands: write in the channel '${::botnet-nick} help' - or '/msg $::botnick help <channel>'"
    lappend output2 "For private commands: '/msg $::botnick help'"
    lappend output2 "Note: commands available in public and in private differ."
    lappend output2 "The help function explains each command. For more info '/msg $::botnick help help'"
    lappend output "Sending introduction to $target ([nick2hand $target])"
    if { [catch {set x [cnotice $target $output2]} error] || !$x } {
      foreach t $output2 { puthelp "NOTICE $target :$t" }
    }
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}



#check flags, returns 1 if the user has flags fvlomn anywhere, 0 if not
proc c_hello:check { handle } {
  if { ![validuser $handle] } { return 0 }
  if { [matchattr $handle fvlomn] } { return 1 }
  foreach chan [channels] { if { [matchattr $handle fvlomn|fvlomn $chan] } { return 1 } }
  return 1
}

