html/clones.pl


   1 use Irssi 20010920.0000 ();
   2 $VERSION = "2.01";
   3 %IRSSI = (
   4     authors     => 'From irssi source, modified by David Leadbeater (dg)',
   5     name        => 'clones',
   6     description => '/CLONES - Display clones in the active channel (with added options)',
   7     license     => 'Same as Irssi',
   8     url         => 'http://irssi.dgl.yi.org/',
   9 );
  10 
  11 use strict;
  12 
  13 sub cmd_clones {
  14   my ($data, $server, $channel) = @_;
  15 
  16   my $min = $data =~ /\d/ ? $data : Irssi::settings_get_int('clones_min_show');
  17 
  18   if (!$channel || $channel->{type} ne 'CHANNEL') {
  19     Irssi::print('No active channel in window');
  20     return;
  21   }
  22 
  23   my %hostnames = {};
  24   my $ident = Irssi::settings_get_bool('clones_host_only');
  25   
  26   foreach my $nick ($channel->nicks()) {
  27 	my $hostname;
  28 	if($ident) {
  29 	   ($hostname = $nick->{host}) =~ s/^[^@]+@//;
  30 	}else{
  31 	   $hostname = $nick->{host};
  32 	}
  33 
  34 	$hostnames{$hostname} ||= [];
  35 	push( @{ $hostnames{$hostname} }, $nick->{nick});
  36   }
  37 
  38   my $count = 0;
  39   foreach my $host (keys %hostnames) {
  40 	next unless ref($hostnames{$host}) eq 'ARRAY'; # sometimes a hash is here
  41     my @clones = @{ $hostnames{$host} };
  42     if (scalar @clones >= $min) {
  43       $channel->print('Clones:') if ($count == 0);
  44       $channel->print("$host: " . join(' ',@clones));
  45       $count++;
  46     }
  47   }
  48 
  49   $channel->print('No clones in channel') if ($count == 0);
  50 }
  51 
  52 Irssi::command_bind('clones', 'cmd_clones');
  53 Irssi::settings_add_bool('misc', 'clones_host_only', 1);
  54 Irssi::settings_add_int('misc', 'clones_min_show', 2);
  55