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 use strict;
38 use vars qw($VERSION
39
40 use utf8;
41 use Encode qw(encode decode is_utf8);
42 use encoding 'UTF-8', STDOUT => 'UTF-8', STDIN => 'UTF-8';
43
44 use Irssi;
45 $VERSION = '$Id: ulatrus.pl,v 1.00 2011/09/12 19:20:00 Sergej Qkowlew $';
46
47 authors => 'Sergej Qkowlew',
48 contact => 'sergej_at_irssi_qkowlew1@qkowlew.org',
49 name => 'ulatrus',
50 description => 'Script Changes latin1 ÀÁÂÃÄŨÆ...þÿ to russian АБВГДЕЁ...юя UTF-8',
51 license => 'GPL',
52 );
53
54 my $stripped_out = 0;
55 my $stripped_in = 0;
56
57 sub ulatrus_out {
58 if(Irssi::settings_get_bool('ulatrus_strip_out') && !$stripped_out) {
59 my $ulatrus_tag = Irssi::settings_get_str('ulatrus_tag_out');
60
61 my $debug=Irssi::settings_get_bool('ulatrus_debug');
62
63 my $ulatrus_lat = Irssi::settings_get_str('ulatrus_lat');
64 my $ulatrus_rus = Irssi::settings_get_str('ulatrus_rus');
65 if (length($ulatrus_lat) != length($ulatrus_rus)) {
66 if ($debug) {
67 Irssi::print("`$ulatrus_lat' and `$ulatrus_rus' hasn't same length");
68 }
69 }
70 else {
71 my $emitted_signal = Irssi::signal_get_emitted();
72 my ($msg, $dummy1, $dummy2) = @_;
73
74 if ($debug) {
75 Irssi::print("signal emitted: $emitted_signal");
76 }
77 Encode::_utf8_on($msg);
78 if ( $msg =~ /[$ulatrus_lat]/ ) {
79 if ($debug) {
80 Irssi::print("outgoing contains ulatrus: $msg");
81 }
82 eval "\$msg =~ tr/$ulatrus_lat/$ulatrus_rus/;";
83 Encode::_utf8_on($msg);
84 $msg = $msg . ' ' . $ulatrus_tag;
85 Encode::_utf8_on($msg);
86 $stripped_out=1;
87
88 Irssi::signal_emit("$emitted_signal", $msg, $dummy1, $dummy2 );
89 Irssi::signal_stop();
90 $stripped_out=0;
91 }
92 }
93 }
94 }
95
96 sub ulatrus_in {
97 if(Irssi::settings_get_bool('ulatrus_strip_in') && !$stripped_in) {
98 my $ulatrus_tag = Irssi::settings_get_str('ulatrus_tag_in');
99
100 my $debug=Irssi::settings_get_bool('ulatrus_debug');
101
102 my $ulatrus_lat = Irssi::settings_get_str('ulatrus_lat');
103 my $ulatrus_rus = Irssi::settings_get_str('ulatrus_rus');
104 if (length($ulatrus_lat) != length($ulatrus_rus)) {
105 if ($debug) {
106 Irssi::print("`$ulatrus_lat' and `$ulatrus_rus' hasn't same length");
107 }
108 }
109 else {
110 my $emitted_signal = Irssi::signal_get_emitted();
111
112 my ($dummy0, $text, $dummy3, $dummy4, $dummy5) = @_;
113 if ($debug) {
114 Irssi::print("signal emitted: $emitted_signal");
115 }
116 Encode::_utf8_on($text);
117 if ( $text =~ /[$ulatrus_lat]/ ) {
118 if ($debug) {
119 Irssi::print("incoming contains ulatrus: $text");
120 }
121 if ($debug) {
122 Irssi::print("text=$text");
123 }
124 #no idea why w/o eval doesn't work:
125 eval "\$text =~ tr/$ulatrus_lat/$ulatrus_rus/;";
126 Encode::_utf8_on($text);
127 $text = $text . ' ' . $ulatrus_tag;
128 Encode::_utf8_on($text);
129 $stripped_in=1;
130
131 if ($debug) {
132 Irssi::print("text=$text");
133 }
134 Irssi::signal_emit("$emitted_signal", $dummy0, $text, $dummy3, $dummy4, $dummy5 );
135 Irssi::signal_stop();
136 $stripped_in=0;
137 }
138 }
139 }
140 }
141
142 #main():
143
144 #default settings /set ulatrus_in ON && ulatrus_out OFF:
145 Irssi::settings_add_bool('lookandfeel', 'ulatrus_strip_in', 1);
146 Irssi::settings_add_bool('lookandfeel', 'ulatrus_strip_out', 0);
147
148 #define the default tags for the filtered text:
149 Irssi::settings_add_str('lookandfeel', 'ulatrus_tag_in', '[ulatrus]');
150 Irssi::settings_add_str('lookandfeel', 'ulatrus_tag_out', '[ulatrus]');
151
152 #define which chars will be changed:
153 Irssi::settings_add_str('lookandfeel', 'ulatrus_lat', "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
154 Irssi::settings_add_str('lookandfeel', 'ulatrus_rus', "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя");
155
156 #define wheather debug or not (default OFF):
157 Irssi::settings_add_bool('lookandfeel', 'ulatrus_debug', 0);
158
159 #filters:
160 #incoming filters:
161 Irssi::signal_add_first('server event', 'ulatrus_in');
162
163 #output filters:
164 Irssi::signal_add_first('send command', 'ulatrus_out');
165 #Irssi::signal_add_first('message own_public', 'ulatrus_out');
166 #Irssi::signal_add_first('message own_private', 'ulatrus_out');
167
168 #startup info:
169 Irssi::print("latin1 to cp1251 unicode stripper by Qkowlew based on accent.pl by Tamas SZERB toma\@rulez.org");
170 Irssi::print("Version: $VERSION");
, as shown below in the list of files. Do
link, since this is subject to change and can break easily.