Text censoring

By Pass on Aug 13, 2008

This code is useful for filtering out any unwanted text, whether it be replacing it or banning the user. All options and settings can be found in the menu. I've commented the aliases with their syntax and descriptions.

Updated 8/17

I've added kick/banning and ignoring options. Additional options are available when the protections are enabled in the menu.

alias badword return %censor_list
alias censor_word { if (!%censor_word) set %censor_word <censor> | return %censor_word }
alias censor_str { if (!%censor_str) set %censor_str 1 | return %censor_str }
alias censor_bl { if (!%censor_blength) set %censor_blength 300 | return %censor_blength }
alias censor_klimit { if (!%censor_klimit) set %censor_klimit 4 | return %censor_klimit }
alias censor_il { if (!%censor_ilength) set %censor_ilength 300 | return %censor_ilength }

#censor on
on ^*:TEXT:*:*: {
  if ($c.check($1-)) {
    echo -mltbf $iif($chan,$v1,$nick) $+(<,$iif($chan,$pnick($chan,$nick),$nick),>) $censor($1-)
    if (%censor_ignore) .ignore $+(-u,$censor_il) $nick 2 $network
    if ($chan && %censor_kick) c.kick $chan $nick
    haltdef
  }
}
#censor end

; $pnick(chan,nick) -  Nickname with (one) prefix
alias pnick { var %p = $+($left($remove($nick($1,$2).pnick,$nick),1),$nick) | return %p }

; $c.add(badword[,badword2]) - Adds badwords to the list
alias c.add {
  var %n = $0,%p = $numtok($badword,44)
  while (%n) {
    var %1 = $($+($chr(36),%n),2)
    set %censor_list $addtok(%censor_list,%1,44)
    dec %n
  }
  return * /c.add: Added $calc($numtok($badword,44) - %p) badword(s)
}

; $c.del(badword[,badword2]) - Deletes badwords from the list
alias c.del {
  var %n = $0,%p = $numtok($badword,44)
  while (%n) {
    var %1 = $($+($chr(36),%n),2)
    set %censor_list $remtok(%censor_list,%1,1,44)
    dec %n
  }
  return * /c.del: Removed $calc(%p - $numtok($badword,44)) badword(s)
}

; $c.check(text) - Checks for badwords in text
alias c.check { 
  var %n = $numtok($1-,32),%list,%p
  while (%n) {
    var %1 = $gettok($1-,%n,32)
    if ($istok($badword,%1,44) && $censor_str == 1)  { 
      if ($prop == pos) var %p = %p %n
      var %list = $addtok(%list,%1,44)
    }
    if ($wtok($badword,%1,44) && $censor_str == 2) {
      if ($prop == pos) var %p = %p %n
      var %list = $addtok(%list,%1,44)
    }
    dec %n
  }
  if ($prop == pos) return %p
  return %list
}

; $c.kick(channel,nick) - /_kicks/bans if need be
alias c.kick {
  var %v = $+(%,c.,$1,.,$2),%limit = $censor_klimit
  if ($(%v,2)) inc -u120 $+(%,c.,$1,.,$2)
  else set -u120 $+(%,c.,$1,.,$2) 1
  if ($(%v,2) >= %limit) {
    if ($me isop $1) || ($me ishop $1) ban $+(-u,$censor_bl) $1 $address($2,2)
    var %msg = Swearing - Banned for $+(,$calc($censor_bl /60),) minutes.
    set -u0 $+(%,c.,$1,.,$2) 1
  }
  if (!%msg) {
    if ($calc(%limit - $(%v,2)) == 1) var %msg = Swearing - $ord($(%v,2)) & Last warning. 
    else var %msg = Swearing - $ord($(%v,2)) warning.
  }
  _kick $1 $2 %msg
}

; $censor(text) - Censors badwords in text
alias censor { 
  var %list = $strip($1-),%clist = %list
  var %p = $c.check(%list).pos,%n = $numtok(%p,32)
  while (%n) {
    var %badword = $gettok(%list,$gettok(%p,%n,32),32)
    var %clist = $puttok(%clist,$censor_word,$gettok(%p,%n,32),32)
    dec %n
  }
  return %clist
}

; $cmlist - A submenu
alias cmlist {
  if ($1 == Begin) return -
  var %n = $numtok($badword,44)
  while (%n) {
    if ($1 == %n) return $gettok($badword,%n,44) :return
    dec %n
  }
  if ($1 == $calc($numtok($badword,44) + 1)) return -
  if ($1 == $calc($numtok($badword,44) + 2)) return Clear list:unset $+(%,censor_list)
  if ($1 == end) return -
}

; $wtok(text,matchtext,C)
alias wtok {
  var %n = 1
  while ($gettok($1,%n,$3)) {
    var %1 = $v1
    if (%1 iswm $2) || (%1 isin $2) return %1
    inc %n 
  }
}

; /_kick channel nick - kicks a user from a channel
alias _kick {
  var %e = echo $color(info) -a * /_kick:
  if ($me ison $1) {
    if ($2 ison $1) {
      if ($me isop $1 || $me ishop $1) {
        if ($2 ishop $1 && $me ishop $1) return
        .kick $1-
      }
      else %e Insufficient status in $2
    }
    else %e $2 is not on $1
  }
  else %e You're not on $1
}

menu channel,status,query {
  -
  Censor
  .$iif($group(#censor) == on,En,Dis) $+ abled: $iif($group(#censor) == on,.disable,.enable) #censor
  .-
  .Offensive
  ..$iif(%censor_kick,$style(1)) Kickban:set %censor_kick $iif(%censor_kick,$false,$true)
  ..$iif(%censor_kick,Warning kicks $+ $chr(58) $censor_klimit):set %censor_klimit $iif($$?="Enter new limit" isnum 1-10,$v1,$censor_klimit)
  ..$iif(%censor_kick,Ban length $+ $chr(58) $+($calc($censor_bl /60),m)):set %censor_blength $iif($$?="Enter new ban length (minutes):" isnum 1-60,$calc($v1 *60),$censor_bl)
  ..-
  ..$iif(%censor_ignore,$style(1)) Ignore:set %censor_ignore $iif(%censor_ignore,$false,$true)
  ..$iif(%censor_ignore,Ignore length $+ $chr(58) $+($calc($censor_il /60),m)):set %censor_ilength $iif($$?="Enter new ignore length (minutes):" isnum 1-60,$calc($v1 *60),$censor_il)
  .Strength
  ..Currently $+ $chr(58) $+($censor_str,/2) :return
  ..-
  ..$iif($censor_str < 2,Increase): inc %censor_str
  ..$iif($censor_str > 1,Decrease): dec %censor_str
  .Replacement
  ..$iif($censor_word,$v1,N/A):set %censor_word $$?="Enter replacement word:"
  .-
  .$iif(!$badword,$style(2)) List
  ..$submenu($cmlist($1))
  .-
  .Add:var %x = $$?="Enter word1[,word2]:" | return $input($c.add(%x),i)
  .$iif(!$badword,$style(2)) Delete:var %x = $$?="Enter word1[,word2]:" | return $input($c.del(%x),i)
}

Comments

Sign in to comment.
sk68   -  Aug 10, 2009

awesome for overprotective parents ^^

 Respond  
^Neptune   -  Aug 25, 2008

So.. if you added like the word "pie" to the list, everytime someone said pie in the chat it would be filtered?

Coolio

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.