Cmdstats => 'Tell') );
&addCmdHook("main", 'news', ('CODEREF' => 'News::Parse',
Module => 'news', ) );
-# Module => 'news', Identifier => 'news') );
+&addCmdHook("main", 'countrystats', ('CODEREF' => 'countryStats',
+# Forker => "NULL",
+ ) );
&status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks.");
$reply .= ". At the moment, ". &IJoin(@array);
# Step 3:
- ### TODO: what's wrong with the following?
- my %new = map { $userstats{$_}{'Count'} => $_ } keys %userstats;
+ my %new;
+ foreach (keys %userstats) {
+ next unless (exists $userstats{$_}{'Count'});
+ $new{$_} = $userstats{$_}{'Count'};
+ }
+
my($count) = (sort { $b <=> $a } keys %new)[0];
if ($count) {
- $reply .= ". \002$new{$count}\002 has said the most with a total of \002$count\002 messages";
+ $reply .= ". \002$count\002 has said the most with a total of \002$new{$count}\002 messages";
}
&pSReply("$reply.");
}
&performReply($result);
}
+sub countryStats {
+ if (exists $cache{countryStats}) {
+ &msg($who,"countrystats is already running!");
+ return;
+ }
+
+ if ($chan eq "") {
+ $chan = $_[0];
+ }
+
+ if ($chan eq "") {
+ &help("countrystats");
+ return;
+ }
+
+ &rawout("WHO $chan");
+ $cache{countryStats}{chan} = $chan;
+ $cache{countryStats}{mtype} = $msgType;
+ $cache{countryStats}{who} = $who;
+ $cache{on_who_Hack} = 1;
+}
+
+sub do_countrystats {
+ $chan = $cache{countryStats}{chan};
+ $msgType = $cache{countryStats}{mtype};
+ $who = $cache{countryStats}{who};
+
+ my $total = 0;
+ my %cstats;
+ foreach (keys %{ $cache{nuhInfo} }) {
+ my $h = $cache{nuhInfo}{$_}{Host};
+
+ if ($h =~ /^.*\.(\D+)$/) { # host
+ $cstats{$1}++;
+ } else { # ip
+ $cstats{unresolve}++;
+ }
+ $total++;
+ }
+ my %count;
+ foreach (keys %cstats) {
+ $count{ $cstats{$_} }{$_} = 1;
+ }
+
+ my @list;
+ foreach (sort {$b <=> $a} keys %count) {
+ my $str = join(", ", sort keys %{ $count{$_} });
+# push(@list, "$str ($_)");
+ my $perc = sprintf("%.01f", 100 * $_ / $total);
+ $perc =~ s/\.0+$//;
+ push(@list, "$str ($_, $perc %)");
+ }
+
+ # todo: move this into a scheduler like nickometer
+ $msgType = "private";
+ &pSReply( &formListReply(0, "Country Stats ", @list) );
+
+ delete $cache{countryStats};
+ delete $cache{on_who_Hack};
+}
###
### amalgamated commands.
sub userCommands {
# conversion: ascii.
if ($message =~ /^(asci*|chr) (\d+)$/) {
- return unless (&IsParam("allowConv"));
+ &DEBUG("ascii/chr called ...");
+ return unless (&hasParam("allowConv"));
+
+ &DEBUG("ascii/chr called");
$arg = $2;
$result = chr($arg);
}
# conversion: ord.
- if ($message =~ /^ord (.)$/) {
- return unless (&IsParam("allowConv"));
+ if ($message =~ /^ord(\s+(.*))$/) {
+ return unless (&hasParam("allowConv"));
+
+ $arg = $2;
+
+ if (!defined $arg or length $arg != 1) {
+ &help("ord");
+ return;
+ }
- $arg = $1;
if (ord($arg) < 32) {
$arg = chr(ord($arg) + 64);
if ($arg eq chr(64)) {
# hex.
if ($message =~ /^hex(\s+(.*))?$/i) {
- return unless (&IsParam("allowConv"));
+ return unless (&hasParam("allowConv"));
my $arg = $2;
if (!defined $arg) {