]> git.donarmstrong.com Git - infobot.git/blobdiff - src/CommandStubs.pl
ws
[infobot.git] / src / CommandStubs.pl
index e4380702bbe1e4ed97978aaf2f082478303ade64..7da444ec790176150a434ec4afa892d43285a9a2 100644 (file)
@@ -3,13 +3,22 @@
 # WARN: this file does not reload on HUP.
 #
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
 
-$babel_lang_regex = "fr|sp|po|pt|it|ge|de|gr|en";
+use vars qw($who $msgType $conn $chan $message $ident $talkchannel
+       $bot_version $babel_lang_regex $bot_data_dir);
+use vars qw(@vernick @vernicktodo);
+use vars qw(%channels %cache %mask %userstats %myModules %cmdstats
+       %hooks_extra %lang %ver);
+# FIX THE FOLLOWING:
+use vars qw($total $x $type $i $good);
+
+$babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru";
+$w3search_regex   = "google";
 
 ### COMMAND HOOK IMPLEMENTATION.
 # addCmdHook("SECTION", 'TEXT_HOOK',
-#      (CODEREF        => 'Blah', 
+#      (CODEREF        => 'Blah',
 #      Forker          => 1,
 #      CheckModule     => 1,                   # ???
 #      Module          => 'blah.pl'            # preload module.
@@ -35,7 +44,8 @@ sub addCmdHook {
 # RUN IF ADDRESSED.
 sub parseCmdHook {
     my ($hashname, $line) = @_;
-    $line =~ /^(\S+)( (.*))?$/;
+    $line =~ s/^\s+|\s+$//g;   # again.
+    $line =~ /^(\S+)(\s+(.*))?$/;
     my $cmd    = $1;   # command name is whitespaceless.
     my $flatarg        = $3;
     my @args   = split(/\s+/, $flatarg || '');
@@ -48,8 +58,13 @@ sub parseCmdHook {
        return 0;
     }
 
+    if (!defined $cmd) {
+       &WARN("cstubs: cmd == NULL.");
+       return 0;
+    }
+
     foreach (keys %{"hooks_$hashname"}) {
-       # rename to something else!
+       # rename to something else! like $id or $label?
        my $ident = $_;
 
        next unless ($cmd =~ /^$ident$/i);
@@ -59,7 +74,7 @@ sub parseCmdHook {
            next;
        }
 
-       &status("hooks($hashname): $cmd matched '$ident'");
+       &status("hooks($hashname): $cmd matched '$ident' '$flatarg'");
        my %hash = %{ ${"hooks_$hashname"}{$ident} };
 
        if (!scalar keys %hash) {
@@ -68,7 +83,7 @@ sub parseCmdHook {
        }
 
        if ($hash{NoArgs} and $flatarg) {
-           &DEBUG("cmd $ident does not take args; skipping.");
+           &DEBUG("cmd $ident does not take args ('$flatarg'); skipping.");
            next;
        }
 
@@ -115,7 +130,7 @@ sub parseCmdHook {
 
            # check if CODEREF exists.
            if (!defined &{ $hash{'CODEREF'} }) {
-               &WARN("coderef $hash{'CODEREF'} don't exist.");
+               &WARN("coderef $hash{'CODEREF'} does not exist.");
                if (defined $who) {
                    &msg($who, "coderef does not exist for $ident.");
                }
@@ -169,13 +184,13 @@ sub parseCmdHook {
 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
        'Forker' => 1, 'Identifier' => 'debian',
        'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
-&addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
-       'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
+#&addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
+#      'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
        'Forker' => 1, 'Identifier' => 'kernel',
        'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
-       'Identifier' => 'search', Module => 'factoids', 
+       'Identifier' => 'search', Module => 'factoids',
        'Help' => 'listauth') );
 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
        'Forker' => 1, 'Identifier' => 'quote',
@@ -203,13 +218,39 @@ sub parseCmdHook {
 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
        'Identifier' => 'slashdot', 'Forker' => 1,
        'Cmdstats' => 'Slashdot') );
+&addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug',
+       'Identifier' => 'plug', 'Forker' => 1,
+       'Cmdstats' => 'Plug') );
 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
        'Cmdstats' => 'Uptime') );
 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
-&addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
-       'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
-       'Forker' => 1, 'Help' => 'freshmeat') );
 &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
