html/xlist.pl


   1 #!/usr/bin/perl
   2 
   3 # (c) Matthäus 'JonnyBG' Wander <jbg@swznet.de>
   4 
   5 # Usage: Simply use /list as you always do
   6 
   7 use strict;
   8 use vars qw($VERSION %IRSSI);
   9 
  10 $VERSION = '1.00';
  11 %IRSSI = (
  12     authors => 'Matthäus \'JonnyBG\' Wander',
  13     contact => 'jbg@swznet.de',
  14     name => 'xlist',
  15     description => 'Better readable listing of channel names',
  16     license => 'GPLv2',
  17     url => 'http://jbg.swznet.de/xlist/',
  18 );
  19 
  20 use Irssi;
  21 
  22 my %xlist = ();
  23 
  24 sub collect {
  25     my ($server, $data) = @_;
  26     
  27     my (undef, $channel, $users, $topic) = split(/\s/, $data, 4);
  28     $topic = substr($topic, 1);
  29     
  30     $xlist{$channel} = [ $users, $topic ];
  31 }
  32 
  33 sub list {
  34     my ($data, $server) = @_;
  35     %xlist = ();
  36     
  37     print "%K[%n".$server->{'tag'}."%K]%n %B<-->%n xlist";
  38 }
  39 
  40 sub show {
  41     my ($server) = @_;
  42     my ($printstring, $channel);
  43 
  44     for $channel ( sort { ${ $xlist{$b} }[0] <=> ${ $xlist{$a} }[0] } keys %xlist ) {
  45 	$printstring =	"%K[%n" . $server->{'tag'} . "%K]%n " .
  46 			sprintf("%4d", ${ $xlist{$channel} }[0]) .
  47 			" " . $channel;
  48 
  49 	if (length ${ $xlist{$channel} }[1] > 0 ) {
  50 	    $printstring .= " %B->%n ". ${ $xlist{$channel} }[1];
  51 	}
  52 
  53 	print $printstring;
  54     }
  55     
  56     %xlist = ();
  57     
  58     print "%K[%n".$server->{'tag'}."%K]%n %B<-->%n End of xlist";
  59 }
  60 
  61 Irssi::command_bind('list', \&list);
  62 Irssi::signal_add('event 322', \&collect);
  63 Irssi::signal_add('event 323', \&show);
  64 
  65 print "%B<-->%n xlist v$VERSION: Simply use /list as you always do";