#!/usr/bin/perl
#
# by Jan Krüger aka jast

# quick help:
# /wat [<av. number of wats> [<av. length of wats> [<av. deviation>]]]

use strict;

use vars qw($VERSION %IRSSI);
$VERSION = "2003080400";
%IRSSI = (
    authors     => "Jan 'jast' Krueger",
    contact     => 'jast@heapsort.de',
    name        => "Waaaat",
    description => "goes to great lengths to express non-understanding",
    license     => "GPLv2",
    url         => "http://jast.heapsort.de/dev/irssi.html",
    changed     => "$VERSION",
);


use Irssi;
use POSIX;

sub generatewat {
    my ($words, $letters, $dev) = @_[0..2];
	 my ($awords, $aletters);

    $words = 5 if(!$words);
    $letters = 4 if(!$letters);
	 $dev = 6 if(!$dev);

    $awords = $words + floor(rand($dev) - $dev * 0.5);
    $awords = 1 if($awords < 1);

    my $result = '';
    for(1..$awords) {
	     $aletters = $letters + floor(rand($dev) - $dev * 0.5);
	     $aletters = 1 if($aletters < 1);
        $result .= 'w' . ('a' x $aletters) . 't ';
    }

    return $result;
}

sub cmd_wat ($$$) {
    my ($arg, $server, $witem) = @_;
    if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) {
	$witem->command('MSG '.$witem->{name}.' '.generatewat($arg ? split(/ /, $arg) : ''));
    } else {
	print CLIENTCRAP "%B>>%n ".generatewat($arg ? split(/ /, $arg) : '');
    }
}

Irssi::command_bind('wat', \&cmd_wat);
