summaryrefslogtreecommitdiffstats
path: root/scripts/nopl.pl
blob: 2cf794ea95ad91104fb343f8a4c6c5470e5b87b3 (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
# nopl.pl
#
# Removes polish national diacritic characters from received msgs on irc, 
# replacing them with their corresponding letters. Can be used against 
# ISO-8859-2 and Windows-1250 character sets.
#
# Settings:
#
#    nopl_replace: How to notify you that letters have been changed. Default 
#                  is "<pl>text</pl>", where "text" is replaced with the 
#                  message.
#
# Thanks to James <james@jamesoff.net> for his nocaps.pl script on which 
# I have based my nopl (I don't know perl :)).

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;

$VERSION = '1.00';
%IRSSI = (
	authors		=> 'Adam Wysocki',
	contact		=> 'gophi <at> efnet.pl',
	name		=> 'nopl',
	description	=> 'Replaces polish national characters with their corresponding letters',
	license		=> 'Public Domain',
	url		=> 'http://www.gophi.rotfl.pl/',
	changed		=> '10 May 2005 16.12.32',
);


sub have_polish_chars {
	my ($msg) = @_;

	# only pl-letters
	$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;

	# if it has pl-letters, return 1 else return 0
	return 1 if length($msg);

	return 0;
}

# main event handler
sub pl_message {
	my ($server, $data, $nick, $address) = @_;
	my ($target, $msg) = split(/ :/, $data, 2);

	return if (!have_polish_chars($msg));

	# bleh, a line contains pl-chars
	$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/;

	my $replacement = Irssi::settings_get_str('pl_replace');
	$replacement =~ s/text/$msg/;

	# display it
	Irssi::signal_emit('event privmsg', ($server, "$target :$replacement", $nick, $address));

	# and stop
	Irssi::signal_stop();
}

Irssi::signal_add('event privmsg', 'pl_message');
Irssi::settings_add_str('misc', 'pl_replace', "<pl>text</pl>");