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

####################################################
# rule:help:pubm
####################################################
bind pubm lomn|lomn "% ${botnet-nick} help rule" rule:help:pubm
proc rule:help:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "rule: usage rule"
  lappend o "rule: shows predefined rules which can be used in warn/kick/out/chanout/ban commands. it shows the rules numbers followed by keywords. to use them in warn/kick/ban, simply specify a keyword from the rule that you want to use. for example 'advertise', but 'adv' will also work (regexp match) or 'adv*' (wildcardmatch), the input needs at least 2 letters."
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "rule: " } }
  putloglev c $c "help: $n $u $h $c rule"
  return 1
}


####################################################
# rule:help:msgm
####################################################
bind msgm lomn|lomn "help rule" rule:help:msgm
proc rule:help:msgm { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "rule: usage rule"
  lappend o "rule: shows predefined rules which can be used in warn/kick/out/chanout/ban commands. it shows the rules numbers followed by keywords. to use them in warn/kick/ban, simply specify a keyword from the rule that you want to use. for example 'advertise', but 'adv' will also work (regexp match) or 'adv*' (wildcardmatch), the input needs at least 2 letters."
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "rule: " } }
  putcmdlog "($n!$u) !$h! help rule"
  return 1
}


####################################################
# rule:pubm
####################################################
bind pubm lomn|lomn "% ${botnet-nick} rule" rule:pubm
bind pubm lomn|lomn "% ${botnet-nick} rule *" rule:pubm
proc rule:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  set o [rule:get "" 1]
  lappend o "rule: to use these predefined rules in warn/kick/out/chanout/ban commands simply specify a keyword from the rule that you want to use. for example 'advertise', but 'adv' will also work (regexp match) or 'adv*' (wildcardmatch), the input needs at least 2 letters."
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "rule: " } }
  putloglev c $c "rule: $n $u $h $c"
  return 1
}


####################################################
# rule:msg
####################################################
bind msg lomn|lomn rule rule:msg
proc rule:msg { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  set o [rule:get "" 1]
  lappend o "rule: to use these predefined rules in warn/kick/out/chanout/ban commands simply specify a keyword from the rule that you want to use. for example 'advertise', but 'adv' will also work (regexp match) or 'adv*' (wildcardmatch), the input needs at least 2 letters."
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "rule: " } }
  return 1
}


####################################################
# rule:dcc
####################################################
bind dcc -|- rule rule:dcc
proc rule:dcc { h i t } {
  set o [rule:get "" 1]
  lappend o "rule: to use these predefined rules in warn/kick/out/chanout/ban commands simply specify a keyword from the rule that you want to use. for example 'advertise', but 'adv' will also work (regexp match) or 'adv*' (wildcardmatch), the input needs at least 2 letters."
  foreach l $o { putidx $i $l }
  return 1
}


####################################################
# rule:get
####################################################
proc rule:get { t {a 0} } {
  if {![string equal $a "0"]} { set a 1 }
  if {!$a && ![regexp {^[a-zA-Z0-9\?\*]+$} $t]} { return $t }
  if {!$a && ![regexp {[a-zA-Z0-9]} $t]} { return $t }
  set t [string tolower $t]
  set r(\#0,rules,violate) "You are violating channel rules."
  set r(\#1,welcome) "You are no longer welcome here."
  set r(\#2,repeat,flood,scream,spam) "Do NOT repeat, flood, scream or spam."
  set r(\#3,harass,fight,swear,foul) "Do NOT harass, fight, swear or use foul language."
  set r(\#4,advertise) "Do NOT advertise."
  set r(\#5,scripts,mp3s,bots,triggers) "Do NOT use scripts such as mp3 or bot scripts."
  set r(\#6,warez) "Distribution of copyrighted material or pornography is not allowed on QuakeNet. Please read http://www.quakenet.org/rules"
  set r(\#7,caps) "Do NOT use excessive caps or excessive amounts of \"!?\"."
  set r(\#8,pm) "Do NOT private message people without their permission."
  set r(\#9,network) "Do NOT violate network rules. Please read http://www.quakenet.org/rules"
  set r(\#10,clones) "Too many clients from your host."
  set r(\#11,amsg) "Do NOT /amsg in this channel."
  set r(\#12,worm,virus,infected) "You appear to be infected with a worm/virus, please clean your computer."
  set r(\#13,paste) "If you want to show us more than 3 lines, use www.impulze.net/paste/"
  set r(\#14,away,back) "Away/back actions are not welcome here so please disable them, feel free to return when you are back."
  foreach e [lsort -dictionary [array names r]] {
    set f [split $e ,]; set n [lindex $f 0]; set f [lrange $f 1 end]
    if {$a} { lappend t "$n [join $f ", "]"; continue }
    foreach g $f {
      if {[string equal -nocase $t $f]} { return $r($e) }
      if {[string match -nocase $t $f]} { return $r($e) }
      if {[regexp {^[a-zA-Z0-9]{2,}$} $t]} {
        if {[regexp $t $f]} { return $r($e) }
        if {[string match -nocase "$t*" $f]} { return $r($e) }
      }
    }
  }
  if {$a} { lappend o "rule: [join $t "   "]"; return $o }
  return $t
}


set scriptdb(rule) {
  "provides rule command and predefined rules that can be used in warn/kick/ban commands."
}

