#!/usr/bin/perl

use CGI;

print <<EOF;
Content-type: text/html
X-Frame-Options: DENY
Content-Security-Policy: frame-ancestors 'none'

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>Drunk speech tester</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>

<form method="POST" action="">
Speech: <input type="text" size="30" name="speech">
<input type="submit" value="Speak!">
</form>
EOF

#<pre>
#replace 's' or 'ss' with 'sh' - once per word.
#	Oh, also you'd have to check for any accidental 'shit's, of course.
#
#sometimes repeat short words - once per sentence
#	Yesh, althought it'sh, it'sh, it'sh mildly amushing anyway.
#
#add random *hic*
#
#occasional words in randomly shouty capitals
#</pre>
#
#EOF

my $qw = new CGI;
if ($qw->param('speech')) {
	my $wordcount = 0;
	my $hic = 0;
	my $repeat = 0;
	my $shout = 0;
	my $output = "";
	foreach my $word (split /\s+/, $qw->param('speech')) {
		my $origword = $word;

		$wordcount ++;

		if ($word =~ /ss/) {
			$word =~ s/ss/sh/;
		} elsif ($word =~ /s[^h]/) {
			$word =~ s/s([^h])/sh\1/;
		}
		if ($word =~ /shit/) { $word = $origword; }

		if (($word =~ /[aeiou]/) && (int(rand(8)) == 1)) {
			$word =~ s/([aeiou])/\1\1\1/s;
		}

		if ((int(rand(9)) == 1) && ($hic < ($wordcount / 4))) {
			$hic ++;
			$output .= " *hic* ";
		}
		if (int(rand(8)) == 2) {
			$word = uc($word);
		}
#		if ((int(rand(7)) == 1) && (length($word) < 5) && !$repeat) {
#			$output .= ", ".$word . ", ". $word . ",";
#			$repeat = 1;
#		}

		$output .= " " . $word;
	}
	print "<p><b>$output</b></p>";
}

print <<EOF;
</body>
</html>
EOF