+&addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather',
+       'Identifier' => 'weather', 'Help' => 'weather',
+       'Cmdstats' => 'weather', 'Forker' => 1) );
+&addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list',
+       'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
+       'Forker' => 1) );
+&addCmdHook("extra", 'bzfquery', ('CODEREF' => 'BZFlag::query',
+       'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
+       'Forker' => 1, 'Help' => 'bzflag') );
+&addCmdHook("extra", 'zfi', ('CODEREF' => 'zfi::query',
+       'Identifier' => 'zfi', 'Cmdstats' => 'zfi',
+       'Forker' => 1) );
+&addCmdHook("extra", '(zippy|yow)', ('CODEREF' => 'zippy::get',
+       'Identifier' => 'zippy', 'Cmdstats' => 'zippy',
+       'Forker' => 1) );
+&addCmdHook("extra", 'zsi', ('CODEREF' => 'zsi::query',
+       'Identifier' => 'zsi', 'Cmdstats' => 'zsi',
+       'Forker' => 1) );
+&addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query',
+       'Identifier' => 'exchange', 'Cmdstats' => 'exchange',
+       'Forker' => 1) );
+&addCmdHook("extra", '(botmail|message)', ('CODEREF' => 'botmail::parse',
+       'Identifier' => 'botmail', 'Cmdstats' => 'botmail') );
+&addCmdHook("extra", 'httpdtype', ('CODEREF' => 'HTTPDtype::HTTPDtype',
+       'Identifier' => 'httpdtype', 'Cmdstats' => 'httpdtype',
+       'Forker' => 1) );
 
 ###
 ### END OF ADDING HOOKS.
@@ -223,16 +264,17 @@ sub Modules {
     }
 
     # babel bot: Jonathan Feinberg++
