finally fixed the regexes
authorminima <minima>
Thu, 4 Oct 2001 15:52:12 +0000 (15:52 +0000)
committerminima <minima>
Thu, 4 Oct 2001 15:52:12 +0000 (15:52 +0000)
cmd/dx.pl
data/badw_regex.issue
perl/BadWords.pm

index 0b2ece1d6b250cd0808f05205c455ed2967520f5..1d09a4769f489744b4c31192c47a8554952203a8 100644 (file)
--- a/cmd/dx.pl
+++ b/cmd/dx.pl
@@ -17,6 +17,12 @@ my @out;
 my $valid = 0;
 return (1, $self->msg('e5')) if $self->remotecmd;
 
+my @bad;
+if (@bad = BadWords::check($line)) {   
+       $self->badcount(($self->badcount||0) + @bad);
+       return (1, $self->msg('e17', @bad));
+}
+
 # do we have at least two args?
 return (1, $self->msg('dx2')) unless @f >= 2;
 
@@ -93,11 +99,6 @@ if ($spotted le ' ') {
 
 return (1, @out) unless $valid;
 
-my @bad;
-if (@bad = BadWords::check($line)) {   
-       $self->badcount(($self->badcount||0) + @bad);
-       return (1, $self->msg('e17', @bad));
-}
 
 # Store it here (but only if it isn't baddx)
 if ($DXProt::baddx->in($spotted)) {
index 489da6176020f9e97d81480bfdc9bfbe809ae02b..e38b4c8d062bb92938b8202d76ba850d236c634f 100644 (file)
@@ -8,7 +8,7 @@ cock c0ck
 wank
 shit sh1t
 piss p1ss
-bolock b0lock b0lock
+bolock b0lock b0l0ck
 toser t0ser
 tospot t0spot t0sp0t
 arse
index db33d7a1c4ebaeb34127c79bb1f5c1463dc35463..b598c385d4e940f45716a4f2f35c303ad9b46e1e 100644 (file)
@@ -17,7 +17,7 @@ use DXDebug;
 
 use IO::File;
 
-use vars qw($badword @regex);
+use vars qw($badword $regexcode);
 
 my $oldfn = "$main::data/badwords";
 my $regex = "$main::data/badw_regex";
@@ -61,11 +61,10 @@ sub load
 sub create_regex
 {
        my @out;
-       @regex = ();
-       
        my $fh = new IO::File $regex;
        
        if ($fh) {
+               my $s = "sub { my \$str = shift; my \@out; \n";
                while (<$fh>) {
                        chomp;
                        next if /^\s*\#/;
@@ -75,12 +74,18 @@ sub create_regex
                                # and repeated characters in it
                                my $w = uc $_;
                                my @l = split //, $w;
-                               my $e = join '+[\s\W]+', @l;
-                               my $s = eval qq{sub { return \$_[0] =~ /$e+/ ? '$w' : () } };
-                               push @regex, $s unless $@;
-                               dbg("create_regex: $@") if $@;
+                               my $e = join '+[\s\W]*', @l;
+                               $s .= "push \@out, \$1 if \$str =~ /($e)/;\n";
                        }
                }
+               $s .= "return \@out;\n}";
+               $regexcode = eval $s;
+               dbg($s) if isdbg('badword');
+               if ($@) {
+                       @out = ($@);
+                       dbg($@);
+                       return @out;
+               }
                $fh->close;
        } else {
                my $l = "can't open $regex $!";
@@ -96,10 +101,9 @@ sub check
 {
        my $s = uc shift;
        my @out;
-       
-       for (@regex) {
-               push @out, &$_($s);
-       }
+
+       dbg($s) if isdbg('badword');
+       push @out, &$regexcode($s) if $regexcode;
        
        return @out if @out;