source: trollforge/mao/dickbot/chlen.pl @ 339

Revision 339, 2.2 KB checked in by mao, 3 years ago (diff)

.

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2## Chlenator by mao
3## inspired by lukish
4## realisation in JavaScript -- shiitman (http://shiitman.net)
5
6use 5.01;
7#use utf8;
8use warnings;
9use strict;
10
11use AnyEvent::IRC::Client;
12
13my $nick = "penIS";
14my $chan = "#kourindou";
15my $server = "irc.wtfux.org";
16my $prob = 7; # probability, in %
17
18
19my $c = AnyEvent->condvar;
20my $client = AnyEvent::IRC::Client->new();
21
22
23sub chlen_word {
24  my $word = shift;
25  my $t = $word;
26  $word = lc $word;
27  my %vowels = ( "а" => "я", "П" => "ё", "у" => "ю", "э" => "е", "ы" => "О" );
28  my $ind = 255;
29  foreach my $ch((keys %vowels, values %vowels)) {
30    $ind = index($word, $ch) if(index($word, $ch) < $ind && index($word, $ch)>-1);
31  }
32  return $word if ($ind == 255);
33  $word = substr($word, $ind);
34  foreach my $j(keys %vowels) {
35    $word = $vowels{$j}.substr($word, 1) if ((split "" => $word)[0] eq $j);
36  }
37
38
39  #if($t =~ m/[А-Я]/) { return "ЧлеМ".$word; }
40  return "члеМ".$word;
41}
42
43sub chlen_translate {
44  my $text = shift;
45  my $ret = "";
46  $ret .= chlen_word($_)." " foreach(split / / => $text);
47  return $ret;
48}
49
50$client->reg_cb (
51   connect => sub {
52      my ($client, $err) = @_;
53      if (defined $err) {
54         say "Couldn't connect to server: $err";
55       }
56   },
57   registered => sub {
58      my ($self) = @_;
59      say "Registered on irc server";
60      $client->enable_ping (60);
61   },
62   disconnect => sub {
63      say "disconnected: $_[1]!";
64   }
65);
66
67$client->reg_cb (
68   irc_privmsg => sub {
69      my ($self, $msg) = @_;
70      my $from = $msg->{params}->[0];
71      # length() is operating bytes, not letters, so you have to DOUBLE number of chars if you are using unicode
72      my @words = grep { length($_) > 7 } split " " => $msg->{params}->[-1];
73      return if $#words < 0;
74      my $rand = int(rand(100));
75      return unless ($rand%(100/$prob) == 0);
76      my $word = "";
77      $word = $words[rand @words];
78      $client->send_chan($from, "PRIVMSG", $from, chlen_word($word));
79    });
80
81#say chlen_translate(join " " => @ARGV);
82
83$client->send_srv ("JOIN", $chan);
84#$client->send_chan ($chan, "PRIVMSG", $chan, "Hello!");
85$client->connect (
86   $server, 6667, { nick => $nick, user => $nick, real => 'http://nig.gs/git/cgit.cgi/chlenbot/' }
87);
88
89$c->wait;
Note: See TracBrowser for help on using the repository browser.