; ======================
; = Censoring script by Pass
; ---------------------------------
; Note: Default words must be
; separated by commas
alias ce.def.words return
alias ce.censor return $!str(*,&len)
alias ce.kick return $iif(%ce.kick,$v1,$false)
alias ce.scen return $iif(%ce.scen,$v1,$false)
; ---------------------------------
; = Do not edit below this line
; ======================
#ce off
on ^*:TEXT:*:*: {
  if ($ce.match($strip($1-))) || ($ce.match($strip($1-))) {
    if ($ce.kick) && ($chan) {
      var %m = $ce.match($1-)
      .timer 1 1 kick $chan $nick Badword! ( $+ $left(%m,2) $+ $str(*,$calc($len(%m) - 2)) $+ )
    }
    echo -mltbf $iif($chan,$v1,$nick) $+(<,$iif($chan,$nick($chan,$nick).pnick,$nick),>) $censor($1-)
    haltdef
  }
}
on *:start:ce.start
#ce end
alias ce.start {
  if (!%ce.words) set %ce.words $ce.def.words
}
alias ce.add {
  if (!$badwords) ce.start
  if (!$ce.check($1)) {
    set %ce.words $addtok($badwords,$1,44)
    return Added $1 to the censoring list
  }
}
alias ce.del {
  if (!$badwords) ce.start
  if ($1 === -c) { var %msg = Cleared $numtok($badwords,44) censor'd entire(s) | unset %ce.words | return %msg }
  if ($1 isnum $+(1-,$numtok($badwords,44))) {
    var %item = $gettok($badwords,$1,44)
    set %ce.words $remtok($badwords,$1,44)
    return Deleted %item from censoring list
  }
  if ($ce.check($1)) { set %ce.words $remtok($badwords,$1,44) | return Deleted $1 from censoring list }
  else return
}
alias ce.list {
  if (!$badwords) ce.start
  if ($1 === -a)  return $numtok($badwords,44)
}
alias ce.check {
  if (!$ce.scen) return $wildtok($badwords,$+(*,$1,*),1,44)
  else {
    var %x = 1
    while ($gettok($badwords,%x,44)) {
      var %v = $v1,%w = $gettok(%v,1,58)
      if ($+(*,%w,*) iswm $1) || ($+(*,$1,*) iswm %w) return %v
      inc %x
    }
    return $false
  }
}
alias badwords return $iif(%ce.words,$v1,$ce.def.words)
alias ce.match {
  var %x = 1,%words
  while ($gettok($1-,%x,32)) {
    if ($ce.check($v1)) {
      if ($prop == pos) var %words = %words %x
      else return $gettok($1-,%x,32)
    }
    inc %x
  }
  return %words
}
alias censor {
  var %n = 1
  var %word = $strip($1-),%pos = $ce.match(%word).pos
  while (%n <= $numtok(%pos,32)) {
    var %p = $gettok(%pos,%n,32),%g = $gettok(%word,%p,32)
    if ($ce.check(%g)) {
      var %c.c = $v1
      if (*:* iswm %c.c) var %censor = $gettok(%c.c,2,58)
      else var %censor = $ce.censor
      var %cen = $($replace(%censor,&text,%g,&len,$len(%g)),2)
    }
    var %word = $reptok(%word,%g,%cen,32)
    inc %n
  }     
  return %word
}
menu menubar,channel,status {
  Censoring list
  .$ce.list(-a) $iif($ce.list(-a) == 1,Entry,Entries) :return
  .$iif($group(#ce) != on,En,Dis) $+ able: $($+(.,$iif($group(#ce) != on,en,dis),able),2) #ce
  .-
  .$iif($ce.kick,$style(1)) $+ Kick:set %ce.kick $iif($ce.kick,$false,$true)
  .$iif(!$ce.scen,$style(1)) $+ Strict:set %ce.scen $iif($ce.scen,$false,$true)
  .-
  .$iif($group(#ce) != on,$style(2)) Add:ce.add $$?="Word(:Cover-up):"
  .$iif(!$badwords || $group(#ce) != on,$style(2)) Delete:ce.del $$?="Word (or entry number)"
  .-
  .$iif(!$badwords || $group(#ce) != on,$style(2)) Clear:ce.del -c
} 
