| 1 | #!/usr/bin/perl |
|---|
| 2 | ## Chlenator by mao |
|---|
| 3 | ## inspired by lukish |
|---|
| 4 | ## realisation in JavaScript -- shiitman (http://shiitman.net) |
|---|
| 5 | |
|---|
| 6 | use 5.01; |
|---|
| 7 | #use utf8; |
|---|
| 8 | use warnings; |
|---|
| 9 | use strict; |
|---|
| 10 | |
|---|
| 11 | use AnyEvent::IRC::Client; |
|---|
| 12 | |
|---|
| 13 | my $nick = "fagot"; |
|---|
| 14 | my $chan = "#gapp"; |
|---|
| 15 | my $server = "irc.anonymuncule.com"; |
|---|
| 16 | my $prob = 40; # probability, in % |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | my $c = AnyEvent->condvar; |
|---|
| 20 | my $client = AnyEvent::IRC::Client->new(); |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | sub chlen_word { |
|---|
| 25 | my $word = shift; |
|---|
| 26 | my $t = $word; |
|---|
| 27 | $word = lc $word; |
|---|
| 28 | my @vowels = ("a","e","i","o","u"); |
|---|
| 29 | |
|---|
| 30 | my $ind = 255; |
|---|
| 31 | my @positions = (); |
|---|
| 32 | |
|---|
| 33 | my $offset; |
|---|
| 34 | |
|---|
| 35 | foreach my $ch(@vowels) { |
|---|
| 36 | $offset = -1; |
|---|
| 37 | while(index($word, $ch, $offset+1)>-1 && $offset < length($word)) { |
|---|
| 38 | $ind = index($word, $ch, $offset+1); |
|---|
| 39 | say $ch." - ".$offset." - ".$ind; |
|---|
| 40 | push @positions, $ind; |
|---|
| 41 | last if ($offset == $ind); |
|---|
| 42 | $offset = $ind; |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | return $word if ($ind == 255); |
|---|
| 46 | @positions = sort @positions; |
|---|
| 47 | $ind = $positions[1] if ($#positions > 0); |
|---|
| 48 | $word = substr($word, $ind); |
|---|
| 49 | |
|---|
| 50 | #say $word; |
|---|
| 51 | # for (my $j = 0; $j < 5; $j++) { |
|---|
| 52 | # if ((split // => $word)[0] eq $vowels[$j]) { |
|---|
| 53 | # $word = substr($word,1); |
|---|
| 54 | # } |
|---|
| 55 | # } |
|---|
| 56 | |
|---|
| 57 | if($t =~ m/[A-Z]/) { return "Dick".$word; } |
|---|
| 58 | return "dick".$word; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | sub chlen_translate { |
|---|
| 62 | my $text = shift; |
|---|
| 63 | my $ret = ""; |
|---|
| 64 | $ret .= chlen_word($_)." " foreach(split / / => $text); |
|---|
| 65 | return $ret; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | $client->reg_cb ( |
|---|
| 70 | connect => sub { |
|---|
| 71 | my ($client, $err) = @_; |
|---|
| 72 | if (defined $err) { |
|---|
| 73 | say "Couldn't connect to server: $err"; |
|---|
| 74 | } |
|---|
| 75 | }, |
|---|
| 76 | registered => sub { |
|---|
| 77 | my ($self) = @_; |
|---|
| 78 | say "Registered on irc server"; |
|---|
| 79 | $client->enable_ping (60); |
|---|
| 80 | }, |
|---|
| 81 | disconnect => sub { |
|---|
| 82 | say "disconnected: $_[1]!"; |
|---|
| 83 | } |
|---|
| 84 | ); |
|---|
| 85 | |
|---|
| 86 | $client->reg_cb ( |
|---|
| 87 | irc_privmsg => sub { |
|---|
| 88 | my ($self, $msg) = @_; |
|---|
| 89 | my $from = $msg->{params}->[0]; |
|---|
| 90 | my @words = grep { length($_) > 4 } split " " => $msg->{params}->[-1]; |
|---|
| 91 | return if $#words < 0; |
|---|
| 92 | my $rand = int(rand(100)); |
|---|
| 93 | return unless ($rand%(100/$prob) == 0); |
|---|
| 94 | my $word = ""; |
|---|
| 95 | $word = $words[rand @words]; |
|---|
| 96 | $client->send_chan($from, "PRIVMSG", $from, chlen_word($word)); |
|---|
| 97 | }); |
|---|
| 98 | |
|---|
| 99 | #say chlen_translate(join " " => @ARGV); |
|---|
| 100 | |
|---|
| 101 | $client->send_srv ("JOIN", $chan); |
|---|
| 102 | #$client->send_chan ($chan, "PRIVMSG", $chan, "dickbot here"); |
|---|
| 103 | $client->connect ( |
|---|
| 104 | $server, 6667, { nick => $nick, user => $nick, real => 'DICKBOT [HEAD] :: http://www.gnaa.eu/browser/trollforge/mao/dickbot' } |
|---|
| 105 | ); |
|---|
| 106 | |
|---|
| 107 | $c->wait; |
|---|