diff options
| author | ailin-nemui | 2016-09-14 08:25:42 +0200 |
|---|---|---|
| committer | GitHub | 2016-09-14 08:25:42 +0200 |
| commit | bee419a36dd02eaed92d96e929887d994b62db3d (patch) | |
| tree | f2879ee303dc5df272ada479b758412dbb143b83 /scripts/anames.pl | |
| parent | cee3648e306c18dbba32cdb2ec74a1458b5da59e (diff) | |
| parent | dad794ef0ffc1f10212f82e41dd91abf071731e3 (diff) | |
| download | scripts.irssi.org-bee419a36dd02eaed92d96e929887d994b62db3d.tar.bz2 | |
Merge pull request #305 from tslocum/anames
Improve anames nick prefix sorting
Diffstat (limited to 'scripts/anames.pl')
| -rw-r--r-- | scripts/anames.pl | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/scripts/anames.pl b/scripts/anames.pl index 385ffe6..b3af564 100644 --- a/scripts/anames.pl +++ b/scripts/anames.pl @@ -23,6 +23,8 @@ # Thanks to Dirm and Chris62vw for the Perl help and coekie for writing the # evil code to sort the nicklist by the alphabet and rank in nicklist.pl # +# 1.7 - Improved nick prefix sorting (tslocum) +# # 1.6 - optional support for unicode nicknames, realnames script, # formattable summary line (default away colour changed!) (Nei) # @@ -60,7 +62,7 @@ use List::Util qw(min max); use vars qw($VERSION %IRSSI); -$VERSION = '1.6'; # 6eb152135b1bc6d +$VERSION = '1.7'; %IRSSI = ( authors => 'Matt "f0rked" Sparks, Miklos Vajna', contact => 'ms+irssi@quadpoint.org', @@ -199,6 +201,27 @@ sub cmd_anames } } +sub prefix_index +{ + my ($nick) = @_; + my $index = 999; + my $prefixes = Irssi::server_find_tag($tmp_server)->get_nick_flags(); + if (!$prefixes) { + $prefixes = "~&@%+"; + } + + my $prefix_index; + foreach my $prefix (split("", $nick->{'prefixes'})) { + if ($prefix) { + $prefix_index = index($prefixes, $prefix); + if ($prefix_index > -1) { + $index = min($prefix_index, $index); + } + } + } + + return $index; +} sub print_anames { @@ -224,22 +247,11 @@ sub print_anames my $nick = shift; $prefer_real && length $nick->{'realname'} ? $nick->{'realname'} : $nick->{'nick'} }; - # sorting from nicklist.pl - foreach my $nick (sort {($a->{'op'}?'1':$a->{'halfop'}?'2':$a->{'voice'}?'3':$a->{'other'}>32?'0':'4').lc($_real->($a)) - cmp ($b->{'op'}?'1':$b->{'halfop'}?'2':$b->{'voice'}?'3':$b->{'other'}>32?'0':'4').lc($_real->($b))} $channel->nicks()) { + foreach my $nick (sort {prefix_index($a) <=> prefix_index($b) || lc($a->{'nick'}) cmp lc($b->{'nick'})} $channel->nicks()) { my $realnick = $_real->($nick); my $gone = $nick->{'gone'}; - - my $prefix; - if ($nick->{'other'}) { - $prefix = chr $nick->{'other'}; - } elsif ($nick->{'op'}) { - $prefix = "@"; - } elsif ($nick->{'halfop'}) { - $prefix = "%"; - } elsif ($nick->{'voice'}) { - $prefix = "+"; - } else { + my $prefix = substr($nick->{'prefixes'}, 0, 1); + if (!$prefix) { $prefix = " "; } |
