summaryrefslogtreecommitdiffstats
path: root/scripts/rot13.pl
blob: 2b74fd7ef61ff800e95f7b92b47b915c318b4b39 (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
# rot13.pl
# Mariusz "Craig" Cie�la <craig at fish.mac.edu.pl>
# ROT13-encodes and decodes messages on the channel :)

use strict;

use vars qw($VERSION %IRSSI);

$VERSION = "2003121202";

%IRSSI = (
	authors		=>	"Mariusz 'Craig' Ciesla",
	contact		=>	"craig\@fish.mac.edu.pl",
	name		=>	"rot13",
	description	=>	"ROT13 encoding and reverse :)",
	license		=>	"GPLv2",
	changed		=>	"$VERSION",
	commands	=>	"rot13 unrot13"
);

use Irssi 20020324;

sub text2rot ($)
{
	my ($text) = @_;

	$text =~ y/N-ZA-Mn-za-m/A-Za-z/;

	return $text."  ";
}

sub rot2text ($)
{
	my ($text) = @_;

	$text =~ y/A-Za-z/N-ZA-Mn-za-m/;

	return $text;
}

sub rot13_decode ($$$)
{
	my ($server, $target, $text) = @_;
	
	return unless ($text =~ /(^|.*?)  /g);
	my $witem = $server->window_item_find($target);

	return unless ($witem);
	$witem->print("%B[ROT13]>>%n ".rot2text($1), MSGLEVEL_CLIENTCRAP);
}

sub cmd_rot13 ($$$)
{
	my ($arg, $server, $witem) = @_;

	if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY'))
	{
		$witem->command('MSG '.$witem->{name}.' '.text2rot($arg));
	} else {
		print CLIENTCRAP "%B>>%n ".text2rot($arg);
	}
}

sub cmd_unrot13 ($$$)
{
	my ($arg, $server, $witem) = @_;
	
	print CLIENTCRAP "%B>>%n ".rot2text($arg);
}

Irssi::command_bind('rot13',\&cmd_rot13);
Irssi::command_bind('unrot13',\&cmd_unrot13);

Irssi::signal_add('message public',sub {rot13_decode($_[0], $_[4], $_[1]);} );
Irssi::signal_add('message own_public',sub {rot13_decode($_[0], $_[2], $_[1]);});

print "%B>>%n ".$IRSSI{name}." ".$VERSION." loaded";