From d5063cf314ba7c08e9441f128735ba4169a56cd6 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 17:19:56 -0800 Subject: New listsort.pl script: order /list by chan size --- scripts/listsort.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 scripts/listsort.pl (limited to 'scripts') diff --git a/scripts/listsort.pl b/scripts/listsort.pl new file mode 100644 index 0000000..f615cd9 --- /dev/null +++ b/scripts/listsort.pl @@ -0,0 +1,59 @@ +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); +Irssi::signal_add_last('notifylist event', \&list_start); + +# Store the channel list between IRC messages +my %list; + +# When we get a start-list, create an empty list. +sub list_start { + %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; + + $more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/; + my $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 $msg = sprintf ( + "%d %s: %s (%s)", + $list{$name}{'size'}, + $name, + $list{$name}{'desc'}, + $list{$name}{'modes'} + ); + + Irssi::print($msg, MSGLEVEL_CRAP); + } + # Drop the hash values; no point in holding them in memory. + delete @list{keys %list}; +} + -- cgit v1.2.3 From 2d83df01cbda6946f84c1bba1c01c34bd05e9570 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 18:44:35 -0800 Subject: Fix build errors --- scripts/listsort.pl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/listsort.pl b/scripts/listsort.pl index f615cd9..deb8770 100644 --- a/scripts/listsort.pl +++ b/scripts/listsort.pl @@ -1,3 +1,5 @@ +use strict; +use warnings; use Irssi; use vars qw/$VERSION %IRSSI/; @@ -15,16 +17,10 @@ $VERSION = '0.1'; # 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); -Irssi::signal_add_last('notifylist event', \&list_start); # Store the channel list between IRC messages my %list; -# When we get a start-list, create an empty list. -sub list_start { - %list = {}; -} - # Store list info in the hash. sub list_event { my ($server, $data, $server_name) = @_; @@ -32,9 +28,12 @@ sub list_event { my ($nick, $name, $size) = split (/ /, $meta, 3); $list{$name}{'size'} = $size; - $more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/; - my $modes = $1; - $list{$name}{'desc'} = $2; + my $modes = ''; + $list{$name}{'desc'} = ''; + if ($more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/) { + $modes = $1; + $list{$name}{'desc'} = $2; + } $modes =~ s/ +$//; $list{$name}{'modes'} = $modes; @@ -43,12 +42,14 @@ sub list_event { # 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)", + "%d %s: %s%s", $list{$name}{'size'}, $name, $list{$name}{'desc'}, - $list{$name}{'modes'} + $mode ); Irssi::print($msg, MSGLEVEL_CRAP); -- cgit v1.2.3 From a276aad4819e7d3a2c24cc2e621d7fce0dcac574 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 18:46:15 -0800 Subject: Drop remaining tabs --- scripts/listsort.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/listsort.pl b/scripts/listsort.pl index deb8770..8e6e02d 100644 --- a/scripts/listsort.pl +++ b/scripts/listsort.pl @@ -29,11 +29,11 @@ sub list_event { $list{$name}{'size'} = $size; my $modes = ''; - $list{$name}{'desc'} = ''; + $list{$name}{'desc'} = ''; if ($more =~ /^[^[]*\[([^]]*)\][^ ]* *([^ ].*)$/) { - $modes = $1; - $list{$name}{'desc'} = $2; - } + $modes = $1; + $list{$name}{'desc'} = $2; + } $modes =~ s/ +$//; $list{$name}{'modes'} = $modes; @@ -42,8 +42,8 @@ sub list_event { # 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 $mode = $list{$name}{'modes'}; + $mode = " ($mode)" if ($mode); my $msg = sprintf ( "%d %s: %s%s", $list{$name}{'size'}, -- cgit v1.2.3 From 4d704c971074017215867b054c80c26517a4e1c4 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Wed, 7 Dec 2016 11:32:54 -0800 Subject: Reset the list hash cleanly. Avoid deleting key by key. --- scripts/listsort.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/listsort.pl b/scripts/listsort.pl index 8e6e02d..81b9ab9 100644 --- a/scripts/listsort.pl +++ b/scripts/listsort.pl @@ -55,6 +55,6 @@ sub list_end { Irssi::print($msg, MSGLEVEL_CRAP); } # Drop the hash values; no point in holding them in memory. - delete @list{keys %list}; + %list = (); } -- cgit v1.2.3