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

####################################################
# moo:help:pubm
####################################################
bind pubm fvlomn|fvlomn "% ${botnet-nick} help moo" moo:help:pubm
proc moo:help:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "moo: usage moo \[<chan>\] <nick>"
  lappend o "moo:moos at nick"
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "moo: " } }
  putloglev c $c "help: $n $u $h $c moo"
  return 1
}


####################################################
# moo:help:msg
####################################################
bind msgm fvlomn|fvlomn "help moo" moo:help:msgm
proc moo:help:msgm { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "moo: usage moo <chan> <nick>"
  lappend o "moo: moos at nick"
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "moo: " } }
  putcmdlog "($n!$u) !$h! help moo"
  return 1
}


####################################################
# moo:pub
####################################################
bind pubm fvlomn|fvlomn "% ${botnet-nick} moo" moo:pubm
bind pubm fvlomn|fvlomn "% ${botnet-nick} moo *" moo:pubm
proc moo:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  set t [join [lrange [split $t] 2 end]]
  if {[string equal $t ""]} { lappend o "moo: usage moo \[<chan>\] <nick>"
  } else { set o [moo:moo $h $t $c $n] }
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "moo: " } }
  putloglev c $c "moo: $n $u $h $c $t"
  return 1
}


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


####################################################
# moo:dcc
####################################################
bind dcc -|- moo moo:dcc
proc moo:dcc { h i t } {
  if {![valididx $i]} { return 0 }
  set c [lindex [split [console $i]] 0]
  if {![validchan $c]} { set c "" }
  if {[string equal $t ""]} {
    lappend o "moo: usage moo \[<chan>\] <nick>"
    lappend o "moo: moos at nick"
  } else { set o [moo:moo $h $t $c] }
  foreach l $o { putidx $i $l }
  return 1
}


####################################################
# moo:moo
####################################################
proc moo:moo { h t {c ""} {n ""} } {
  set t [split $t]; set d [lindex $t 0]; set m ""; set o ""
  if {[string equal $c ""] || [string match {[#&]*} $d]} {
    set c $d; set t [join [lrange $t 1 end]]
  }
  if {![validchan $c] && ![string equal [info procs whichchan] ""]} { set c [whichchan $h $c] }
  set t [string trimright [join $t] " "]
  if {[validchan $c]} { set m [lindex [split [getchanmode $c]] 0] }
  if {[string equal $c ""] || [string equal $t ""]} {
    lappend o "moo: usage moo \[<chan>\] <nick>"
  } elseif {![validchan $c] || ![matchattr $h fvlomn|fvlomn $c]} {
    lappend o "moo: no access or unknown channel $c"
  } elseif {![botonchan $c]} {
    lappend o "moo: I am not on $c"
  } elseif {[string match *m* $m] && ![botisop $c] && ![botishalfop $c] && ![botisvoice $c]} {
    lappend o "moo: channel $c is moderated"
  } else {
    set a "moos loudly at $t"
    if {[string equal $n ""] || ![onchan $n $c] || [onchansplit $n $c]} {
      lappend o "moo: moo'ed '$t\017' on $c"
    }
    if {[string match *c* $m] } { set a [stripcodes bcru $a] }
    if {[string equal [info procs action] ""]} { puthelp "PRIVMSG $c :\001ACTION$a\001"
    } else { action $c $a puthelp "" }
  }
  return $o
}


set scriptdb(moo) {
  "provides moo command to moo at users"
}

