X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FCommandStubs.pl;h=1deef1401b194191ce84aa629f013c1e167a0657;hb=7464ad6e662a450ac03f246b264c5141730e7c31;hp=cc0a3fb926a759a0eaaeceff275cf1f303beeb62;hpb=5b661567bd6bdb15cc1e48e102bda3a26d03bd65;p=infobot.git diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index cc0a3fb..1deef14 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -44,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 || ''); @@ -73,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) { @@ -183,8 +184,8 @@ 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) ); @@ -278,7 +279,7 @@ sub Modules { return; } - my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?'; + my $debiancmd = 'conflicts?|depends?|desc|file|d?info|provides?'; $debiancmd .= '|recommends?|suggests?|maint|maintainer'; if ($message =~ /^($debiancmd)(\s+(.*))?$/i) { @@ -308,107 +309,8 @@ sub Modules { my $itc; $itc = &getChanConf("ircTextCounters"); $itc = &findChanConf("ircTextCounters") unless ($itc); - if ($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; - } - - if ($message =~ /^($z)stats(\s+(\S+))?$/i) { - my $type = $1; - my $arg = $3; - - # even more uglier with channel/time arguments. - my $c = $chan; -# my $c = $chan || "PRIVATE"; - my $where = "type=".&sqlQuote($type); - $where .= " AND channel=".&sqlQuote($c) if (defined $c); - &DEBUG("not using chan arg") if (!defined $c); - 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 = ""; - &DEBUG("*stats: tp => $tp"); - 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; - } - - # 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 0) { my $i; $i = $userstats{lc $seen[0]}{'Count'}; $reply .= ". Has said a total of \002$i\002 messages" if (defined $i); @@ -904,6 +807,111 @@ sub verstats_flush { $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 $tp"); if (scalar @top) { $topstr = ". Top ".scalar(@top).": ".join(', ', @top); } @@ -948,53 +955,55 @@ sub textstats_main { } else { &pSReply("zero counter for \037$type\037."); } - } else { - # 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 $i, good => $good, total => $total"); - $x .= " ".$total."blah blah"; + # 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 $i, good => $good, total => $total"); + $x .= " ".$total."blah blah"; + } - if (!defined $x) { # !defined. - &pSReply("$arg has not said $type yet."); - return; - } +# 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 %)"; - } + if (!defined $x) { # !defined. + &pSReply("$arg has not said $type yet."); + return; + } - my $pct1 = sprintf("%.01f", 100*$x/$sum); - &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra"); + 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);