-    if (&IsChanConf("babelfish") and $message =~ m{
+    if ($message =~ m{
                ^\s*
                (?:babel(?:fish)?|x|xlate|translate)
                \s+
-               (to|from)               # direction of translation (through)
+               ($babel_lang_regex)\w*  # from language?
                \s+
-               ($babel_lang_regex)\w*  # which language?
+               ($babel_lang_regex)\w*  # to language?
                \s*
                (.+)                    # The phrase to be translated
-       }xoi) {
+    }xoi) {
+       return unless (&hasParam("babelfish"));
 
        &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
 
@@ -240,24 +282,24 @@ sub Modules {
        return;
     }
 
-    if (&IsChanConf("debian")) {
-       my $debiancmd    = 'conflicts?|depends?|desc|file|info|provides?';
-       $debiancmd      .= '|recommends?|suggests?|maint|maintainer';
-       if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
-           my $package = lc $3;
+    my $debiancmd       = 'conflicts?|depends?|desc|file|(?:d)?info|provides?';
+    $debiancmd         .= '|recommends?|suggests?|maint|maintainer';
 
-           if (defined $package) {
-               &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
-           } else {
-               &help($1);
-           }
+    if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
+       return unless (&hasParam("debian"));
+       my $package = lc $3;
 
-           return;
+       if (defined $package) {
+           &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
+       } else {
+           &help($1);
        }
+
+       return;
     }
 
     # google searching. Simon++
-    if (&IsChanConf("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
+    if ($message =~ /^(?:search\s+)?($w3search_regex)\s+(?:for\s+)?['"]?(.*?)["']?\s*\?*$/i) {
        return unless (&hasParam("wwwsearch"));
 
        &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
@@ -266,30 +308,37 @@ sub Modules {
        return;
     }
 
+    # text counters. (eg: hehstats)
+    my $itc;
+    $itc = &getChanConf("ircTextCounters");
+    $itc = &findChanConf("ircTextCounters") unless ($itc);
+    return if ($itc && &do_text_counters($itc) == 1);
+    # end of text counters.
+
     # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
-    if ($message =~ /^list(\S+)( (.*))?$/i) {
+    if ($message =~ /^list(\S+)(\s+(.*))?$/i) {
        return unless (&hasParam("search"));
 
-       my $thiscmd     = lc($1);
-       my $args        = $3;
-       $args           =~ s/\s+$//g;
-       # suggested by asuffield nad \broken.
-       if ($args =~ /^["']/ and $args =~ /["']$/) {
-           &DEBUG("list*: removed quotes.");
-           $args       =~ s/^["']|["']$//g;
-       }
+       my $thiscmd     = lc $1;
+       my $args        = $3 || "";
 
-       $thiscmd =~ s/^vals$/values/;
+       $thiscmd        =~ s/^vals$/values/;
        return if ($thiscmd ne "keys" && $thiscmd ne "values");
 
        # Usage:
-       if (!defined $args) {
+       if (!defined $args or $args =~ /^\s*$/) {
            &help("list". $thiscmd);
            return;
        }
 
-       if (length $args == 1) {
-           &msg($who,"search string is too short.");
+       # suggested by asuffield and \broken.
+       if ($args =~ /^["']/ and $args =~ /["']$/) {
+           &DEBUG("list*: removed quotes.");
+           $args       =~ s/^["']|["']$//g;
+       }
+
+       if (length $args < 2 && &IsFlag("o") ne "o") {
+           &msg($who, "search string is too short.");
            return;
        }
 
@@ -348,7 +397,7 @@ sub Modules {
            $percentage = "off the scale";
        } else {
            $percentage = sprintf("%0.4f", $percentage);
-           $percentage =~ s/\.?0+$//;
+           $percentage =~ s/(\.\d+)0+$/$1/;
            $percentage .= '%';
        }
 
@@ -362,7 +411,7 @@ sub Modules {
     }
 
     # Topic management. xk++
-    # may want to add a flag(??) for topic in the near future. -xk
+    # may want to add a userflags for topic. -xk
     if ($message =~ /^topic(\s+(.*))?$/i) {
        return unless (&hasParam("topic"));
 
@@ -421,7 +470,7 @@ sub Modules {
            $reply .= ".  Started the scan ".&Time2String(time() - $wingaterun)." ago";
        }
 
-       &performStrictReply("$reply.");
+       &pSReply("$reply.");
 
        return;
     }
@@ -430,19 +479,6 @@ sub Modules {
     return "CONTINUE";
 }
 
-# Freshmeat. xk++
-sub freshmeat {
-    my ($query) = @_;
-
-    if (!defined $query) {
-       &help("freshmeat");
-       &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
-       return;
-    }
-
-    &Freshmeat::Freshmeat($query);
-}
-
 # Uptime. xk++
 sub uptime {
     my $count = 1;
@@ -461,7 +497,8 @@ sub uptime {
 
 # seen.
 sub seen {
-    my($person) = @_;
+    my($person) = lc shift;
+    $person =~ s/\?*$//;
 
     if (!defined $person or $person =~ /^$/) {
        &help("seen");
@@ -474,16 +511,15 @@ sub seen {
     }
 
     my @seen;
-    $person =~ s/\?*$//;
 
     &seenFlush();      # very evil hack. oh well, better safe than sorry.
 
-    ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
+    # TODO: convert to &sqlSelectRowHash();
     my $select = "nick,time,channel,host,message";
     if ($person eq "random") {
        @seen = &randKey("seen", $select);
     } else {
-       @seen = &dbGet("seen", "nick", $person, $select);
+       @seen = &sqlSelect("seen", $select, { nick => $person } );
     }
 
     if (scalar @seen < 2) {
@@ -498,6 +534,7 @@ sub seen {
     my $reply;
     ### TODO: multi channel support. may require &IsNick() to return
     ###        all channels or something.
+
     my @chans = &getNickInChans($seen[0]);
     if (scalar @chans) {
        $reply = "$seen[0] is currently on";
@@ -508,7 +545,7 @@ sub seen {
            $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
        }
 
-       if (&IsParam("seenStats")) {
+       if (&IsChanConf("seenStats") > 0) {
            my $i;
            $i = $userstats{lc $seen[0]}{'Count'};
            $reply .= ".  Has said a total of \002$i\002 messages" if (defined $i);
@@ -522,7 +559,7 @@ sub seen {
                 "saying\002:\002 '$seen[4]'.";
     }
 
-    &performStrictReply($reply);
+    &pSReply($reply);
     return;
 }
 
@@ -564,8 +601,8 @@ sub cookie {
     ### TODO: convert this to a Forker function!
     if ($arg) {
        my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
-       $key  = &getRandom(@list);
-       $val  = &getFactInfo("factoids", $key, "factoid_value");
+       $key    = &getRandom(@list);
+       $value  = &getFactInfo($key, "factoid_value");
     } else {
        ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
     }
@@ -621,7 +658,7 @@ sub lart {
        }
     }
 
-    my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
+    my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.lart");
     if (defined $line) {
        if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
            $line =~ s/WHO/$who/g;
@@ -637,7 +674,7 @@ sub lart {
 }
 
 sub DebianNew {
-    my $idx   = "debian/Packages-woody.idx";
+    my $idx   = "debian/Packages-sid.idx";
     my $error = 0;
     my %pkg;
     my @new;
@@ -646,7 +683,7 @@ sub DebianNew {
     $error++ unless ( -e "$idx-old");
 
     if ($error) {
-       $error = "no woody/woody-old index file found.";
+       $error = "no sid/sid-old index file found.";
        &ERROR("Debian: $error");
        &msg($who, $error);
        return;
@@ -669,11 +706,11 @@ sub DebianNew {
        next if (/^\*/);
        next if (exists $pkg{$_});
 
-       push(@new);
+       push(@new, $_);
     }
     close IDX1;
 
-    &::performStrictReply( &::formListReply(0, "New debian packages:", @new) );
+    &::pSReply( &::formListReply(0, "New debian packages:", @new) );
 }
 
 sub do_verstats {
@@ -694,12 +731,24 @@ sub do_verstats {
        return;
     }
 
-    &msg($who, "Sending CTCP VERSION...");
+    &msg($who, "Sending CTCP VERSION to $chan; results in 60s.");
     $conn->ctcp("VERSION", $chan);
     $cache{verstats}{chan}     = $chan;
     $cache{verstats}{who}      = $who;
     $cache{verstats}{msgType}  = $msgType;
 
+    $conn->schedule(30, sub {
+       my $c           = lc $cache{verstats}{chan};
+       @vernicktodo    = ();
+
+       foreach (keys %{ $channels{$c}{''} } ) {
+           next if (grep /^\Q$_\E$/i, @vernick);
+           push(@vernicktodo, $_);
+       }
+
+       &verstats_flush();
+    } );
+
     $conn->schedule(60, sub {
        my $vtotal      = 0;
        my $c           = lc $cache{verstats}{chan};
@@ -717,7 +766,7 @@ sub do_verstats {
        my $unknown     = $total - $vtotal;
        my $perc        = sprintf("%.1f", $unknown * 100 / $total);
        $perc           =~ s/.0$//;
-       $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)";
+       $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)" if ($unknown);
 
        foreach (keys %ver) {
            my $count   = scalar keys %{ $ver{$_} };
@@ -736,6 +785,8 @@ sub do_verstats {
            }
        }
 
+       # hack. this is one major downside to scheduling.
+       $chan = $c;
        &pSReply( &formListReply(0, "IRC Client versions for $c ", @list) );
 
        # clean up not-needed data structures.
@@ -746,6 +797,218 @@ sub do_verstats {
     return;
 }
 
+sub verstats_flush {
+    for (1..5) {
+       last unless (scalar @vernicktodo);
+
+       my $n = shift(@vernicktodo);
+       $conn->ctcp("VERSION", $n);
+    }
+
+    return unless (scalar @vernicktodo);
+
+    $conn->schedule(3, \&verstats_flush() );
+}
+
+sub do_text_counters {
+    my ($itc) = @_;
+    $itc =~ s/([^\w\s])/\\$1/g;
+    my $z = join '|', split ' ', $itc;
+
+    if ($msgType eq "privmsg" and $message =~ / ($mask{chan})$/) {
+       &DEBUG("ircTC: privmsg detected; chan = $1");
+       $chan = $1;
+    }
+
+    if ($message =~ /^_stats(\s+(\S+))$/i) {
+       &textstats_main($2);
+       return 1;
+    }
+
+    my ($type,$arg);
+    if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
+       $type = $1;
+       $arg  = $3;
+    } else {
+       return 0;
+    }
+
+    # even more uglier with channel/time arguments.
+    my $c      = $chan;
+#   my $c      = $chan || "PRIVATE";
+    my $where  = "type=".&sqlQuote($type);
+    if (defined $c) {
+       &DEBUG("c => $c");
+       $where  .= " AND channel=".&sqlQuote($c) if (defined $c);
+    } else {
+       &DEBUG("not using chan arg");
+    }
+
+    my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats"
+                       ." WHERE ".$where ))[0];
+
+    if (!defined $arg or $arg =~ /^\s*$/) {
+       # this is way fucking ugly.
+
+       # TODO convert $where to hash
+       my %hash = &sqlSelectColHash("stats", "nick,counter",
+                       { },
+                       $where." ORDER BY counter DESC LIMIT 3", 1
+       );
+       my $i;
+       my @top;
+
+       # unfortunately we have to sort it again!
+       my $tp = 0;
+       foreach $i (sort { $b <=> $a } keys %hash) {
+           foreach (keys %{ $hash{$i} }) {
+               my $p   = sprintf("%.01f", 100*$i/$sum);
+               $tp     += $p;
+               push(@top, "\002$_\002 -- $i ($p%)");
+           }
+       }
+       my $topstr = "";
+       if (scalar @top) {
+           $topstr = ".  Top ".scalar(@top).": ".join(', ', @top);
+       }
+
+       if (defined $sum) {
+           &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
+       } else {
+           &pSReply("zero counter for \037$type\037.");
+       }
+    } else {
+       # TODO convert $where to hash and use a sqlSelect
+       my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats".
+                       " WHERE $where AND nick=".&sqlQuote($arg) ))[0];
+
+       if (!defined $x) {      # !defined.
+           &pSReply("$arg has not said $type yet.");
+           return 1;
+       }
+
+       # defined.
+       # TODO convert $where to hash
+       my @array = &sqlSelect("stats", "nick", undef,
+                       $where." ORDER BY counter", 1
+       );
+       my $good = 0;
+       my $i = 0;
+       for ($i=0; $i<scalar @array; $i++) {
+           next unless ($array[0] =~ /^\Q$who\E$/);
+           $good++;
+           last;
+       }
+       $i++;
+
+       my $total = scalar(@array);
+       my $xtra = "";
+       if ($total and $good) {
+           my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total);
+           $xtra = ", ranked $i\002/\002$total (percentile: \002$pct\002 %)";
+       }
+
+       my $pct1 = sprintf("%.01f", 100*$x/$sum);
+       &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
+    }
+
+    return 1;
+}
+
+sub textstats_main {
+    my($arg) = @_;
+
+    # even more uglier with channel/time arguments.
+    my $c      = $chan;
+#    my $c     = $chan || "PRIVATE";
+    &DEBUG("not using chan arg") if (!defined $c);
+
+    # example of converting from RawReturn to sqlSelect.
+    my $where_href = (defined $c) ? { channel => $c } : "";
+    my $sum = &sqlSelect("stats", "SUM(counter)", $where_href);
+
+    if (!defined $arg or $arg =~ /^\s*$/) {
+       # this is way fucking ugly.
+       &DEBUG("_stats: !arg");
+
+       my %hash = &sqlSelectColHash("stats", "nick,counter",
+               $where_href,
+               " ORDER BY counter DESC LIMIT 3", 1
+       );
+       my $i;
+       my @top;
+
+       # unfortunately we have to sort it again!
+       my $tp = 0;
+       foreach $i (sort { $b <=> $a } keys %hash) {
+           foreach (keys %{ $hash{$i} }) {
+               my $p   = sprintf("%.01f", 100*$i/$sum);
+               $tp     += $p;
+               push(@top, "\002$_\002 -- $i ($p%)");
+           }
+       }
+
+       my $topstr = "";
+       if (scalar @top) {
+           $topstr = ".  Top ".scalar(@top).": ".join(', ', @top);
+       }
+
+       if (defined $sum) {
+           &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
+       } else {
+           &pSReply("zero counter for \037$type\037.");
+       }
+
+       return;
+    }
+
+    # TODO add nick to where_href
+    my %hash = &sqlSelectColHash("stats", "type,counter",
+               $where_href, " AND nick=".&sqlQuote($arg)
+    );
+    # this is totally fucked... needs to be fixed... and cleaned up.
+    my $total;
+    my $good;
+    my $ii;
+    my $x;
+
+    foreach (keys %hash) {
+       &DEBUG("_stats: hash{$_} => $hash{$_}");
+       # ranking.
+       # TODO convert $where to hash
+       my @array = &sqlSelect("stats", "nick", undef,
+               $where." ORDER BY counter", 1);
+       $good = 0;
+       $ii = 0;
+       for(my $i=0; $i<scalar @array; $i++) {
+           next unless ($array[0] =~ /^\Q$who\E$/);
+           $good++;
+           last;
+       }
+       $ii++;
+
+       $total = scalar(@array);
+       &DEBUG("   i => $i, good => $good, total => $total");
+       $x .= " ".$total."blah blah";
+    }
+
+#    return;
+
+    if (!defined $x) { # !defined.
+       &pSReply("$arg has not said $type yet.");
+       return;
+    }
+
+    my $xtra = "";
+    if ($total and $good) {
+       my $pct = sprintf("%.01f", 100*(1+$total-$ii)/$total);
+       $xtra = ", ranked $ii\002/\002$total (percentile: \002$pct\002 %)";
+    }
+
+    my $pct1 = sprintf("%.01f", 100*$x/$sum);
+    &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
+}
+
 sub nullski { my ($arg) = @_; return unless (defined $arg);
        foreach (`$arg`) { &msg($who,$_); } }