From 4f80f121720d3a1497ec82b2d1d440172ec5bd9b Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Thu, 11 May 2017 17:21:34 -0400 Subject: [PATCH] Dynamic banned word list --- lib/App/Controller/Apiv1.pm | 10 +++++++++- lib/App/Model/Paste.pm | 11 ++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/App/Controller/Apiv1.pm b/lib/App/Controller/Apiv1.pm index b917349..e9082f2 100644 --- a/lib/App/Controller/Apiv1.pm +++ b/lib/App/Controller/Apiv1.pm @@ -19,6 +19,7 @@ sub routes { $route->(post => '/api/v1/paste' => 'api_post_paste'); $route->(get => '/api/v1/languages' => 'api_get_languages'); $route->(get => '/api/v1/channels' => 'api_get_channels'); + $route->(get => '/api/v1/re' => 'api_get_re'); } sub api_get_paste { @@ -61,7 +62,7 @@ sub api_post_paste { # warn "I thought this was spam! $type"; # } else { if ($channel) { # TODO config for allowing announcements - my $words = qr/nigger|jew|spic|tranny|trannies|fuck|shit|piss|cunt|asshole|hitler|klan|klux/i; + my $words = $c->paste->banned_word_list_re; unless ($code =~ $words || $who =~ $words || $desc =~ $words) { $c->perlbot->announce($channel, $who, substr($desc, 0, 40), $c->req->url->base()."/p/$id"); } @@ -100,4 +101,11 @@ sub api_get_channels { ]}); }; +sub api_get_re { + my $c=shift; + + use Data::Dumper; + $c->render(text => Dumper($c->paste->banned_word_list_re)); +} + 1; diff --git a/lib/App/Model/Paste.pm b/lib/App/Model/Paste.pm index f235b8b..617a51f 100644 --- a/lib/App/Model/Paste.pm +++ b/lib/App/Model/Paste.pm @@ -60,15 +60,12 @@ sub get_paste { sub banned_word_list_re { my $self = shift; - my $data = $self->dbh->selectall_arrayref("SELECT word FROM wordlist WHERE deleted <> 1"); + my $data = $self->dbh->selectall_arrayref("SELECT word FROM banned_words WHERE deleted <> 1"); - #return $re; -} + my $re_str = join '|', map {quotemeta $_->[0]} @$data; + my $re = qr/($re_str)/i; -sub add_banned_word { - my ($self, $word, $who) = @_; - -# $self-> + return $re; } 1;