summaryrefslogtreecommitdiffstats
path: root/scripts/rud_emotes.pl
blob: de55cbaad19317ab66346d9a68d1636081ac9cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#    Copyright (C) 2016  Dawid Lekawski
#      contact: xxrud0lf@gmail.com
#
#       --- INFORMATION ---
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#       --- END OF INFORMATION ---
#
#     Emote script - replace :emote_name: in your sent messages into predefined 
#   emotes (mostly but not limited to unicode). Result is visible both for you
#   and channel/query target users.
#
#     Feel free to modify or add your own ones!
#
#      (that's a lot of "emote" word, isn't it?)
#
#   commands:
#
#   - /emotes   - shows list of emotes in status window
#
#   notes:
#
#   - script doesn't work with /msg target text; must be typed in a channel
#     or query window (from version 1.10 it works with /me command too)
#
#   - Ctrl+O (ascii 15) at the beggining of your text turns off emote replacing 
#     for this text
#
#   - remeber to escape "\" characters in emotes (just type it twice -> "\\"),
#       take a look at 'shrug' emote for reference
#
#
#
#   -- CHANGES: --
#
#   - script now works with /me command (action)
#
#   - moved text output messages into nice and clean theme_register
#
#

use strict;
use warnings;
use utf8;

use Irssi qw(signal_add signal_continue command_bind theme_register
	printformat);

our $VERSION = "1.10";
our %IRSSI = (
	authors		=> "Dawid 'rud0lf' Lekawski",
	contact		=> 'rud0lf/IRCnet; rud0lf/freenode; xxrud0lf@gmail.com',
	name		=> 'emotes script',
	description	=> 'Replaces :emote_name: text in your sent messages into pre-defined emotes (unicode mostly).',
	license		=> 'GPLv3',
	changed		=> 'Mon Nov 07 14:54:38 2016'
);

my $pattern = '';
my %emotes = (
	'huh', '°-°',
	'lenny', '( ͡° ͜ʖ ͡°)',
	'shrug', '¯\\_(ツ)_/¯',
	'smile', '☺',
	'sad', '☹',
	'heart', '♥',
	'note', '♪',
	'victory', '✌',
	'coffee', '☕',
	'kiss', '💋',
	'inlove', '♥‿♥',
	'annoyed', '(¬_¬)',
	'bear', 'ʕ•ᴥ•ʔ',
	'animal', '(•ω•)',
	'happyanimal', '(ᵔᴥᵔ)',
	'strong', 'ᕙ(⇀‸↼‶)ᕗ',
	'happyeyeroll', '◔ ⌣ ◔',
	'tableflip', '(╯°□°)╯︵ ┻━┻',
	'tableback', '┬──┬ ノ( ゜-゜ノ)',
	'tm', '™',
	'birdflip', '╭∩╮(-_-)╭∩╮',
	'lolshrug', '¯\\(°_o)/¯',
	'shades', '(⌐■_■)',
	'smoke', '🚬',
	'poop', '💩',
	'drops', '💦',
	'yuno', 'щ(゚Д゚щ)',
	'dead', '✖_✖',
	'wtf', '☉_☉',
	'disapprove', '๏̯͡๏',
	'wave', '(•◡•)/',
    'shock', '⊙▃⊙',
    'wink', '◕‿↼',
	'gift', '(´・ω・)っ由',
    'success', '(•̀ᴗ•́)و',
	'whatever', '◔_◔',
	'run', 'ᕕ(⚆ ʖ̯⚆)ᕗ',
	'rock', '(ツ)\m/'
);

sub init {
	theme_register([
		'rud_emotes_list', 'List of emotes:',
		'rud_emotes_emote', '* $[!15]0 : $1',
		'rud_emotes_total', 'Total of $0 emotes.'
]);  
  
	$pattern = join('|', keys %emotes);
	if ($pattern eq '') {
		$pattern = '!?';
	}
}

sub process_emotes {
	my ($line) = @_;
	
	# don't process line starting with Ctrl+O (ascii 15)
	if ($line =~ /^\x0f/) {
		return $line;
	}

	$line =~ s/:($pattern):/$emotes{$1}/g;

	return $line;
}

sub sig_send_text {
	my ($line, $server, $witem) = @_;

	return unless ($witem);
	return unless ($witem->{type} eq "CHANNEL" or $witem->{type} eq "QUERY");

	my $newline = process_emotes($line);
	signal_continue($newline, $server, $witem);
}

sub sig_command_me {
	my ($line, $server, $witem) = @_;

	return unless ($witem);
	return unless ($witem->{type} eq "CHANNEL" or $witem->{type} eq "QUERY");

	my $newline = process_emotes($line);
	signal_continue($newline, $server, $witem);	
}

sub cmd_emotes {
	my ($data, $server, $witem) = @_;

	printformat(MSGLEVEL_CLIENTCRAP, 'rud_emotes_list');
	foreach my $key (sort(keys %emotes)) {
		printformat(MSGLEVEL_CLIENTCRAP, 'rud_emotes_emote', $key, $emotes{$key});
	}	
	printformat(MSGLEVEL_CLIENTCRAP, 'rud_emotes_total', scalar(keys %emotes));
}

init();

signal_add("send text", "sig_send_text");
signal_add("command me", "sig_command_me");
command_bind("emotes", "cmd_emotes");