1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut-pastebin synced 2025-06-07 14:17:26 -04:00

New blogspam.net spam filter, but it doesnt work on the test server, need to figure out why

This commit is contained in:
Ryan Voots 2016-06-26 16:32:42 -04:00
parent 6e6c8e1155
commit 0b0c3f3084
5 changed files with 47 additions and 9 deletions

12
app.cfg
View file

@ -1,6 +1,7 @@
[features]
memcached=true
evalserver=true
blogspam=false
[memcached]
namespace="pastebin"
@ -10,17 +11,20 @@ hash_namespace=1
io_timeout=0.5
max_failures=3
failure_timeout=2
max_size=524288
[[memcached.servers]]
address="localhost:11211"
weight="2.5"
[blogspam]
site="https://perlbot.pl/"
[evalserver]
server="localhost:14400"
languages=[ "perl" ]
[[memcached.servers]]
address="localhost:11211"
weight="2.5"
# Config for a non-local server. Has a lower weight so that the local one gets checked first
# [[memcached.servers]]
# address="remotehost:11211"

16
app.pl
View file

@ -15,12 +15,12 @@ use Encode qw/decode/;
use Mojolicious::Lite;
use Mojolicious::Plugin::TtRenderer;
use POE::Filter::Reference;
use App::Config;
use App::Memcached;
use Eval::Perlbot;
use IRC::Perlbot;
use DateTime;
use App::Spamfilter;
plugin 'tt_renderer' => {
template_options => {
@ -32,6 +32,10 @@ plugin 'tt_renderer' => {
app->renderer->default_handler( 'tt' );
if ($cfg->{features}{blogspam}) {
plugin 'BlogSpam' => ($cfg->{blogspam}->%*);
}
my $dbh = DBI->connect("dbi:SQLite:dbname=pastes.db", "", "", {RaiseError => 1});
$dbh->{sqlite_unicode} = 1;
# hardcode some channels first
@ -60,11 +64,16 @@ post '/paste' => sub {
my @args = map {($c->param($_))} qw/paste name desc chan/;
my $id = insert_pastebin(@args);
my ($code, $who, $desc, $channel) = @args;
# TODO select which one based on config
# TODO make this use the config, or http params for the url
my ($channel, $who, $what, $link) = @_;
IRC::Perlbot::announce($c->param('chan'), $c->param('name'), $c->param('desc'), "https://perlbot.pl/pastebin/$id");
if (my $type = App::Spamfilter::is_spam($c, $who, $desc, $code)) {
warn "I thought this was spam! $type";
} else {
IRC::Perlbot::announce($c->param('chan'), $c->param('name'), $c->param('desc'), "https://perlbot.pl/pastebin/$id");
}
$c->redirect_to('/pastebin/'.$id);
#$c->render(text => "post accepted! $id");
@ -124,7 +133,6 @@ post '/eval' => sub {
get '/robots.txt' => sub {
my ($c) = @_;
$c->render(text => qq{User-agent: *
Disallow: /});
};

View file

@ -1,11 +1,12 @@
requires 'Mojolicious';
requires 'JSON::MaybeXS';
requires 'TOML'
requires 'TOML';
requires 'Cache::Memcached::Fast';
requires 'DateTime';
requires 'DBI';
requires 'DBD::SQLite';
requires 'Mojolicious::Lite';
requires 'Mojolicious::Plugin::TtRenderer';
requires 'Mojolicious::Plugin::BlogSpam';
requires 'POE::Filter::Reference';

25
lib/App/Spamfilter.pm Normal file
View file

@ -0,0 +1,25 @@
package App::Spamfilter;
use strict;
use warnings;
use App::Config;
sub is_spam {
my ($c, $who, $what, $code) = @_;
if ($cfg->{features}{blogspam}) {
my $blogspam = $c->blogspam(
comment => $code,
subject => $what,
name => $who
);
return 1 unless ($blogspam->test_comment());
}
return 2 if ($who =~ /^[A-Z]\w+\s+[A-Z]\w+$/); # block proper names, probably spam
return 3 if ($what =~ m|https?://|); # no links in the desc, maybe relax later
return 0; # we thought it wasn't spam
}
1;

BIN
pastes.db

Binary file not shown.