#by wiebe @ QuakeNet



#help addchan msg
bind msgm mn "help addchan" c_addchan:help:msg

proc c_addchan:help:msg { nick uhost handle text } {
  lappend output "Usage: addchan <channel> \[<settings>\]"
  lappend output "Adds a channel to the bot with the settings specified, default is +inactive."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#addchan msg
bind msg mn addchan c_addchan:msg

proc c_addchan:msg { nick uhost handle text } {
  set chan [lindex [split $text] 0]
  set options [join [lrange [split $text] 1 end]]
  if { [string equal $options ""] } {
    set options +inactive
  } elseif { [string equal [lsearch $options -inactive] -1] } {
    set options "+inactive $options"
  }
  if { [string equal $chan ""] } {
    lappend output "Usage: addchan <channel> \[<settings>\]"
  } elseif { [validchan $chan] } {
    lappend output "Already exists $chan"
  } elseif { [catch {channel add $chan $options} error] } {
    if { [validchan $chan] } {
      lappend output "Added channel $chan ($options)."
      lappend output "Error applying settings ([join $error])."
    } else {
      lappend output "Error adding channel $chan ([join $error ;])."
    }
  } else {
    lappend output "Added channel $chan ($options)."  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}

