-sub userCommands {
- return '' unless ($addressed);
-
- # chaninfo. xk++.
- if ($message =~ /^chan(stats|info)(\s+(\S+))?$/i) {
- my $chan = lc $3;
- my $mode;
-
- if ($chan eq "") { # all channels.
- my $count = 0;
- my $i = keys %channels;
- my $reply = "i am on \002$i\002 ".&fixPlural("channel",$i);
- my @array;
-
- ### line 1.
- foreach (sort keys %channels) {
- if (/^\s*$/ or / /) {
- &status("chanstats: fe channels: chan == NULL.");
- &ircCheck();
- next;
- }
- push(@array, "$_ (".scalar(keys %{$channels{$_}{''}}).")");
- }
- &performStrictReply($reply.": ".join(' ', @array));
-
- ### line 2.
- foreach $chan (keys %channels) {
- # crappy debugging...
- # TODO: use $mask{chan} instead?
- if ($chan =~ / /) {
- &ERROR("bad channel: chan => '$chan'.");
- }
- $count += scalar(keys %{$channels{$chan}{''}});
- }
- &performStrictReply(
- "i've cached \002$count\002 ".&fixPlural("user",$count).
- " distributed over \002".scalar(keys %channels)."\002 ".
- &fixPlural("channel",scalar(keys %channels))."."
- );
-
- return $noreply;
- }
-
- # channel specific.
-
- if (&validChan($chan) == 0) {
- &msg($who,"error: invalid channel \002$chan\002");
- return $noreply;
- }
-
- # Step 1:
- my @array;
- foreach (sort keys %{$chanstats{$chan}}) {
- my $int = $chanstats{$chan}{$_};
- next unless ($int);
-
- push(@array, "\002$int\002 ". &fixPlural($_,$int));
- }
- my $reply = "On \002$chan\002, there ".
- &fixPlural("has",scalar(@array)). " been ".
- &IJoin(@array);
-
- # Step 1b: check channel inconstencies.
- $chanstats{$chan}{'Join'} ||= 0;
- $chanstats{$chan}{'SignOff'} ||= 0;
- $chanstats{$chan}{'Part'} ||= 0;
-
- my $delta_stats = $chanstats{$chan}{'Join'}
- - $chanstats{$chan}{'SignOff'}
- - $chanstats{$chan}{'Part'};
-
- if ($delta_stats) {
- my $total = scalar(keys %{$channels{$chan}{''}});
- &status("chaninfo: join ~= signoff + part (drift of $delta_stats < $total).");
-
- if ($delta_stats > $total) {
- &ERROR("chaninfo: delta_stats exceeds total users.");
- }
- }
-
- # Step 2:
- undef @array;
- my $type;
- foreach ("v","o","") {
- my $int = scalar(keys %{$channels{$chan}{$_}});
- next unless ($int);
-
- $type = "Voice" if ($_ eq "v");
- $type = "Opped" if ($_ eq "o");
- $type = "Total" if ($_ eq "");
-
- push(@array,"\002$int\002 $type");
- }
- $reply .= ". At the moment, ". &IJoin(@array);
-
- # Step 3:
- ### TODO: what's wrong with the following?
- my %new = map { $userstats{$_}{'Count'} => $_ } keys %userstats;
- 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";
- }
- &performStrictReply("$reply.");
-
- return $noreply;
- }
-
- # Command statistics.
- if ($message =~ /^cmdstats$/i) {
- my @array;
-
- if (!scalar(keys %cmdstats)) {
- &performReply("no-one has run any commands yet");
- return $noreply;
- }
-
- my %countstats;
- foreach (keys %cmdstats) {
- $countstats{$cmdstats{$_}}{$_} = 1;
- }
-
- foreach (sort {$b <=> $a} keys %countstats) {
- my $int = $_;
- next unless ($int);
-
- foreach (keys %{$countstats{$int}}) {
- push(@array, "\002$int\002 of $_");
- }
- }
- &performStrictReply("command usage include ". &IJoin(@array).".");
-
- return $noreply;
+###
+### Start of commands for hooks.
+###
+
+sub chaninfo {
+ my $chan = lc shift(@_);
+ my $mode;
+
+ if ( $chan eq '' ) { # all channels.
+ my $i = keys %channels;
+ my $tucount = 0; # total user count.
+ my $uucount = 0; # unique user count.
+ my %chans;
+ my @array;
+
+ ### line 1.
+ foreach ( keys %channels ) {
+ if ( /^\s*$/ or / / ) {
+ &status('chanstats: fe channels: chan == NULL.');
+
+ #&ircCheck();
+ next;
+ }
+ next if (/^_default$/);
+
+ $chans{$_} = scalar( keys %{ $channels{$_}{''} } );
+ }
+ foreach $chan ( sort { $chans{$b} <=> $chans{$a} } keys %chans ) {
+ push( @array, "$chan/" . $chans{$chan} );
+ }
+
+ ### total user count.
+ foreach $chan ( keys %channels ) {
+ $tucount += scalar( keys %{ $channels{$chan}{''} } );
+ }
+
+ ### unique user count.
+ my %nicks = ();
+ foreach $chan ( keys %channels ) {
+ my $nick;
+ foreach $nick ( keys %{ $channels{$chan}{''} } ) {
+ $nicks{$nick}++;
+ }
+ }
+ $uucount = scalar( keys %nicks );
+
+ my $chans = scalar( keys %channels );
+ my $join = &ircCheck();
+ &performStrictReply(
+ "\002$chans/".($chans+$join)."\002 " . &fixPlural('channel', $chans)
+ . ", \002$tucount\002 " . &fixPlural('user', $tucount)
+ . ", \002$uucount\002 unique: "
+ . join(', ', @array));
+
+ return;