#!/usr/bin/tclsh

# This plugin refuses all messages with specific "bad" words in them.
# WARNING: No attempt is made to check if a word considered bad is actually
# a substring of an innocuous word (e.g. cunt -> Scunthorpe, a city in UK)
# unless specifically encoded into the regexp.

# Each badwords entry is a Tcl regexp held in a list.

# Written by Michael McConnell, Eridani Star System. This demo file is in the
# public domain. Feel free to use this script as a template for your own.

set MSTRIP_CMD [lindex $argv 0]
set MSTRIP_VER [lindex $argv 1]
set MSTRIP_SRCIP [lindex $argv 2]
set MSTRIP_RMSG [lindex $argv 3]
set MSTRIP_SMSG [lindex $argv 4]

set badwords [list]
lappend badwords {[^s]cunt[^h]}
lappend badwords {fuck}

if { $MSTRIP_CMD == "-id" } {
  puts "BadWords Plugin"
  puts "0.1.0"
  puts "Eridani Star System, this demo is in the public domain"
  if {![string length $MSTRIP_VER]} {
    puts "No"
  } else {
    puts "Yes"
  }
} elseif { $MSTRIP_CMD == "-scan" } {
  if {[catch {set fh [open $MSTRIP_SMSG "r"]}]} {
    puts "#Error, unable to open processed message file"
    puts "0"
    exit
  }
  set datablock [read $fh]
  close $fh

  set r 0
  foreach word $badwords {
    incr r [regexp -all -nocase $word $datablock]
  }

  if {$r} {
    puts "2000 Unsuitable content"
  } else {
    puts "0"
  }
}
