-
Notifications
You must be signed in to change notification settings - Fork 235
/
bitlbee_nick_change.pl
72 lines (65 loc) · 2.36 KB
/
bitlbee_nick_change.pl
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
65
66
67
68
69
70
71
72
use strict;
use Data::Dumper;
use vars qw($VERSION %IRSSI);
$VERSION = '1.3';
%IRSSI = (
authors => 'Tijmen "timing" Ruizendaal',
name => 'BitlBee_nick_change',
description => 'Shows an IM nickchange in an Irssi way. (in a query and in the bitlbee channel). (For bitlbee 3.0+)',
license => 'GPLv2',
url => 'http://the-timing.nl/stuff/irssi-bitlbee',
changed => '2010-07-28'
);
my $bitlbee_server; # server object
my @control_channels; # mostly: &bitlbee, &facebook etc.
init();
sub init { # if script is loaded after connect
my @servers = Irssi::servers();
foreach my $server(@servers) {
if( $server->isupport('NETWORK') eq 'BitlBee' ){
$bitlbee_server = $server;
my @channels = $server->channels();
foreach my $channel(@channels) {
if( $channel->{mode} =~ /C/ ){
push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels);
}
}
}
}
}
# if connect after script is loaded
Irssi::signal_add_last('event 005' => sub {
my( $server ) = @_;
if( $server->isupport('NETWORK') eq 'BitlBee' ){
$bitlbee_server = $server;
}
});
# if new control channel is synced after script is loaded
Irssi::signal_add_last('channel sync' => sub {
my( $channel ) = @_;
if( $channel->{mode} =~ /C/ && $channel->{server}->{tag} eq $bitlbee_server->{tag} ){
push @control_channels, $channel->{name} unless (grep $_ eq $channel->{name}, @control_channels);
}
});
# BEGIN bitlbee_nick_change.pl
sub event_notice {
my ($server, $msg, $nick, $address, $target) = @_;
if( $server->{tag} eq $bitlbee_server->{tag} && $msg =~ /.*Changed name to.*/ ){
my $friendly_name = $msg;
$friendly_name =~ s/.*Changed name to `(.*)'.*/$1/;
my $window = $server->window_find_item($nick);
if ($window) {
$window->printformat(MSGLEVEL_CRAP, 'nick_change', $nick, $address, 'changed name to `'.$friendly_name.'`');
Irssi::signal_stop();
} else {
# TODO find control channel where this user is located and display the notice there
#my $window = $server->window_find_item($bitlbee_channel);
#$window->printformat(MSGLEVEL_CRAP, 'nick_change', $nick, $address, 'changed name to `'.$friendly_name.'`');
#Irssi::signal_stop();
}
}
};
Irssi::signal_add_last('message irc notice', 'event_notice');
Irssi::theme_register(['nick_change', '{channick_hilight $0} [$1] $2']);
# END bitbee_nick_change.pl