diff options
| author | ailin-nemui | 2016-12-09 07:56:54 +0100 | 
|---|---|---|
| committer | GitHub | 2016-12-09 07:56:54 +0100 | 
| commit | 4fa07671dd5c4b12e6cb8f7294fd5996901693e8 (patch) | |
| tree | 62842fc83499c0a298712a8334115a3008e5cdf3 | |
| parent | 08d91ab1b2b2a38b49530544c4d1013501028f6f (diff) | |
| parent | 4d704c971074017215867b054c80c26517a4e1c4 (diff) | |
| download | scripts.irssi.org-4fa07671dd5c4b12e6cb8f7294fd5996901693e8.tar.bz2 | |
Merge pull request #323 from IsaacG/new_listchan
New listsort.pl script: order /list by chan size
| -rw-r--r-- | scripts/listsort.pl | 60 | 
1 files changed, 60 insertions, 0 deletions
| diff --git a/scripts/listsort.pl b/scripts/listsort.pl new file mode 100644 index 0000000..81b9ab9 --- /dev/null +++ b/scripts/listsort.pl @@ -0,0 +1,60 @@ +use strict; +use warnings; +use Irssi; +use vars qw/$VERSION %IRSSI/; + +$VERSION = '0.1'; +%IRSSI = ( +    authors     => 'Isaac Good', +    name        => 'listsort', +    contact     => 'irssi@isaacgood.com', +    decsription => 'Sort the /list output by channel size', +    license     => 'BSD', +    url         => 'https://github.com/IsaacG/irssi-scripts', +    created     => '2013/02/23', +); + +# Bindings. Start of channel list, end of list, list item. +Irssi::signal_add_last('event 322', \&list_event); +Irssi::signal_add_last('event 323', \&list_end); + +# Store the channel list between IRC messages +my %list; + +# Store list info in the hash. +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; + +    my $modes = ''; +    $list{$name}{'desc'} = ''; +    if ($more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/) { +        $modes = $1; +        $list{$name}{'desc'} = $2; +    } + +    $modes =~ s/ +$//; +    $list{$name}{'modes'} = $modes; +} + +# Print out the whole list in sorted order. +sub list_end { +    for my $name (sort {$list{$a}{'size'} <=> $list{$b}{'size'}} keys %list) { +        my $mode = $list{$name}{'modes'}; +        $mode = " ($mode)" if ($mode); +        my $msg = sprintf ( +            "%d %s: %s%s", +            $list{$name}{'size'}, +            $name, +            $list{$name}{'desc'}, +            $mode +        ); + +        Irssi::print($msg, MSGLEVEL_CRAP); +    } +    # Drop the hash values; no point in holding them in memory. +    %list = (); +} + | 
