File: bitlbee_nick_change.pl

package info (click to toggle)
irssi-scripts 20100512
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,420 kB
  • ctags: 2,479
  • sloc: perl: 58,204; sh: 171; makefile: 33
file content (64 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use vars qw($VERSION %IRSSI);

$VERSION = '1.2';
%IRSSI = (
    authors	=> 'Tijmen "timing" Ruizendaal',
    contact	=> 'tijmen.ruizendaal@gmail.com',
    name	=> 'bitlbee_nick_change',
    description	=> 'Shows an IM nickchange in an Irssi way. (in a query and in the bitlbee channel).',
    license	=> 'GPLv2',
    url		=> 'http://the-timing.nl/stuff/irssi-bitlbee',
    changed	=> '2006-10-27',
);

my $bitlbee_channel = "&bitlbee";
my $bitlbee_server_tag = "localhost";

Irssi::signal_add_last 'channel sync' => sub {
        my( $channel ) = @_;
        if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){
                $bitlbee_server_tag = $channel->{server}->{tag};
                $bitlbee_channel = $channel->{name};
        }
};

get_channel();

sub get_channel {
        my @channels = Irssi::channels();
        foreach my $channel(@channels) {
                if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") {
                        $bitlbee_channel = $channel->{name};
                        $bitlbee_server_tag = $channel->{server}->{tag};
			return 1;
                }
        }
	return 0;
}

sub message {
  my ($server, $msg, $nick, $address, $target) = @_;
  if($server->{tag} eq $bitlbee_server_tag) {
    if($msg =~ /User.*changed name to/) {
      $nick = $msg;
      $nick =~ s/.* - User `(.*)' changed name to.*/$1/;
      my $window = $server->window_find_item($nick);  
      
      if ($window) {
        $window->printformat(MSGLEVEL_CRAP, 'nick_change',$msg);
        Irssi::signal_stop();
      } else {
        my $window = $server->window_find_item($bitlbee_channel);
        $window->printformat(MSGLEVEL_CRAP, 'nick_change',$msg);
        Irssi::signal_stop();
      }
    }
  }    
}

Irssi::signal_add_last ('message public', 'message');

Irssi::theme_register([
  'nick_change', '$0'
 ]);