spider/perl/BadWords.pm
minima 8e0eef8021 fix a talk bug for t xxx > yyy
added badword checking
2000-09-02 15:28:14 +00:00

55 lines
709 B
Perl

#
# Search for bad words in strings
#
# Copyright (c) 2000 Dirk Koopman
#
# $Id$
#
package BadWords;
use strict;
use DXUtil;
use DXVars;
use IO::File;
use vars qw(%badwords $fn);
$fn = "$main::data/badwords";
%badwords = ();
# load the badwords file
sub load
{
my @out;
return unless -e $fn;
my $fh = new IO::File $fn;
if ($fh) {
%badwords = ();
while (<$fh>) {
chomp;
next if /^\s*\#/;
my @list = split " ";
for (@list) {
$badwords{lc $_}++;
}
}
$fh->close;
} else {
my $l = "can't open $fn $!";
dbg('err', $l);
push @out, $l;
}
return @out;
}
# check the text against the badwords list
sub check
{
return grep { $badwords{$_} } split(/\b/, lc shift);
}
1;