From 6d4ac7e30424973c2eee2e651b1a2b805c82cee4 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Fri, 13 Jan 2017 14:44:26 -0500 Subject: [PATCH] Update pastebin to add "Anonymous" for no name. Update eval to include another module. Update factoids to not be case sensitive in suggestions. --- cpanfile | 1 + lib/Bot/BB3/Roles/Evalpastebin.pm | 2 ++ lib/eval.pl | 3 +++ plugins/factoids.pm | 23 ++++++++++++++--------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cpanfile b/cpanfile index 65934e6..651110e 100644 --- a/cpanfile +++ b/cpanfile @@ -92,3 +92,4 @@ requires 'Text::Metaphone' => 0; requires 'DBD::SQLite::BundledExtensions' => 0; requires 'Text::Levenshtein' => 0; requires 'Text::Metaphone' => 0; +requires 'Math::Round' => 0; diff --git a/lib/Bot/BB3/Roles/Evalpastebin.pm b/lib/Bot/BB3/Roles/Evalpastebin.pm index 4d91327..cab629f 100644 --- a/lib/Bot/BB3/Roles/Evalpastebin.pm +++ b/lib/Bot/BB3/Roles/Evalpastebin.pm @@ -68,6 +68,8 @@ sub receive_paste { } else { my ($alert_channel, $link, $who, $summary) = split(/\x1E/, $line); + $who = "Anonymous" unless $who =~ /\S/; + if( $alert_channel !~ /^\s*---/ ) { # Ignore things like "---irc.freenode, skip server names my($server,$nick,$channel) = split /:/,$alert_channel,3; diff --git a/lib/eval.pl b/lib/eval.pl index 4fc0ef9..7c3a25a 100755 --- a/lib/eval.pl +++ b/lib/eval.pl @@ -18,6 +18,9 @@ use Encode qw/encode decode/; use IO::String; use File::Slurper qw/read_text/; +# Easter egg +do {package Tony::Robbins; sub import {die "Tony Robbins hungry: https://www.youtube.com/watch?v=GZXp7r_PP-w\n"}; $INC{"Tony/Robbins.pm"}=1}; + # save the old stdout, we're going to clobber it soon. STDOUT my $oldout; my $outbuffer = ""; diff --git a/plugins/factoids.pm b/plugins/factoids.pm index 1168ce6..c3adc2a 100644 --- a/plugins/factoids.pm +++ b/plugins/factoids.pm @@ -135,7 +135,10 @@ sub postload { metaphone TEXT, compose_macro CHAR(1) DEFAULT '0', protected BOOLEAN DEFAULT '0' - )"; # Stupid lack of timestamp fields + ); + CREATE INDEX factoid_subject_idx ON factoid(subject); + CREATE INDEX factoid_original_subject_idx ON factoid(original_subject_idx); + "; # Stupid lack of timestamp fields $pm->create_table( $self->dbh, "factoid", $sql ); @@ -617,9 +620,10 @@ sub get_fact_search { my $search = $1; #XXX: need to also search contents of factoids TODO $results = $self->dbh->selectall_arrayref( - "SELECT subject,copula,predicate - FROM (SELECT subject,copula,predicate FROM factoid GROUP BY original_subject) as subquery - WHERE subject regexp ? OR predicate regexp ?", # using a subquery so that i can do this properly + "SELECT subject,copula,predicate + FROM factoid + JOIN (SELECT max(factoid_id) AS factoid_id FROM factoid GROUP BY original_subject) AS subquery ON subquery.factoid_id = factoid.factoid_id + WHERE subject regexp ? OR predicate regexp ?", {Slice => {}}, $search, $search, ); @@ -628,9 +632,10 @@ sub get_fact_search { { #XXX: need to also search contents of factoids TODO $results = $self->dbh->selectall_arrayref( - "SELECT subject,copula,predicate - FROM (SELECT subject,copula,predicate FROM factoid GROUP BY original_subject) as subquery - WHERE subject like ? OR predicate like ?", # using a subquery so that i can do this properly + "SELECT subject,copula,predicate + FROM factoid + JOIN (SELECT max(factoid_id) AS factoid_id FROM factoid GROUP BY original_subject) AS subquery ON subquery.factoid_id = factoid.factoid_id + WHERE subject like ? OR predicate like ?", {Slice => {}}, "%$body%", "%$body%", ); @@ -691,7 +696,7 @@ sub _db_get_protect { SELECT protected FROM factoid WHERE original_subject = ? - ORDER BY factoid_id DESC + ORDER BY factoid_id DESC LIMIT 1 ", undef, $subj, @@ -800,7 +805,7 @@ sub _metaphone_matches { # TODO this needs to be rewritten to do an edit distance based on the metaphone columns, rather than a direct comparison #XXX HACK WARNING: not really a hack, but something to document, the inner query here seems to work fine on sqlite, but i suspect on other databases it might need an ORDER BY factoid_id clause to enforce that it picks the last entry in the database my $rows = $dbh->selectall_arrayref( - "SELECT f.factoid_id, f.subject, f.predicate, f.metaphone, spellfix1_editdist(f.metaphone, ?) AS score FROM (SELECT max(factoid_id) AS factoid_id FROM factoid GROUP BY subject) as subquery JOIN factoid AS f USING (factoid_id) WHERE NOT (f.predicate = ' ') AND f.predicate IS NOT NULL AND length(f.metaphone) > 1 AND score < 200 ORDER BY score ASC;", + "SELECT f.factoid_id, f.subject, f.predicate, f.metaphone, spellfix1_editdist(f.metaphone, ?) AS score FROM (SELECT max(factoid_id) AS factoid_id FROM factoid GROUP BY original_subject) as subquery JOIN factoid AS f USING (factoid_id) WHERE NOT (f.predicate = ' ' OR f.predicate = '') AND f.predicate IS NOT NULL AND length(f.metaphone) > 1 AND score < 200 ORDER BY score ASC;", undef, $metaphone );