This script displays a nicklist on the top of your irssi-window. Since it uses the split function of irssi, it works without any external programs.
1 #!/usr/bin/perl 2 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 use strict; 17 use Irssi; 18 my %IRSSI = ( 19 'authors' => 'Haui', 20 'contact' => 'haui45@web.de', 21 'description' => 'nicklist for irssi', 22 'license' => 'GPL', 23 'version' => '0.1', 24 'bugs' => 'yep :D' 25 ); 26 27 my @array; 28 my $string; 29 my $nicklist = ""; 30 my $nicklistheight = 2; 31 sub init { 32 my $current = Irssi::active_win()->{refnum}; #save the current window 33 Irssi::command("window new"); #create a new window 34 Irssi::command("window size $nicklistheight"); # height of our nicklist 35 Irssi::command("window name nicklist"); #nicklist identifier 36 Irssi::command("window number 99"); #nicklist number 37 $nicklist = Irssi::window_find_name("nicklist"); 38 Irssi::command("window $current"); 39 } 40 sub update { 41 my $witem = Irssi::active_win()->{active}; #get the active windowitem 42 if($witem->{type} ne "CHANNEL"){ #clear the nicklist, if we're 43 $nicklist->command("clear"); #not in a channel 44 return; 45 } 46 $string =""; 47 @array = $witem->nicks(); #read in the nicks of the channel 48 foreach(@array){ 49 my $tmp=""; 50 if($_->{op} == 1){ # 51 $tmp = "\@"; # 52 } #build the actual nicklist 53 elsif($_->{voice} == 1){ # 54 $tmp = "+"; # 55 } # 56 else { # 57 $tmp = "#"; # 58 } # 59 # 60 $tmp .= $_->{nick}; # 61 # 62 $string .= " " . $tmp; # 63 chomp $string; # 64 } 65 chomp $string; 66 my @sorted = sort {lc substr($a,1, length($a)-1) cmp 67 lc substr($b, 1, length($b)-1)} split(" ", $string); 68 $string = join(" ", @sorted); 69 $string =~ s/#//g; 70 $nicklist->command("clear"); 71 $nicklist->command("echo $string"); 72 73 $string = ""; 74 } 75 sub part { 76 my ($info1, $channel, $nick) = @_; 77 my $witem = Irssi::active_win()->{active}; 78 if ($witem->{name} ne $channel){ 79 return; 80 } 81 if($witem->{type} ne "CHANNEL"){ 82 $nicklist->command("clear"); 83 return; 84 } 85 $string =""; 86 @array = $witem->nicks(); 87 foreach(@array){ 88 my $tmp=""; 89 if($_->{op} == 1){ 90 $tmp = "\@"; 91 } 92 elsif($_->{voice} == 1){ 93 $tmp = "+"; 94 } 95 else { 96 $tmp = "#"; 97 } 98 $tmp .= $_->{nick}; 99 100 $string .= " " . $tmp unless $_->{nick} eq $nick; 101 chomp $string; 102 } 103 chomp $string; 104 my @sorted = sort {lc substr($a,1, length($a)-1) cmp 105 lc substr($b, 1, length($b)-1)} split(" ", $string); 106 $string = join(" ", @sorted); 107 $string =~ s/#//g; 108 $nicklist->command("clear"); 109 $nicklist->command("echo $string"); 110 111 $string = ""; 112 } 113 sub quit { 114 my ($server, $nick) = @_; 115 my $witem = Irssi::active_win()->{active}; 116 if($witem->{type} ne "CHANNEL"){ 117 return; 118 } 119 $string =""; 120 @array = $witem->nicks(); 121 foreach(@array){ 122 my $tmp=""; 123 if($_->{op} == 1){ 124 $tmp = "\@"; 125 } 126 elsif($_->{voice} == 1){ 127 $tmp = "+"; 128 } 129 else { 130 $tmp = "#"; 131 } 132 $tmp .= $_->{nick}; 133 134 $string .= " " . $tmp unless $_->{nick} eq $nick; 135 chomp $string; 136 } 137 chomp $string; 138 my @sorted = sort {lc substr($a,1, length($a)-1) cmp 139 lc substr($b, 1, length($b)-1)} split(" ", $string); 140 $string = join(" ", @sorted); 141 $string =~ s/#//g; 142 $nicklist->command("clear"); 143 $nicklist->command("echo $string"); 144 $string = ""; 145 } 146 147 148 sub close { 149 my ($command, $args) = @_; 150 if($command =~ m/script load nicklist/i){ #prevent irssi from creating multiple nicklist windows 151 $nicklist->destroy(); 152 } 153 if ($command =~ m/script unload nicklist/i){ #destroy the nicklist window when unloading the script 154 $nicklist->destroy(); 155 } 156 } 157 158 init(); 159 update(); 160 161 Irssi::signal_add('window changed', 'update'); #user changes the current window, e.g. by pressing alt+2 162 Irssi::signal_add('channel joined', 'update'); #user joined a channel 163 Irssi::signal_add('send command', 'close'); #user unloads the script 164 Irssi::signal_add('message join', 'update'); #someone joined the channel 165 Irssi::signal_add('message part', 'part'); #someone left the channel 166 Irssi::signal_add('message kick', 'part'); #etc... 167 Irssi::signal_add('nick mode changed', 'update'); # 168 Irssi::signal_add('message own_nick', 'update'); # 169 Irssi::signal_add('message nick', 'update'); # 170 Irssi::signal_add('message quit', 'quit'); # 171