/var/www/www.irssi.org-old/scripts/html/auto_whois.pl


   1 # /WHOIS all the users who send you a private message.
   2 # v0.9 for irssi by Andreas 'ads' Scherbaum
   3 # idea and some code taken from autowhois.pl from Timo Sirainen
   4 use Irssi;
   5 use vars qw($VERSION %IRSSI); 
   6 
   7 $VERSION = "0.9";
   8 %IRSSI = (
   9     authors	=> "Andreas \'ads\' Scherbaum",
  10     contact	=> "ads\@ufp.de",
  11     name	=> "auto_whois",
  12     description	=> "/WHOIS all the users who send you a private message.",
  13     license	=> "GPL",
  14     url		=> "http://irssi.org/",
  15     changed	=> "2004-02-10",
  16     changes	=> "v0.9: don't /WHOIS if query exists for the nick already"
  17 );
  18 
  19 # History:
  20 #  v0.9: don't /WHOIS if query exists for the nick already
  21 #        now we store all nicks we have seen in the last 10 minutes
  22 
  23 my @seen = ();
  24 
  25 sub msg_private_first {
  26   my ($server, $msg, $nick, $address) = @_;
  27 
  28   # go through every stored connection and remove, if timed out
  29   my $time = time();
  30   my ($connection);
  31   my @new = ();
  32   foreach $connection (@seen) {
  33     if ($connection->{lasttime} >= $time - 600) {
  34       # is ok, use it
  35       push(@new, $connection);
  36       # all timed out connections will be dropped
  37     } 
  38   }
  39   @seen = @new;
  40 }
  41 
  42 sub msg_private {
  43   my ($server, $msg, $nick, $address) = @_;
  44 
  45   # look, if we already know this connection
  46   my ($connection, $a);
  47   my $known_to_us = 0;
  48   for ($a = 0; $a <= $#seen; $a++) {
  49     $connection = $seen[$a];
  50     # the lc() works not exact, because irc uses another charset
  51     if ($connection->{server} eq $server->{address} and $connection->{port} eq $server->{port} and lc($connection->{nick}) eq lc($nick)) {
  52       $known_to_us = 1;
  53       # mark as refreshed
  54       $seen[$a]->{lasttime} = time();
  55       last;
  56     }
  57   }
  58 
  59   if ($known_to_us == 1) {
  60     # all ok, return
  61     return;
  62   }
  63 
  64   # now store the new connection
  65   $connection = {};
  66   # store our own server data here
  67   $connection->{server} = $server->{address};
  68   $connection->{port} = $server->{port};
  69   # and the nick who queried us
  70   $connection->{nick} = $nick;
  71   $connection->{lasttime} = time();
  72   $connection->{starttime} = time();
  73   push(@seen, $connection);
  74 
  75   $server->command("whois $nick");
  76 }
  77 
  78 Irssi::signal_add_first('message private', 'msg_private_first');
  79 Irssi::signal_add('message private', 'msg_private');