├── README.md └── facebook_bitlbee_rename.pl /README.md: -------------------------------------------------------------------------------- 1 | This is a irssi script to automatically issue bitlbee `rename` 2 | commands for nonsensical nicks like `u1359078110`, changing them into 3 | e.g. `AEvarArnfjord`. 4 | 5 | To do this it uses the 6 | [Text::Unidecode](http://search.cpan.org/perldoc?Text::Unidecode) 7 | module. You must install it for the script to work, either from CPAN 8 | or from your package manager. E.g. `aptitude install 9 | libtext-unidecode-perl` in Debian and Ubuntu. 10 | 11 | Additionally, Bitlbee itself must be configured to use `utf-8` as its 12 | `charset`. To find out if that's the case, do this in the `&bitlbee` 13 | channel: 14 | 15 | <@avar> set charset 16 | <@root> charset = `utf-8' 17 | 18 | If not, just set the charset to `utf-8` like so: 19 | 20 | <@avar> set charset utf-8 21 | <@root> charset = `utf-8' 22 | 23 | # Author 24 | 25 | This script is originally from 26 | [nowhere.dk](http://www.nowhere.dk/articles/facebook-chat-in-bitlbee) 27 | modified by Ævar Arnfjörð Bjarmason to support Unicode names. 28 | -------------------------------------------------------------------------------- /facebook_bitlbee_rename.pl: -------------------------------------------------------------------------------- 1 | # See this script's repository at 2 | # http://github.com/avar/irssi-bitlbee-facebook-rename for further 3 | # information. 4 | 5 | use strict; 6 | use warnings; 7 | use Irssi; 8 | use Irssi::Irc; 9 | use Text::Unidecode; 10 | use Encode qw(decode); 11 | 12 | our $VERSION = '0.02'; 13 | our %IRSSI = ( 14 | authors => do { use utf8; 'Ævar Arnfjörð Bjarmason' }, 15 | contact => 'avarab@gmail.com', 16 | name => 'facebook-bitlbee-rename', 17 | description => 'Rename XMPP chat.facebook.com contacts in bitlbee to human-readable names', 18 | license => 'GPL', 19 | ); 20 | 21 | my $bitlbeeChannel = "&bitlbee"; 22 | my %nicksToRename = (); 23 | 24 | sub message_join 25 | { 26 | # "message join", SERVER_REC, char *channel, char *nick, char *address 27 | my ($server, $channel, $nick, $address) = @_; 28 | my ($username, $host) = split /@/, $address; 29 | 30 | if ($host eq 'chat.facebook.com' and $channel =~ m/$bitlbeeChannel/ and $nick =~ m/$username/) 31 | { 32 | $nicksToRename{$nick} = $channel; 33 | $server->command("whois -- $nick"); 34 | } 35 | } 36 | 37 | sub whois_data 38 | { 39 | my ($server, $data) = @_; 40 | my ($me, $nick, $user, $host) = split(" ", $data); 41 | 42 | if (exists($nicksToRename{$nick})) 43 | { 44 | my $channel = $nicksToRename{$nick}; 45 | delete($nicksToRename{$nick}); 46 | 47 | my $ircname = substr($data, index($data,':')+1); 48 | 49 | $ircname = munge_nickname( $ircname ); 50 | 51 | if ($ircname ne $nick) 52 | { 53 | $server->command("msg $channel rename $nick $ircname"); 54 | $server->command("msg $channel save"); 55 | } 56 | } 57 | } 58 | 59 | sub munge_nickname 60 | { 61 | my ($nick) = @_; 62 | 63 | $nick = decode('utf8', $nick); 64 | $nick =~ s/[- ]/_/g; 65 | $nick = unidecode($nick); 66 | $nick =~ s/[^A-Za-z0-9-]//g; 67 | $nick = substr $nick, 0, 24; 68 | 69 | return $nick; 70 | } 71 | 72 | Irssi::signal_add_first 'message join' => 'message_join'; 73 | Irssi::signal_add_first 'event 311' => 'whois_data'; 74 | --------------------------------------------------------------------------------