#by wiebe @ QuakeNet
#provides rule commands and 'reason' proc



#help rule pub
bind pubm lomn|lomn "% ${botnet-nick} help rule" c_rule:help:pub

proc c_rule:help:pub { nick uhost handle chan text } {
  lappend output "Usage: rule show|all|<rule1> \[<rule2|> .. <ruleN>\]"
  lappend output "'show' displays all short rules defined, these can be used in warn/kick/ban commands, 'all' lists all full rules. Specify #<number> (#1 #2 #3) as reason or the short word (adv amsg away) as shown in 'show'."
  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]]"
}



#help rule msg
bind msgm lomn|lomn "help rule" c_rule:help:msg

proc c_rule:help:msg { nick uhost handle text } {
  lappend output "Usage: rule show|all|<rule1> \[<rule2|> .. <ruleN>\]"
  lappend output "'show' displays all short rules defined, these can be used in warn/kick/ban commands, 'all' lists all full rules. Specify #<number> (#1 #2 #3) as reason or the short word (adv amsg away) as shown in 'show'."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#rule pub
bind pubm lomn|lomn "% ${botnet-nick} rule" c_rule:pub
bind pubm lomn|lomn "% ${botnet-nick} rule *" c_rule:pub

proc c_rule:pub { nick uhost handle chan text } {
  set rules [join [lrange [split $text] 2 end]]
  if { [string equal -nocase $rules all] } {
    set rules "#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16"
  }
  if { [string equal $rules ""] } {
    lappend output "Usage: rule <show>|<#number1> \[<#number2> .. <#numberN>\]"
  } elseif { [string equal -nocase [lindex [split $rules] 0] show] } {
    lappend output [c_rule:rule \#show]
  } else {
    foreach rule [split $rules] {
      if { ![string equal [set r [c_rule:rule $rule]] 0] } {
        lappend output "$rule   $r"
      }
    }
    lappend output "End of rule list for $rules"
  }
  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]]"
}



#rule msg
bind msg lomn|lomn rule c_rule:msg

proc c_rule:msg { nick uhost handle text } {
  set rules $text
  if { [string equal -nocase $rules all] } {
    set rules "#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16"
  }
  if { [string equal $rules ""] } {
    lappend output "Usage: rule <show>|<#number1> \[<#number2> .. <#numberN>\]"
  } elseif { [string equal -nocase [lindex [split $rules] 0] show] } {
    lappend output [c_rule:rule \#show]
  } else {
    foreach rule [split $rules] {
      if { ![string equal [set r [c_rule:rule $rule]] 0] } {
        lappend output "$rule   $r"
      }
    }
    lappend output "End of rule list for $rules"
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  return 1
}



#rule proc
proc c_rule:rule { number } {
  if { [string equal $number ""] } { return 0 }

  set r(#show) "0. violating 1. welcome 2. repeat, flood, scream, spam 3. haras, fight, swear, foul 4. adv 5. script mp3 bot 6. warez 7. caps, control, !? 8. pm 9. network 10. clones 11. amsg 12. idle 13. worm, virus, infected 14. english 15. paste 16. away"

  set r(#0) "You are violating channel rules."
  set r(violating) $r(#0)

  set r(#1) "You are no longer welcome here."
  set r(welcome) $r(#1)

  set r(#2) "Do NOT repeat, flood, scream or spam."
  set r(repeat) $r(#2)
  set r(flood) $r(#2)
  set r(scream) $r(#2)
  set r(spam) $r(#2)

  set r(#3) "Do NOT harass, fight, swear or use foul language."
  set r(haras) $r(#3)
  set r(fight) $r(#3)
  set r(swear) $r(#3)
  set r(foul) $r(#3)

  set r(#4) "Do NOT advertise."
  set r(adv) $r(#4)

  set r(#5) "Do NOT use scripts such as mp3 or bot scripts."
  set r(script) $r(#5)
  set r(mp3) $r(#5)
  set r(bot) $r(#5)

  set r(#6) "Distribution of copyrighted material or pornography is not allowed on QuakeNet. Please read http://www.quakenet.org/rules"
  set r(warez) $r(#6)

  set r(#7) "Do NOT use excessive caps, control codes or excessive amounts of \"!?\"."
  set r(caps) $r(#7)
  set r(control) $r(#7)

  set r(#8) "Do NOT private message people without their permission."
  set r(pm) $r(#8)

  set r(#9) "Do NOT violate network rules. Please read http://www.quakenet.org/rules"
  set r(network) $r(#9)

  set r(#10) "Too many clients from your host."
  set r(clone) $r(#10)
  set r(clones) $r(#10)

  set r(#11) "Do NOT /amsg in this channel."
  set r(amsg) $r(#11)

  set r(#12) "Idle deals, bots and alike are a waste of resources and are not welcome on QuakeNet. Please read http://www.quakenet.org/rules"
  set r(idle) $r(#12)

  set r(#13) "You appear to be infected with a worm/virus, please clean your computer."
  set r(worm) $r(#13)
  set r(virus) $r(#13)
  set r(infected) $r(#13)

  set r(#14) "Speak English here."
  set r(english) $r(#14)

  set r(#15) "If you want to show us more than 3 lines, use www.nomorepasting.com/paste.php"
  set r(paste) $r(#15)

  set r(#16) "Away/back actions are not welcome here, feel free to return when you are back."
  set r(away) $r(#16)

  set number [string tolower $number]
  if { [info exists r($number)] } { return $r($number) }
  return 0
}

