aboutsummaryrefslogtreecommitdiff
path: root/jumble.pl
blob: 79ac4faa04505d6f13d128c2feb2fdc03060c9b8 (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
#!/usr/bin/perl

# script was written ages ago (probably 2008 or earlier).

use warnings;
use strict;

use Irssi qw/command command_bind/;

our $VERSION = "0.1";
our %IRSSI = (
	authors     => 'Urchlay',
	contact     => 'Urchlay on NewNet',
	name        => 'jumble',
	description => 'Smiultae bad tpying',
	license     => 'Same as Perl',
	url         => 'none',
);

sub jumble {
	my ($text, $srv, $chan) = @_;
	my @words = split /\s+/, $text;

	for(@words) {
		if(length($_) > 2) {
			/(\W*\w)(\w+)(\w\W*)/;
			if($2) {
				my $start = $1;
				my $middle = $2;
				my $end = $3;

				my @letters = split "", $middle;
				for(0..$#letters-1) {
					($letters[$_], $letters[$_+1]) = ($letters[$_+1], $letters[$_])
						if rand > 0.5;
				}
				$_ = $start . join("", @letters) . $end;
			}
		}
	}

	$chan->command('MSG ' . $chan->{name} . ' ' . join(" ", @words));
}

command_bind("jumble", \&jumble);