html/chanshare.pl


   1 # /CHANSHARE - display people who are in more than one channel with you
   2 # for irssi 0.7.98
   3 #
   4 # /CHANSHARE [ircnets ...] [#channels ...]
   5 #
   6 # This program is free software; you can redistribute it and/or
   7 # modify it under the terms of the GNU General Public License
   8 # as published by the Free Software Foundation; either version 2
   9 # of the License, or (at your option) any later version.
  10 # 
  11 # This program is distributed in the hope that it will be useful,
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 # GNU General Public License for more details.
  15 # 
  16 # You should have received a copy of the GNU General Public License
  17 # along with this program; if not, write to the Free Software
  18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19 # 
  20 # Version 0.1 - Timo Sirainen tss@iki.fi
  21 #	Initial stalker.pl 
  22 # Version 0.2 - Chad Armstrong chad@analogself.com
  23 #	Added multiserver support
  24 #	Added keying by nick AND hostname. "nick (fw.corp.com)"
  25 #	Prints to current active window now.
  26 # Version 0.21 - Timo Sirainen tss@iki.fi
  27 #       Removed printing to active window - if you want it, remove your
  28 #       status window.
  29 # Version 0.3 - Timo Sirainen tss@iki.fi
  30 #       Supports for limiting searches only to specified ircnets and
  31 #       channels. Some cleanups..
  32 
  33 use Irssi;
  34 use vars qw($VERSION %IRSSI); 
  35 $VERSION = "0.3";
  36 %IRSSI = (
  37     authors	=> "Timo \'cras\' Sirainen",
  38     contact	=> "tss\@iki.fi",
  39     name	=> "chan share",
  40     description	=> "/CHANSHARE - display people who are in more than one channel with you",
  41     license	=> "Public Domain",
  42     url		=> "http://irssi.org/",
  43     changed	=> "2002-03-04T22:47+0100",
  44     changes	=> "v0.3 - Timo Sirainen tss\@iki.fi: Supports for limiting searches only to specified ircnets and channels. Some cleanups.."
  45 );
  46 
  47 sub cmd_chanshare {
  48   my ($data, $server, $channel) = @_;
  49   my (%channicks, @show_channels, @show_ircnets);
  50 
  51   # get list of channels and ircnets
  52   @show_channels = ();
  53   @show_ircnets = ();
  54   foreach my $arg (split(" ", $data)) {
  55     if ($server->ischannel($arg)) {
  56       push @show_channels, $arg;
  57     } else {
  58       push @show_ircnets, $arg;
  59     }
  60   }
  61 
  62   my @checkservers = ();
  63   if (scalar(@show_ircnets) == 0) {
  64     # check from all servers
  65     @checkservers = Irssi::servers();
  66   } else {
  67     # check from specified ircnets
  68     foreach my $s (Irssi::servers()) {
  69       foreach my $n (@show_ircnets) {
  70 	if ($s->{chatnet} eq $n) {
  71 	  push @checkservers, $s;
  72 	  last;
  73 	}
  74       }
  75     }
  76   }
  77 
  78   foreach my $s (@checkservers) {
  79     my $mynick = $s->{nick};
  80     foreach my $channel ($s->channels()) {
  81       foreach my $nick ($channel->nicks()) {
  82 	my ($user, $host) = split(/@/, $nick->{host});
  83 	my $nickhost = $nick->{nick}." ($host)";
  84 	my @list = ();
  85 	next if ($nick->{nick} eq $mynick);
  86 
  87 	@list = @{$channicks{$nickhost}} if (@{$channicks{$nickhost}});
  88 #	Irssi::print($nickhost);
  89 	push @list, $channel->{name};
  90 	$channicks{$nickhost} = [@list];
  91       }
  92     }
  93   }
  94 
  95   Irssi::print("Nicks of those who share your #channels:");
  96   foreach my $nick (keys %channicks) {
  97     my @channels = @{$channicks{$nick}};
  98     if (@channels > 1) {
  99       my $chanstr = "";
 100       my $ok = scalar(@show_channels) == 0;
 101       foreach $channel (@channels) {
 102 	if (!$ok) {
 103 	  # check the show_channels list..
 104 	  foreach my $c (@show_channels) {
 105 	    if ($channel eq $c) {
 106 	      $ok = 1;
 107 	      last;
 108 	    }
 109 	  }
 110 	}
 111 	$chanstr .= "$channel ";
 112       }
 113       Irssi::print("$chanstr : $nick") if ($ok);
 114     }
 115   }
 116 }
 117 
 118 Irssi::command_bind('chanshare', 'cmd_chanshare');