html/nickmix_pasky.pl


   1 # Nickmix - Perturbates given nick (or just a word) in certain way.
   2 #
   3 # $Id: nickmix.pl,v 1.2 2002/02/09 22:13:12 pasky Exp pasky $
   4 
   5 
   6 use strict;
   7 
   8 use vars qw ($VERSION %IRSSI $rcsid);
   9 
  10 $rcsid = '$Id: nickmix.pl,v 1.2 2002/02/09 22:13:12 pasky Exp pasky $';
  11 ($VERSION) = '$Revision: 1.2 $' =~ / (\d+\.\d+) /;
  12 %IRSSI = (
  13           name        => 'nickmix',
  14           authors     => 'Petr Baudis',
  15           contact     => 'pasky@ji.cz',
  16           url         => 'http://pasky.ji.cz/~pasky/dev/irssi/',
  17           license     => 'GPLv2, not later',
  18           description => 'Perturbates given nick (or just a word) in certain way.'
  19          );
  20 
  21 
  22 use Irssi;
  23 use Irssi::Irc;
  24 
  25 
  26 sub cmd_nickmix {
  27   my ($data) = @_;
  28   my %letters; # letters hash - value is count of letters
  29   my $vstr; # vowels string
  30   my $str; # resulting string
  31 
  32   # First load the whole thing into letters hash
  33   map { $letters{$_}++; } split(//, $data);
  34 
  35   # Now take the (most of/all) vowels away and compose string from them
  36   foreach (qw(a e i o u y)) {
  37     my $c = int rand($letters{$_} * 4 + 1);
  38 
  39     $c = $letters{$_} if ($c > $letters{$_});
  40     $letters{$_} -= $c;
  41 
  42     for (; $c; $c--) {
  43       # Either add or prepend
  44       if (rand(2) < 1) {
  45 	$vstr .= $_;
  46       } else {
  47 	$vstr = $_ . $vstr;
  48       }
  49     }
  50   }
  51 
  52   # Position of the $vstr..
  53   my $vpos = int rand (3);
  54 
  55   $str = $vstr if (not $vpos);
  56 
  57   # Now take the rest and do the same ;)
  58   foreach (keys %letters) { for (; $letters{$_}; $letters{$_}--) {
  59     # Either add or prepend
  60     if (rand(2) < 1) {
  61       $str .= $_;
  62     } else {
  63       $str = $_ . $str;
  64     }
  65   } }
  66 
  67   if ($vpos == 1) { $str .= $vstr; } elsif ($vpos == 2) { $str = $vstr . $str; }
  68 
  69   Irssi::print "$data -> $str";
  70 }
  71 
  72 Irssi::command_bind("nickmix", "cmd_nickmix");
  73 
  74 Irssi::print("Nickmix $VERSION loaded...");