-
Notifications
You must be signed in to change notification settings - Fork 6
/
facebook_bitlbee_rename.pl
73 lines (59 loc) · 1.69 KB
/
facebook_bitlbee_rename.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
73
# See this script's repository at
# http://github.com/avar/irssi-bitlbee-facebook-rename for further
# information.
use strict;
use warnings;
use Irssi;
use Irssi::Irc;
use Text::Unidecode;
use Encode qw(decode);
our $VERSION = '0.02';
our %IRSSI = (
authors => do { use utf8; 'Ævar Arnfjörð Bjarmason' },
contact => '[email protected]',
name => 'facebook-bitlbee-rename',
description => 'Rename XMPP chat.facebook.com contacts in bitlbee to human-readable names',
license => 'GPL',
);
my $bitlbeeChannel = "&bitlbee";
my %nicksToRename = ();
sub message_join
{
# "message join", SERVER_REC, char *channel, char *nick, char *address
my ($server, $channel, $nick, $address) = @_;
my ($username, $host) = split /@/, $address;
if ($host eq 'chat.facebook.com' and $channel =~ m/$bitlbeeChannel/ and $nick =~ m/$username/)
{
$nicksToRename{$nick} = $channel;
$server->command("whois -- $nick");
}
}
sub whois_data
{
my ($server, $data) = @_;
my ($me, $nick, $user, $host) = split(" ", $data);
if (exists($nicksToRename{$nick}))
{
my $channel = $nicksToRename{$nick};
delete($nicksToRename{$nick});
my $ircname = substr($data, index($data,':')+1);
$ircname = munge_nickname( $ircname );
if ($ircname ne $nick)
{
$server->command("msg $channel rename $nick $ircname");
$server->command("msg $channel save");
}
}
}
sub munge_nickname
{
my ($nick) = @_;
$nick = decode('utf8', $nick);
$nick =~ s/[- ]/_/g;
$nick = unidecode($nick);
$nick =~ s/[^A-Za-z0-9-]//g;
$nick = substr $nick, 0, 24;
return $nick;
}
Irssi::signal_add_first 'message join' => 'message_join';
Irssi::signal_add_first 'event 311' => 'whois_data';