html/bitlbee_nick_change-pre-3.0.pl


   1 use strict;
   2 use vars qw($VERSION %IRSSI);
   3 
   4 $VERSION = '1.2';
   5 %IRSSI = (
   6     authors	=> 'Tijmen "timing" Ruizendaal',
   7     contact	=> 'tijmen.ruizendaal@gmail.com',
   8     name	=> 'bitlbee_nick_change-pre-3.0',
   9     description	=> 'Shows an IM nickchange in an Irssi way. (in a query and in the bitlbee channel). (For bitlbee 1.2.x)',
  10     license	=> 'GPLv2',
  11     url		=> 'http://the-timing.nl/stuff/irssi-bitlbee',
  12     changed	=> '2006-10-27',
  13 );
  14 
  15 my $bitlbee_channel = "&bitlbee";
  16 my $bitlbee_server_tag = "localhost";
  17 
  18 Irssi::signal_add_last 'channel sync' => sub {
  19         my( $channel ) = @_;
  20         if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){
  21                 $bitlbee_server_tag = $channel->{server}->{tag};
  22                 $bitlbee_channel = $channel->{name};
  23         }
  24 };
  25 
  26 get_channel();
  27 
  28 sub get_channel {
  29         my @channels = Irssi::channels();
  30         foreach my $channel(@channels) {
  31                 if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") {
  32                         $bitlbee_channel = $channel->{name};
  33                         $bitlbee_server_tag = $channel->{server}->{tag};
  34 			return 1;
  35                 }
  36         }
  37 	return 0;
  38 }
  39 
  40 sub message {
  41   my ($server, $msg, $nick, $address, $target) = @_;
  42   if($server->{tag} eq $bitlbee_server_tag) {
  43     if($msg =~ /User.*changed name to/) {
  44       $nick = $msg;
  45       $nick =~ s/.* - User `(.*)' changed name to.*/$1/;
  46       my $window = $server->window_find_item($nick);  
  47       
  48       if ($window) {
  49         $window->printformat(MSGLEVEL_CRAP, 'nick_change',$msg);
  50         Irssi::signal_stop();
  51       } else {
  52         my $window = $server->window_find_item($bitlbee_channel);
  53         $window->printformat(MSGLEVEL_CRAP, 'nick_change',$msg);
  54         Irssi::signal_stop();
  55       }
  56     }
  57   }    
  58 }
  59 
  60 Irssi::signal_add_last ('message public', 'message');
  61 
  62 Irssi::theme_register([
  63   'nick_change', '$0'
  64  ]);