mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 21:45:41 -04:00
Update pastebin to add "Anonymous" for no name. Update eval to include another module. Update factoids to not be case sensitive in suggestions.
This commit is contained in:
parent
35466627e6
commit
6d4ac7e304
4 changed files with 20 additions and 9 deletions
1
cpanfile
1
cpanfile
|
@ -92,3 +92,4 @@ requires 'Text::Metaphone' => 0;
|
||||||
requires 'DBD::SQLite::BundledExtensions' => 0;
|
requires 'DBD::SQLite::BundledExtensions' => 0;
|
||||||
requires 'Text::Levenshtein' => 0;
|
requires 'Text::Levenshtein' => 0;
|
||||||
requires 'Text::Metaphone' => 0;
|
requires 'Text::Metaphone' => 0;
|
||||||
|
requires 'Math::Round' => 0;
|
||||||
|
|
|
@ -68,6 +68,8 @@ sub receive_paste {
|
||||||
} else {
|
} else {
|
||||||
my ($alert_channel, $link, $who, $summary) = split(/\x1E/, $line);
|
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
|
if( $alert_channel !~ /^\s*---/ ) { # Ignore things like "---irc.freenode, skip server names
|
||||||
my($server,$nick,$channel) = split /:/,$alert_channel,3;
|
my($server,$nick,$channel) = split /:/,$alert_channel,3;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ use Encode qw/encode decode/;
|
||||||
use IO::String;
|
use IO::String;
|
||||||
use File::Slurper qw/read_text/;
|
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
|
# save the old stdout, we're going to clobber it soon. STDOUT
|
||||||
my $oldout;
|
my $oldout;
|
||||||
my $outbuffer = "";
|
my $outbuffer = "";
|
||||||
|
|
|
@ -135,7 +135,10 @@ sub postload {
|
||||||
metaphone TEXT,
|
metaphone TEXT,
|
||||||
compose_macro CHAR(1) DEFAULT '0',
|
compose_macro CHAR(1) DEFAULT '0',
|
||||||
protected BOOLEAN 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 );
|
$pm->create_table( $self->dbh, "factoid", $sql );
|
||||||
|
|
||||||
|
@ -617,9 +620,10 @@ sub get_fact_search {
|
||||||
my $search = $1;
|
my $search = $1;
|
||||||
#XXX: need to also search contents of factoids TODO
|
#XXX: need to also search contents of factoids TODO
|
||||||
$results = $self->dbh->selectall_arrayref(
|
$results = $self->dbh->selectall_arrayref(
|
||||||
"SELECT subject,copula,predicate
|
"SELECT subject,copula,predicate
|
||||||
FROM (SELECT subject,copula,predicate FROM factoid GROUP BY original_subject) as subquery
|
FROM factoid
|
||||||
WHERE subject regexp ? OR predicate regexp ?", # using a subquery so that i can do this properly
|
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 => {}},
|
{Slice => {}},
|
||||||
$search, $search,
|
$search, $search,
|
||||||
);
|
);
|
||||||
|
@ -628,9 +632,10 @@ sub get_fact_search {
|
||||||
{
|
{
|
||||||
#XXX: need to also search contents of factoids TODO
|
#XXX: need to also search contents of factoids TODO
|
||||||
$results = $self->dbh->selectall_arrayref(
|
$results = $self->dbh->selectall_arrayref(
|
||||||
"SELECT subject,copula,predicate
|
"SELECT subject,copula,predicate
|
||||||
FROM (SELECT subject,copula,predicate FROM factoid GROUP BY original_subject) as subquery
|
FROM factoid
|
||||||
WHERE subject like ? OR predicate like ?", # using a subquery so that i can do this properly
|
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 => {}},
|
{Slice => {}},
|
||||||
"%$body%", "%$body%",
|
"%$body%", "%$body%",
|
||||||
);
|
);
|
||||||
|
@ -691,7 +696,7 @@ sub _db_get_protect {
|
||||||
SELECT protected
|
SELECT protected
|
||||||
FROM factoid
|
FROM factoid
|
||||||
WHERE original_subject = ?
|
WHERE original_subject = ?
|
||||||
ORDER BY factoid_id DESC
|
ORDER BY factoid_id DESC LIMIT 1
|
||||||
",
|
",
|
||||||
undef,
|
undef,
|
||||||
$subj,
|
$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
|
# 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
|
#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(
|
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,
|
undef,
|
||||||
$metaphone
|
$metaphone
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue