#by wiebe @ QuakeNet



#help pet pub
bind pubm fvlomn|fvlomn "% ${botnet-nick} help pet" c_pet:help:pub

proc c_pet:help:pub { nick uhost handle chan text } {
  c_pet:pub $nick $uhost $handle $chan ""
  putloglev c $chan "[lindex [split $text] 1]: $nick $uhost $handle $chan [join [lrange [split $text] 2 end]]"
}



#help pet msg
bind msgm fvlomn|fvlomn "help pet" c_pet:help:msg

proc c_pet:help:msg { nick uhost handle text } {
  c_pet:msg $nick $uhost $handle ""
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#pet pub
bind pubm fvlomn|fvlomn "% ${botnet-nick} pet" c_pet:pub
bind pubm fvlomn|fvlomn "% ${botnet-nick} pet *" c_pet:pub

proc c_pet:pub { nick uhost handle chan text } {
  set target [join [lrange [split $text] 2 end]]
  if { ![string equal $target ""] } {
    puthelp "PRIVMSG $chan :\001ACTION pets $target\001"
    lappend output "Petted $target on $chan"
  } else {
    lappend output "Usage: pet <nick>"
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putloglev c $chan "[lindex [split $text] 1]: $nick $uhost $handle $chan [join [lrange [split $text] 2 end]]"
}



#pet msg
bind msg fvlomn|fvlomn pet c_pet:msg

proc c_pet:msg { nick uhost handle text } {
  set chan [lindex [split $text] 0]
  set target [join [lrange [split $text] 1 end]]
  if { ![validchan $chan] && ![string equal $chan ""] } {
    lappend output "No access or unknown channel $chan"
  } elseif { [string equal $chan ""] || [string equal $target ""] } {
    lappend output "Usage: pet <channel> <nick>"
  } elseif { ![matchattr $handle fvlomn|fvlomn $chan] } {
    lappend output "No access or unknown channel $chan"
  } elseif { ![botonchan $chan] } {
    lappend output "I am not on channel $chan"
  } else {
    puthelp "PRIVMSG $chan :\001ACTION pets $target\001"
    lappend output "Petted $target on $chan"  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}

