]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
- use undef instead of { }
[infobot.git] / src / Modules / Factoids.pl
index 724993df7482110322473cff70d0e2c76282dc55..ef80889ffff147141cddf412b24657e1004017fc 100644 (file)
@@ -14,6 +14,7 @@ use vars qw(%param);
 # Usage: &CmdFactInfo($faqtoid, $query);
 sub CmdFactInfo {
     my ($faqtoid, $query) = (lc $_[0], $_[1]);
+    $faqtoid =~ s/^cmd:/CMD:/;
     my @array;
     my $string = "";
 
@@ -64,8 +65,8 @@ sub CmdFactInfo {
        push(@array,$string);
     }
 
-    # modified:
-    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'};
@@ -137,8 +138,8 @@ sub CmdFactStats {
 
     if ($type =~ /^author$/i) {
        my %hash = &sqlSelectColHash("factoids",
-               "factoid_key,created_by", { },
-               "created_by IS NOT NULL"
+               "factoid_key,created_by", undef,
+               "WHERE created_by IS NOT NULL"
        );
        my %author;
 
@@ -174,8 +175,8 @@ sub CmdFactStats {
         &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;
 
@@ -265,7 +266,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) {
@@ -305,8 +306,8 @@ sub CmdFactStats {
         &status("factstats(dupe): starting...");
        my $start_time  = &timeget();
        my %hash        = &sqlSelectColHash("factoids", 
-               "factoid_key,factoid_value", { },
-               "factoid_value IS NOT NULL", 1
+               "factoid_key,factoid_value", undef,
+               "WHERE factoid_value IS NOT NULL", 1
        );
        my $refs        = 0;
        my @list;
@@ -424,8 +425,8 @@ sub CmdFactStats {
 
     } elsif ($type =~ /^locked$/i) {
        my %hash = &sqlSelectColhash("factoids", 
-               "factoid_key,locked_by", { },
-               "locked_by IS NOT NULL"
+               "factoid_key,locked_by", undef,
+               "WHERE locked_by IS NOT NULL"
        );
        my @list = keys %hash;
 
@@ -438,8 +439,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;
 
@@ -519,8 +520,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;
 
@@ -570,8 +571,8 @@ sub CmdFactStats {
 
     } 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) {
@@ -598,8 +599,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;
@@ -618,8 +619,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;
 
@@ -669,7 +670,7 @@ sub CmdFactStats {
        for (@list) {
            my $factoid = $_;
            my $val = &getFactInfo($factoid, "factoid_value");
-       
+
            next unless ($val =~ /^see( also)? (.*?)\.?$/i);
 
            my $redirf  = lc $2;
@@ -728,14 +729,9 @@ sub CmdFactStats {
 
     } 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;
-       }
+       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'.";