/var/www/www.irssi.org-old/scripts/html/nopl.pl
1 # nopl.pl
2 #
3 # Removes polish national diacritic characters from received msgs on irc,
4 # replacing them with their corresponding letters. Can be used against
5 # ISO-8859-2 and Windows-1250 character sets.
6 #
7 # Settings:
8 #
9 # nopl_replace: How to notify you that letters have been changed. Default
10 # is "<pl>text</pl>", where "text" is replaced with the
11 # message.
12 #
13 # Thanks to James <james@jamesoff.net> for his nocaps.pl script on which
14 # I have based my nopl (I don't know perl :)).
15
16 use strict;
17 use vars qw($VERSION %IRSSI);
18
19 use Irssi;
20
21 $VERSION = '1.00';
22 %IRSSI = (
23 authors => 'Adam Wysocki',
24 contact => 'gophi <at> efnet.pl',
25 name => 'nopl',
26 description => 'Replaces polish national characters with their corresponding letters',
27 license => 'Public Domain',
28 url => 'http://www.gophi.rotfl.pl/',
29 changed => '10 May 2005 16.12.32',
30 );
31
32
33 sub have_polish_chars {
34 my ($msg) = @_;
35
36 # only pl-letters
37 $msg =~ s/[^\xF3\xEA\xB6\xB1\xBF\xB3\xE6\xBC\xCA\xF1\xA1\xD3\xA3\xA6\xAC\xAF\xD1\xC6\x9C\xB9\x9F\xA5\x8C\x8F]+//g;
38
39 # if it has pl-letters, return 1 else return 0
40 return 1 if length($msg);
41
42 return 0;
43 }
44
45 # main event handler
46 sub pl_message {
47 my ($server, $data, $nick, $address) = @_;
48 my ($target, $msg) = split(/ :/, $data, 2);
49
50 return if (!have_polish_chars($msg));
51
52 # bleh, a line contains pl-chars
53 $msg =~ tr/\xF3\xEA\xB6\xB1\xBF\xB3\xE6\xBC\xCA\xF1\xA1\xD3\xA3\xA6\xAC\xAF\xD1\xC6\x9C\xB9\x9F\xA5\x8C\x8F/oesazlczEnAOLSZZNCsazASZ/;
54
55 my $replacement = Irssi::settings_get_str('pl_replace');
56 $replacement =~ s/text/$msg/;
57
58 # display it
59 Irssi::signal_emit('event privmsg', ($server, "$target :$replacement", $nick, $address));
60
61 # and stop
62 Irssi::signal_stop();
63 }
64
65 Irssi::signal_add('event privmsg', 'pl_message');
66 Irssi::settings_add_str('misc', 'pl_replace', "<pl>text</pl>");