Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use Net::Jabber::Bot;
- use Log::Log4perl qw(:easy);
- use Encode;
- use utf8;
- InitLog4Perl();
- my @rooms = ('qutim');
- our $botName;
- $botName = "аввакум";
- our $owner;
- $owner = "torkve";
- our @repos;
- @repos = ('qutim', 'oscar', 'jabber', 'mrim');
- our %commitMessages;
- our %botActions;
- $botActions{'git'} = sub {sayTo(@_, "доступные репозитории:\ncgit - ядро\nigit - ICQ\njgit - Jabber\nmgit - MRIM")};
- $botActions{'cgit'} = sub {getGit(@_, "qutim")};
- $botActions{'igit'} = sub {getGit(@_, "oscar")};
- $botActions{'jgit'} = sub {getGit(@_, "jabber")};
- $botActions{'mgit'} = sub {getGit(@_, "mrim")};
- $botActions{'благослови'} = sub {sayTo(@_, "благословляю тебя, дитя моё. Иди и больше не греши.")};
- $botActions{'bless'} = sub {sayTo(@_, "благословляю тебя, дитя моё. Иди и больше не греши.")};
- $botActions{'попингуй'} = sub {sayTo(@_, "сам попингуй")};
- $botActions{'ping'} = \&getPing;
- $botActions{'пинг'} = \&getPing;
- $botActions{'.'} = \&getPing;
- $botActions{'литургия'} = \&getQuit;
- $botActions{'аминь'} = sub {sayTo(@_, "воистину аминь")};
- $botActions{'amen'} = sub {sayTo(@_, "воистину аминь")};
- my %rooms_and_responses;
- foreach my $room (@rooms)
- {
- my $responses = "аввакум:|протопоп:|брат:|святой отец:|bot:|";
- my @response_array = split(/\|/, $responses);
- push @response_array, "";
- $rooms_and_responses{$room} = \@response_array;
- }
- my $bot = new Net::Jabber::Bot(
- server => 'jabber.ru',
- conference_server => 'conference.jabber.ru',
- port => 5222,
- safety_mode => 0,
- username => 'torkvemada',
- password => '',
- alias => $botName,
- message_function => \&callbackBotMessage,
- background_function => \&callbackBackgroundChecks,
- loop_sleep_time => 20,
- process_timeout => 20,
- forums_and_responses => \%rooms_and_responses,
- ignore_server_messages => 1,
- ignore_self_messages => 1,
- out_messages_per_second => 1,
- max_message_size => 1000,
- max_messages_per_hour => 1000
- );
- foreach my $room (@rooms)
- {
- $bot->SendGroupMessage($room, "Мир вам, дети мои");
- callbackBackgroundChecks(\$bot, 0);
- }
- $bot->Start();
- print "Bye-bye!";
- exit;
- sub callbackBotMessage
- {
- my %bot_message_hash = @_;
- foreach my $pararam (%bot_message_hash)
- {
- print $pararam."\n";
- }
- $bot_message_hash{'sender'} = $bot_message_hash{'from_full'};
- $bot_message_hash{'sender'} =~ s{^.+\/([^\/]+)$}{$1};
- return unless $bot_message_hash{'sender'} ne $botName;
- my($command, @options) = split(' ', $bot_message_hash{'body'});
- $command = lc($command);
- DEBUG("Got command: $command");
- if ($bot_message_hash{'body'} =~ /п[иu]т[оo]н|п[еа]йт[оo]н|python/i)
- {
- $bot_message_hash{'bot_object'}->SendGroupMessage($bot_message_hash{'reply_to'}, $bot_message_hash{'sender'}.": Покайся, грешник! Никогда не произноси этого слова! Пейтон будет гореть в аду!");
- }
- elsif ($bot_message_hash{'body'} =~ /[aаoо]н[eеиu]м[eеэ]/i)
- {
- $bot_message_hash{'bot_object'}->SendGroupMessage($bot_message_hash{'reply_to'}, $bot_message_hash{'sender'}.": окстись, несчастный! Онемэ - удел содомитов и мужеложцев!");
- }
- elsif (defined $botActions{$command})
- {
- $botActions{$command}->(\%bot_message_hash, @options);
- }
- }
- sub callbackBackgroundChecks
- {
- my $bot = shift;
- my $counter = shift;
- foreach my $dir (@repos)
- {
- $commitMessages{$dir} = decode_utf8(`cd $dir >/dev/null 2>&1; git pull >/dev/null 2>&1; git log -1; cd .. >/dev/null 2>&1;`);
- $commitMessages{$dir} =~ s/^\s+//s;
- $commitMessages{$dir} =~ s/\s+$//s;
- }
- }
- sub getGit
- {
- DEBUG("Requested Git info");
- my %bot_message_hash = %{shift @_};
- my $repo = shift;
- my $bot_object = $bot_message_hash{'bot_object'};
- my $reply_to = $bot_message_hash{'reply_to'};
- $bot_object->SendGroupMessage($reply_to, $commitMessages{$repo});
- }
- sub sayTo
- {
- my %bot_message_hash = %{shift @_};
- my $bot_object = $bot_message_hash{'bot_object'};
- my $reply_to = $bot_message_hash{'reply_to'};
- my $author = $bot_message_hash{'sender'};
- my $message = shift;
- $bot_object->SendGroupMessage($reply_to, "$author: $message");
- }
- sub getPing
- {
- my %bot_message_hash = %{shift @_};
- my $target = shift || $bot_message_hash{'sender'};
- if ($target eq $botName)
- {
- my $author = $bot_message_hash{'sender'};
- $bot_message_hash{'bot_object'}->SendGroupMessage($bot_message_hash{'reply_to'}, "$author: я отвечаю на запросы мгновенно, с Божьей помощью, ведомый рукой Господа.");
- return;
- }
- DEBUG("Trying to get ping from $target");
- my $address = $bot_message_hash{'from_full'};
- $address =~ s#^(.*?)/.*#$1#;
- $address .= "/".$target;
- $bot_message_hash{'bot_object'}->RegisterPing($address, $target, \&getPing_sendMessage, \&getPing_sendError, \%bot_message_hash);
- }
- sub getPing_sendMessage
- {
- my $pingTime = shift;
- my $target = shift;
- my %bot_messager = %${shift @_};
- sayTo(\%bot_messager, "дитя божье $target среагировало за $pingTime секунд");
- }
- sub getPing_sendError
- {
- my $target = shift;
- my %bot_messager = %${shift @_};
- sayTo(\%bot_messager, "неизвестен мне $target, раб ли он Божий али нехристь?");
- }
- sub getQuit
- {
- my %bot_message_hash = %{shift @_};
- if ($bot_message_hash{'sender'} eq $owner)
- {
- sayTo(\%bot_message_hash, "спешу молиться!");
- exit;
- }
- else
- {
- sayTo(\%bot_message_hash, "всё врёшь, окаянный, не началась ещё!");
- }
- }
- sub InitLog4Perl
- {
- my $debug_level = 'DEBUG';
- my $layout = '%d %p (%L): %m%n';
- my $config_file = <<"CONFIG_DATA";
- log4perl.appender.Screen = Log::Log4perl::Appender::Screen
- log4perl.appender.Screen.stderr = 0
- log4perl.appender.Screen.layout = PatternLayout
- log4perl.appender.Screen.layout.ConversionPattern = $layout
- log4perl.category = $debug_level, Screen
- CONFIG_DATA
- Log::Log4perl->init(\$config_file);
- $| = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement