-
Notifications
You must be signed in to change notification settings - Fork 235
/
cwho.pl
79 lines (63 loc) · 1.95 KB
/
cwho.pl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## Usage: /CWHO [-a | -l | -o | -v ] [ mask ]
## ver 1.1
# - added sorting
# - few fixes
use Irssi 20020300;
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "1.1";
%IRSSI = (
authors => "Maciek \'fahren\' Freudenheim",
contact => "fahren\@bochnia.pl",
name => "Cached WHO",
description => "Usage: /CWHO [-a | -l | -o | -v ] [ mask ]",
license => "GNU GPLv2 or later",
changed => "Mon May 6 14:02:25 CEST 2002"
);
Irssi::theme_register([
'cwho_line', '%K[%W$[!-3]0%K][%C$1%B$[9]2%K][%B$[-10]3%P@%B$[34]4%K]%n'
]);
sub sort_mode {
if ($a->[0] eq $b->[0]) {
return 0;
} elsif ($a->[0] eq "@") {
return -1;
} elsif ($b->[0] eq "@") {
return 1;
} elsif ($a->[0] eq "v") {
return -1;
} elsif ($b->[0] eq "v") {
return 1
};
}
Irssi::command_bind 'cwho' => sub {
my ($pars, $server, $winit) = @_;
$pars =~ s/^\s+//;
my @data = split(/ +/, $pars);
my ($cmode, $cmask, $i) = ('.', "*!*@*", 0);
unless ($winit && $winit->{type} eq "CHANNEL") {
Irssi::print("You don't have active channel in that window");
return;
}
my $channel = $winit->{name};
while ($_ = shift(@data)) {
/^-a$/ and $cmode = '.', next;
/^-l$/ and $cmode = 'X', next;
/^-o$/ and $cmode = '@', next;
/^-v$/ and $cmode = 'v', next;
/[!@.]+/ and $cmask = $_, next;
}
my @sorted = ();
for my $hash ($winit->nicks()) {
my $mode = $hash->{op}? "@" : $hash->{voice}? "v" : " ";
if ($cmode eq "X") {
next if $mode ne " ";
} elsif ($mode !~ /$cmode/) {next}
next unless $server->mask_match_address($cmask, $hash->{nick}, $hash->{host});
my ($user, $host) = split(/@/, $hash->{host});
push @sorted, [ $mode, $hash->{nick}, $user, $host ];
}
@sorted = sort { sort_mode || lc $a->[1] cmp lc $b->[1] } @sorted;
$server->printformat($channel, MSGLEVEL_CLIENTCRAP, 'cwho_line', ++$i, @$_) for (@sorted);
Irssi::print("No matches for \'$cmask\'.") unless $i;
}