use strict; use warnings; use Xchat ':all'; my $CMD = "users"; # alternatives: "count" my $CMD_allchans = "all$CMD"; my $CMD_allchans_incurrent = "all$CMD"."here"; register my$NAME="Count Users", my$VERSION=2, "Count users on a channel (use /$CMD, /$CMD_allchans, /$CMD_allchans_incurrent)"; prnt "\cB$NAME $VERSION\cB by b0at (use /$CMD, /$CMD_allchans, /$CMD_allchans_incurrent)"; my $PREFIX = "\cBCount\cB\t"; sub count_users { my $context = shift(); if( $context ) { set_context($context) or return; } my $channel = get_info("channel"); my @users = get_list("users"); my $count = scalar @users; # count users with modes my %prefix; $prefix{$_->{prefix}}++ for @users; delete $prefix{''}; # remove no mode count return "$channel: $count ". ( !%prefix ? '' : "(".join(", ", map( "$prefix{$_} $_", keys%prefix )).")" ) ; } hook_command($CMD, sub{ prnt "$PREFIX Users in $_" if defined( $_=count_users() ); EAT_XCHAT; }); hook_command($CMD_allchans, sub { for( get_list("channels") ) { next unless $_->{type} == 2; # channel tabs my $count = count_users($_->{context}); prnt "$PREFIX Users in $count" if defined $count; } EAT_XCHAT; }); hook_command($CMD_allchans_incurrent, sub { my $original = get_context(); my @output; for( get_list("channels") ) { next unless $_->{type} == 2; # channel tabs my $count = count_users($_->{context}); push(@output, $count) if defined $count; } set_context($original); prnt "$PREFIX ".join(", ", @output); EAT_XCHAT; });