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.
Asked
Active
Viewed 146 times
1
-
The documentation of what? You would have to create a mapping. Possibly there is already a module on CPAN that does something similar. Going from (`U+1F604: SMILING FACE WITH OPEN MOUTH AND SMILING EYES`) to `:D` should be fairly simple. You build a lookup table with a hash. – simbabque Apr 20 '17 at 13:25
-
The perl part would be relatively easy, although I'm not really a perl programmer. It's the irssi part that's difficult! I tried creating a plugin that would transform all incoming messages, but it's hard to know/see where I would need to hook in exactly. Also, it's not clear what format the string is in. – Michel Apr 20 '17 at 14:00
-
Actually, I found a good example, but implementing a 'no-op' filter already gives me issues: irssi complains about "critical query_find: assertion 'nick != NULL' failed", so there might be a bug I'm triggering somewhere... – Michel Apr 20 '17 at 14:12
1 Answers
2
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!

Michel
- 603
- 6
- 15