Translate unicode code points to specific strings in irssi

157 Views Asked by At

Is there a command/setting/script to translate certain unicode code points to a different string in irssi? To be concrete, I would like to translate the emoji code points to ASCII smileys, as my font doesn't support them. This is mainly useful with the facebook messenger plugin. I've tried creating a perl script for this, but the documentation is somewhat sparse.

1

There are 1 best solutions below

0
Michel On BEST ANSWER

So, the problem was with my irssi being somewhat outdated, the bug has been fixed, and it is actually pretty simple to accomplish. For anyone wanting to do the same, you need something along these lines:

my %hash = (
    0x1f600 => ':)',
    # add smileys to taste here
);

sub transform ($$$$$$) {
    my ($server, $msg, $nick, $address, $target) = @_;
    my $transformed = '';

    $msg = decode('utf8', $msg);

    for (my $l = length($msg), my $i = 0; $i < $l; $i++) {
        my $chr = substr($msg, $i, 1);
        my $code = ord($chr);

        if (defined $hash{$code}) {
            $transformed .= $hash{$code};
        }
        else {
            $transformed .= $chr;
        }
    }
    Irssi::signal_continue($server, $transformed, $nick, $address, $target);
}

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

Note that I'm definitely not a Perl-expert, so there might be smarter/better ways to achieve this!