#by wiebe @ QuakeNet



#help delchan msg
bind msgm mn "help delchan" c_delchan:help:msg

proc c_delchan:help:msg { nick uhost handle text } {
  lappend output "Usage: delchan <channel>"
  lappend output "Removes a channel from the bot."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#delchan msg
bind msg mn delchan c_delchan:msg

proc c_delchan:msg { nick uhost handle text } {
  set chan [lindex [split $text] 0]
  set param [lindex [split $text] 1]
  set md5 [string range [md5 "$nick!$uhost $handle [string tolower $chan]"] 0 9]
  if { [string equal $chan ""] } {
    lappend output "Usage: delchan <channel>"
  } elseif { ![validchan $chan] } {
    lappend output "Invalid channel $chan"
  } elseif { ![string equal $param $md5] } {
    if { [channel get $chan inactive] } {
      lappend output "Channel $chan\017 is already set +inactive. If you want to really remove it, use /msg $::botnick delchan $chan $md5"
    } else {
      channel set $chan +inactive
      lappend output "Channel $chan\017 set +inactive. If you want to really remove it, use /msg $::botnick delchan $chan $md5"
    }
  } elseif { [catch {channel remove $chan} error] } {
    if { [validchan $chan] } {
      lappend output "Error removing channel $chan ([join $error])."
    } else {
      lappend output "Removed channel $chan from the bot ([join $error])."
    }
  } else {
    lappend output "Removed channel $chan from the bot."  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}

