File: clones.pl

package info (click to toggle)
irssi-scripts 20201016
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,068 kB
  • sloc: perl: 71,842; sh: 193; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use vars qw($VERSION %IRSSI);
use Irssi 20010920.0000 ();
$VERSION = "2.01";
%IRSSI = (
    authors     => 'From irssi source, modified by David Leadbeater (dg)',
    name        => 'clones',
    description => '/CLONES - Display clones in the active channel (with added options)',
    license     => 'Same as Irssi',
    url         => 'http://irssi.dgl.cx/',
);

sub cmd_clones {
  my ($data, $server, $channel) = @_;

  my $min = $data =~ /\d/ ? $data : Irssi::settings_get_int('clones_min_show');

  if (!$channel || $channel->{type} ne 'CHANNEL') {
    Irssi::print('No active channel in window');
    return;
  }

  my %hostnames = {};
  my $ident = Irssi::settings_get_bool('clones_host_only');
  
  foreach my $nick ($channel->nicks()) {
	my $hostname;
	if($ident) {
	   ($hostname = $nick->{host}) =~ s/^[^@]+@//;
	}else{
	   $hostname = $nick->{host};
	}

	$hostnames{$hostname} ||= [];
	push( @{ $hostnames{$hostname} }, $nick->{nick});
  }

  my $count = 0;
  foreach my $host (keys %hostnames) {
	next unless ref($hostnames{$host}) eq 'ARRAY'; # sometimes a hash is here
    my @clones = @{ $hostnames{$host} };
    if (scalar @clones >= $min) {
      $channel->print('Clones:') if ($count == 0);
      $channel->print("$host: " . join(' ',@clones));
      $count++;
    }
  }

  $channel->print('No clones in channel') if ($count == 0);
}

Irssi::command_bind('clones', 'cmd_clones');
Irssi::settings_add_bool('misc', 'clones_host_only', 1);
Irssi::settings_add_int('misc', 'clones_min_show', 2);