Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Created October 14, 2014 11:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ajnasz/e4074653d3320e6a4404 to your computer and use it in GitHub Desktop.
Save Ajnasz/e4074653d3320e6a4404 to your computer and use it in GitHub Desktop.
# Replace annoying emojis. You can see them on slack, for example.
# 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 => 'ajnasz@ajnasz.hu',
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