X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FFactoids.pl;h=9a2a8592bbce4c4a59b9bb4713fcdf80d547e5ef;hb=6347aa7bd7d649273a92c66190507cc7b41a6278;hp=56f7ab1b5b9ed3285c27313eb800292b45f4b19b;hpb=f5b6971238746faebb57730bcc946d5a2d1af56d;p=infobot.git diff --git a/src/Modules/Factoids.pl b/src/Modules/Factoids.pl index 56f7ab1..9a2a859 100644 --- a/src/Modules/Factoids.pl +++ b/src/Modules/Factoids.pl @@ -64,9 +64,8 @@ sub CmdFactInfo { push(@array,$string); } - # modified: - # disabled for the time being... it's misleading/useless info. - if (0 && $factinfo{'modified_by'}) { + # modified: (TimRiker asks "why do you keep turning this off?) + if ($factinfo{'modified_by'}) { $string = "last modified"; my $time = $factinfo{'modified_time'}; @@ -129,7 +128,7 @@ sub CmdFactInfo { return; } - &pSReply("$factinfo{'factoid_key'} -- ". join("; ", @array) ."."); + &performStrictReply("$factinfo{'factoid_key'} -- ". join("; ", @array) ."."); return; } @@ -137,14 +136,14 @@ sub CmdFactStats { my ($type) = @_; if ($type =~ /^author$/i) { - my @array = &sqlSelectColArray("factoids", - "factoid_key,created_by", { }, - "created_by IS NOT NULL" + my %hash = &sqlSelectColHash("factoids", + "factoid_key,created_by", undef, + "WHERE created_by IS NOT NULL" ); my %author; - foreach (@array) { - my $thisnuh = $hash{$_}; + foreach my $factoid (keys %hash) { + my $thisnuh = $hash{$factoid}; $thisnuh =~ /^(\S+)!\S+@\S+$/; $author{lc $1}++; @@ -172,16 +171,16 @@ sub CmdFactStats { return &formListReply(0, $prefix, @list); } elsif ($type =~ /^vandalism$/i) { - &status("factstats(vandalism): starting..."); + &status("factstats(vandalism): starting..."); my $start_time = &timeget(); my %data = &sqlSelectColHash("factoids", - "factoid_key,factoid_value", { }, - "factoid_value IS NOT NULL" + "factoid_key,factoid_value", undef, + "WHERE factoid_value IS NOT NULL" ); my @list; my $delta_time = &timedelta($start_time); - &status(sprintf("factstats(vandalismbroken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0); + &status(sprintf("factstats(vandalism): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0); $start_time = &timeget(); # parse the factoids. @@ -193,7 +192,7 @@ sub CmdFactStats { } $delta_time = &timedelta($start_time); - &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0); + &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0); # bail out on no results. if (scalar @list == 0) { @@ -205,7 +204,7 @@ sub CmdFactStats { return &formListReply(1, $prefix, @list); } elsif ($type =~ /^total$/i) { - &status("factstats(total): starting..."); + &status("factstats(total): starting..."); my $start_time = &timeget(); my @list; my $str; @@ -236,7 +235,7 @@ sub CmdFactStats { push(@list, "total prepared for deletion - $str"); # total unique authors. - # todo: convert to sqlSelectColHash ? (or ColArray?) + # TODO: convert to sqlSelectColHash ? (or ColArray?) foreach ( &sqlRawReturn("SELECT created_by FROM factoids WHERE created_by IS NOT NULL") ) { /^(\S+)!/; my $nick = lc $1; @@ -257,7 +256,7 @@ sub CmdFactStats { ### end of "job". my $delta_time = &timedelta($start_time); - &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0); + &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0); $start_time = &timeget(); # bail out on no results. @@ -266,7 +265,7 @@ sub CmdFactStats { } # parse the results. - my $prefix = "General factoid stiatistics "; + my $prefix = "General factoid statistics "; return &formListReply(1, $prefix, @list); } elsif ($type =~ /^deadredir$/i) { @@ -303,11 +302,11 @@ sub CmdFactStats { return &formListReply(1, $prefix, @newlist); } elsif ($type =~ /^dup(licate|e)$/i) { - &status("factstats(dupe): starting..."); + &status("factstats(dupe): starting..."); my $start_time = &timeget(); - my %hash = &sqlSelectColHash("factoids", - "factoid_key,factoid_value", { }, - "factoid_value IS NOT NULL", 1 + my %hash = &sqlSelectColHash("factoids", + "factoid_key,factoid_value", undef, + "WHERE factoid_value IS NOT NULL", 1 ); my $refs = 0; my @list; @@ -339,7 +338,7 @@ sub CmdFactStats { &status("factstats(dupe): (good) dupe refs: $refs."); my $delta_time = &timedelta($start_time); - &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0); + &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0); # bail out on no results. if (scalar @list == 0) { @@ -424,9 +423,9 @@ sub CmdFactStats { return &formListReply(1, $prefix, @list); } elsif ($type =~ /^locked$/i) { - my %hash = &sqlSelectColhash("factoids", - "factoid_key,locked_by", { }, - "locked_by IS NOT NULL" + my %hash = &sqlSelectColhash("factoids", + "factoid_key,locked_by", undef, + "WHERE locked_by IS NOT NULL" ); my @list = keys %hash; @@ -439,8 +438,8 @@ sub CmdFactStats { } elsif ($type =~ /^new$/i) { my %hash = &sqlSelectColHash("factoids", - "factoid_key,created_time", { }, - "created_time IS NOT NULL" + "factoid_key,created_time", undef, + "WHERE created_time IS NOT NULL" ); my %age; @@ -507,7 +506,7 @@ sub CmdFactStats { } my $delta_time = sprintf("%.02fs", &timedelta($start_time) ); - &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0); + &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0); # bail out on no results. if (scalar @list == 0) { @@ -520,8 +519,8 @@ sub CmdFactStats { } elsif ($type =~ /^profanity$/i) { my %data = &sqlSelectColHash("factoids", - "factoid_key,factoid_value", { }, - "factoid_value IS NOT NULL" + "factoid_key,factoid_value", undef, + "WHERE factoid_value IS NOT NULL" ); my @list; @@ -538,6 +537,7 @@ sub CmdFactStats { "factoid_value", "^ see "); my %redir; my $f; + my $dangling = 0; for (@list) { my $factoid = $_; @@ -548,7 +548,8 @@ sub CmdFactStats { if (defined $redirval) { $redir{$redir}{$factoid} = 1; } else { - &WARN("factstats(redir): '$factoid' has loose link => '$redir'."); + &DEBUG("factstats(redir): '$factoid' has loose link => '$redir'."); + $dangling++; } } } @@ -564,13 +565,13 @@ sub CmdFactStats { } # parse the results. - my $prefix = "Redirections in factoids "; + my $prefix = "Redirections in factoids, $dangling dangling "; return &formListReply(1, $prefix, @newlist); } elsif ($type =~ /^request(ed)?$/i) { my %hash = &sqlSelectColHash("factoids", - "factoid_key,requested_count", { }, - "requested_count IS NOT NULL", 1 + "factoid_key,requested_count", undef, + "WHERE requested_count IS NOT NULL", 1 ); if (!scalar keys %hash) { @@ -597,8 +598,8 @@ sub CmdFactStats { } elsif ($type =~ /^reqrate$/i) { my %hash = &sqlSelectColHash("factoids", - "factoid_key,(unix_timestamp() - created_time)/requested_count as rate", { }, - "requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1 + "factoid_key,(unix_timestamp() - created_time)/requested_count as rate", undef, + "WHERE requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1 ); my $rate; @@ -617,8 +618,8 @@ sub CmdFactStats { } elsif ($type =~ /^requesters?$/i) { my %hash = &sqlSelectColHash("factoids", - "factoid_key,requested_by", { }, - "requested_by IS NOT NULL" + "factoid_key,requested_by", undef, + "WHERE requested_by IS NOT NULL" ); my %requester; @@ -668,7 +669,7 @@ sub CmdFactStats { for (@list) { my $factoid = $_; my $val = &getFactInfo($factoid, "factoid_value"); - + next unless ($val =~ /^see( also)? (.*?)\.?$/i); my $redirf = lc $2; @@ -726,15 +727,10 @@ sub CmdFactStats { return &formListReply(1, $prefix, @list); } elsif ($type =~ /^unrequest(ed)?$/i) { - # todo: use sqlSelect() - my @list = &sqlRawReturn("SELECT factoid_key FROM factoids WHERE requested_count IS NULL"); - - for (@list) { - s/([\,\;]+)/\037$1\037/g; - } + # TODO: use sqlSelect() + my ($count) = &sqlRawReturn("SELECT COUNT(*) FROM factoids WHERE requested_count = '0'"); - my $prefix = "Unrequested factoids "; - return &formListReply(0, $prefix, @list); + return "Unrequested factoids: $count"; } return "error: invalid type => '$type'."; @@ -742,7 +738,9 @@ sub CmdFactStats { sub CmdListAuth { my ($query) = @_; + my $maxshow = &::getChanConfDefault('maxListReplyCount', 15, $chan); my @list = &searchTable("factoids","factoid_key", "created_by", "^$query!"); + @list=grep(!/\#DEL\#$/,@list) if (scalar(@list) > $maxshow); my $prefix = "factoid author list by '$query' "; &performStrictReply( &formListReply(1, $prefix, @list) );