-
Notifications
You must be signed in to change notification settings - Fork 0
/
listsort.pl
54 lines (43 loc) · 1.19 KB
/
listsort.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
use Irssi;
use vars qw/$VERSION %IRSSI/;
$VERSION = '0.1';
%IRSSI = (
authors => 'Isaac Good',
name => 'listsort',
contact => '[email protected]',
decsription => 'Sort the /list output by channel size',
license => 'BSD',
url => 'https://github.com/IsaacG/irssi-scripts',
created => '2013/02/23',
);
# Bindings
Irssi::signal_add_last( 'event 322', \&list_event );
Irssi::signal_add_last( 'event 323', \&list_end );
Irssi::signal_add_last( 'notifylist event', \&list_start );
my %list;
sub list_start {
%list = {};
}
sub list_event {
my ( $server, $data, $server_name ) = @_;
my ( $meta, $more ) = split ( / :/, $data, 2 );
my ( $nick, $name, $size ) = split ( / /, $meta, 3 );
$list{ $name }{'size'} = $size;
$more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/;
my $modes = $1;
$list{ $name }{'desc'} = $2;
$modes =~ s/ +$//;
$list{ $name }{'modes'} = $modes;
}
sub list_end {
for my $name ( sort { $list{ $a }{'size'} <=> $list{ $b }{'size'} } keys %list ) {
my $msg = sprintf (
"%d %s: %s (%s)",
$list{ $name }{'size'},
$name,
$list{ $name }{'desc'},
$list{ $name }{'modes'}
);
Irssi::print ( $msg, MSGLEVEL_CRAP );
}
}