Created
October 14, 2014 11:53
-
-
Save Ajnasz/e4074653d3320e6a4404 to your computer and use it in GitHub Desktop.
# Replace annoying emojis. You can see them on slack, for example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# noemoji.pl | |
# | |
# Replace annoying emojis. You can see them on slack, for example. | |
use strict; | |
use vars qw($VERSION %IRSSI); | |
use Irssi; | |
$VERSION = '1.0'; | |
%IRSSI = ( | |
authors => 'Lajos Koszti', | |
contact => '[email protected]', | |
name => 'noemjoi', | |
description => 'Replaces emojis from messages', | |
license => 'Public Domain', | |
url => 'https://ajnasz.hu', | |
); | |
sub replaceEmojis { | |
my ($msg) = @_; | |
my $replace = { | |
'smile' => ':D', | |
'simple_smile' => ':)', | |
'dizzy_face' => 'XO', | |
'disappointed' => ':(' | |
}; | |
for (keys %$replace) { | |
$msg =~ s/:$_:/$replace->{$_}/g; | |
} | |
return $msg; | |
} | |
sub hasEmoji { | |
my ($msg) = @_; | |
if ($msg =~ m/:[a-zA-Z_]+:/) { | |
return 1; | |
} | |
return 0; | |
} | |
#main event handler | |
sub caps_message { | |
my ($server, $data, $nick, $address) = @_; | |
my ($target, $msg) = split(/ :/, $data,2); | |
if (hasEmoji($msg)) { | |
my $replacement = replaceEmojis($msg); | |
#re-emit the signal to make Irssi display it | |
Irssi::signal_emit('event privmsg', ($server, "$target :$replacement", $nick, $address)); | |
#and stop | |
Irssi::signal_stop(); | |
} | |
} | |
Irssi::signal_add('event privmsg', 'caps_message'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment