From d6d0b2a93d7a83f9b54eab39640af53b16611eff Mon Sep 17 00:00:00 2001 From: eleksir Date: Sat, 14 Nov 2020 14:19:05 +0300 Subject: [PATCH] =?UTF-8?q?Implement=20!version,=20!ver,=20!help,=20!?= =?UTF-8?q?=D0=BF=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jabberbot.pm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/jabberbot.pm b/lib/jabberbot.pm index 9bd2d15..6b0ff7b 100644 --- a/lib/jabberbot.pm +++ b/lib/jabberbot.pm @@ -38,7 +38,6 @@ sub __background_checks { sub __new_bot_message { my %hash = @_; my $bot = $hash{bot_object}; -# my $text = encode('utf-8', $hash{body}); my $text = $hash{body}; if ($hash{'type'} eq 'groupchat') { @@ -49,14 +48,12 @@ sub __new_bot_message { if ($text =~ /^$qname$/) { $bot->SendGroupMessage($hash{'reply_to'}, 'Чего тебе?'); } elsif ($text =~ /^$qname[\,|\:]? (.+)/) { -# $bot->SendGroupMessage($hash{'reply_to'}, $hailo->learn_reply(decode('utf-8', $1))); $bot->SendGroupMessage($hash{'reply_to'}, $hailo->learn_reply($1)); } elsif ($text eq "$c->{jabberbot}->{aleesa}->{csign}пинг") { $bot->SendGroupMessage($hash{'reply_to'}, 'Понг.'); } elsif ($text eq "$c->{jabberbot}->{aleesa}->{csign}ping") { $bot->SendGroupMessage($hash{'reply_to'}, 'Pong.'); } elsif (substr($text, 0, 1) eq $c->{jabberbot}->{aleesa}->{csign}) { -# $text = decode('utf-8', $text); if (substr($text, 1, 3) eq 'rum') { eval { @@ -100,7 +97,7 @@ sub __new_bot_message { "/me наливает абсент в стопку. Смочив кубик сахара в абсенте кладёт его на дырявую ложечку и пожигает. Как только пламя потухнет, $c->{jabberbot}->{aleesa}->{mucname} размешивает оплавившийся кубик в абсенте и подносит стопку " .(split(/\//,$hash{from_full}))[1] . '.' ); }; - } elsif ((substr($text, 1, 2) eq 'w ') || (substr($text, 1, 2) eq 'п ')) { + } elsif (substr($text, 1, 2) eq 'w ' || substr($text, 1, 2) eq 'п ') { my $city = substr($text, 2); eval { @@ -109,12 +106,24 @@ sub __new_bot_message { weather($city) =~ tr/\n/ /r ); }; + } elsif ((length($text) == 8 && substr($text, 1, 8) eq 'version') || (length ($text) == 4 && substr($text, 1, 4) eq 'ver')) { + $bot->SendGroupMessage($hash{'reply_to'}, 'Версия нуль.чего-то_там.чего-то_там'); + } elsif ((length ($text) == 5 && substr($text, 1, 5) eq 'help') || (length ($text) == 7 && substr($text, 1, 7) eq 'помощь')) { + my $rate = $bot->message_delay(); + # rate limit this :) specially for jabber.ru + $bot->message_delay($rate * 5); + $bot->SendGroupMessage($hash{'reply_to'}, "!help | !помощь - это сообщение"); + $bot->SendGroupMessage($hash{'reply_to'}, "!w город | !п город - погода в городе"); + $bot->SendGroupMessage($hash{'reply_to'}, "!ping | !пинг - попинговать бота"); + $bot->SendGroupMessage($hash{'reply_to'}, "!some_brew - выдать соответсвующий напиток, на донный момент бармен умеет выдать rum, vodka, beer, tequila, whisky, absinthe"); + $bot->SendGroupMessage($hash{'reply_to'}, "!ver|version - написать что-то про версию ПО"); + $bot->message_delay($rate); } else { - #$hailo->learn($text); + $hailo->learn($text); return; } } else { - #$hailo->learn($text); + $hailo->learn($text); return; } } elsif ($hash{'type'} eq 'chat') { @@ -129,7 +138,7 @@ sub __new_bot_message { sub run_jabberbot { $hailo = Hailo->new( brain => $c->{jabberbot}->{aleesa}->{brain}, - order => 3 + order => 2 ); my %conflist = ();