1

4 Commits

4 changed files with 82 additions and 25 deletions

View File

@@ -1,5 +1,12 @@
# Aleesa-Telegram-bot - Telegram chatty bot # Aleesa-Telegram-bot - Telegram chatty bot
## Disclaimer
This version - 3 (something) - considered stable. It means that further
development of new features kind of frosen. Most effort will be targeted to
future 4-th version development. If you have some ideas or fixes to this version
feel free PR them, they will be merged as soon as being reviewed.
## About ## About
It is based on Perl modules [Telegram::Bot][1] and [Hailo][2] as conversation It is based on Perl modules [Telegram::Bot][1] and [Hailo][2] as conversation

View File

@@ -1,5 +1,16 @@
# Aleesa-Telegram-bot - Болтливый бот для Telegram # Aleesa-Telegram-bot - Болтливый бот для Telegram
## Дисклеймер
Эта версия бота за номером 3 (с мелочью) стабильная. Сие означает, что
дальнейшего развития функций в этой версии не предполагается. Конечно, возможны
исключения, но основной план - переключиться на 4-ю версию, куда планируется
перенести большинство функций 3-й версии.
Если у кого-то возникнут идеи относительно этой версии бота ставьте PR, я только
рад. Т.к. несмотря на то, что развитие этой версии слегка заморожено,
поддерживать её планируется до выхода в свет 4-й версии бота.
## Что это такое ## Что это такое
Это бот, основанный на перловых модулях [Telegram::Bot][1] для работы в Это бот, основанный на перловых модулях [Telegram::Bot][1] для работы в

View File

@@ -92,7 +92,7 @@ sub Command {
} elsif (substr ($text, 1) eq 'roll' || substr ($text, 1) eq 'dice' || substr ($text, 1) eq 'кости') { } elsif (substr ($text, 1) eq 'roll' || substr ($text, 1) eq 'dice' || substr ($text, 1) eq 'кости') {
$reply = sprintf 'На первой кости выпало %d, а на второй — %d.', irand (6) + 1, irand (6) + 1; $reply = sprintf 'На первой кости выпало %d, а на второй — %d.', irand (6) + 1, irand (6) + 1;
} elsif (substr ($text, 1) eq 'ver' || substr ($text, 1) eq 'version' || substr ($text, 1) eq 'версия') { } elsif (substr ($text, 1) eq 'ver' || substr ($text, 1) eq 'version' || substr ($text, 1) eq 'версия') {
$reply = 'Версия: Нуль.Чего-то_там.Чего-то_там'; $reply = 'Версия: Три.Чего-то_там.С_мелочью';
} elsif (substr ($text, 1) eq 'anek' || substr ($text, 1) eq 'анек' || substr ($text, 1) eq 'анекдот') { } elsif (substr ($text, 1) eq 'anek' || substr ($text, 1) eq 'анек' || substr ($text, 1) eq 'анекдот') {
$msg->typing (); $msg->typing ();
$reply = "```\n" . Anek () . "\n```"; $reply = "```\n" . Anek () . "\n```";

View File

@@ -17,6 +17,7 @@ use BotLib::Admin qw (FortuneToggleList);
use BotLib qw (RandomCommonPhrase Command Highlight BotSleep IsCensored); use BotLib qw (RandomCommonPhrase Command Highlight BotSleep IsCensored);
use BotLib::Conf qw (LoadConf); use BotLib::Conf qw (LoadConf);
use BotLib::Fortune qw (Fortune); use BotLib::Fortune qw (Fortune);
use BotLib::Image qw (Oboobs Obutts);
use BotLib::Karma qw (KarmaSet); use BotLib::Karma qw (KarmaSet);
use BotLib::Util qw (trim fmatch); use BotLib::Util qw (trim fmatch);
@@ -125,17 +126,22 @@ sub __on_msg {
foreach my $member (@{$msg->new_chat_members}) { foreach my $member (@{$msg->new_chat_members}) {
my $member_str = ''; my $member_str = '';
if ($member->can ('first_name') && defined ($member->first_name)) { # avoid naming people by spacing symbols, or empty names
if ($member->can ('first_name') && defined ($member->first_name) && $member->first_name !~ /^\s+$/ui) {
$member_str .= $member->first_name; $member_str .= $member->first_name;
if ($member->can ('last_name') && defined ($member->last_name)) { if ($member->can ('last_name') && defined ($member->last_name) && $member->last_name !~ /^\s+$/ui) {
$member_str .= ' ' . $member->last_name; $member_str .= ' ' . $member->last_name;
} }
} else { } else {
if ($member->can ('last_name') && defined ($member->last_name)) { if ($member->can ('last_name') && defined ($member->last_name) && $member->last_name !~ /^\s+$/ui) {
$member_str .= ' ' . $member->last_name; $member_str .= ' ' . $member->last_name;
} else { # username must be uniq and should contain only english letters and numbers, so...
} elsif ($member->can ('username') && defined ($member->username)) {
$member_str .= '@' . $member->username; $member_str .= '@' . $member->username;
# fallback to id if uose trying to be smartass and use only spacing chars in it's firstname and/or lastname
} else {
$member_str .= $member->id;
} }
} }
@@ -195,16 +201,22 @@ sub __on_msg {
} else { } else {
$just_message_in_chat = 1; $just_message_in_chat = 1;
} }
} else {
$just_message_in_chat = 1;
} }
if ($just_message_in_chat) { if ($just_message_in_chat) {
if ($text =~ /^кто +все +эти +люди *\?$/i) { if ($text =~ /^ *кто +все +эти +люди *\?$/ui) {
$reply = 'Какие люди? Мы здесь вдвоём, только ты и я.'; $reply = 'Какие "люди"? Мы здесь вдвоём, только ты и я.';
} elsif ($text =~ /покажи +(сиськи|сиси|титьки) *$/i) { } elsif ($text =~ /^ *кто +я *\?$/ui) {
$reply = 'Где?';
} elsif ($text =~ /^ *кто +(здесь|тут) *\?$/ui) {
$reply = 'Ты да я, да мы с тобой.';
} elsif ($text =~ /покажи +(сиськи|сиси|титьки) *$/ui) {
$reply = Oboobs (); $reply = Oboobs ();
} elsif ($text =~ /show +(titts|tities|boobs) *$/i) { } elsif ($text =~ /show +(titts|tities|boobs) *$/i) {
$reply = Oboobs (); $reply = Oboobs ();
} elsif ($text =~ /покажи +(попку|попу) *$/i) { } elsif ($text =~ /покажи +(попку|попу) *$/ui) {
$reply = Obutts (); $reply = Obutts ();
} elsif ($text =~ /show +(ass|butt|butty) *$/i) { } elsif ($text =~ /show +(ass|butt|butty) *$/i) {
$reply = Obutts (); $reply = Obutts ();
@@ -262,10 +274,22 @@ sub __on_msg {
$log->debug (sprintf ('[DEBUG] In public chat %s (%s) %s quote us!', $chatname, $chatid, $vis_a_vi)); $log->debug (sprintf ('[DEBUG] In public chat %s (%s) %s quote us!', $chatname, $chatid, $vis_a_vi));
# do not answer back if someone quote our new member greet # do not answer back if someone quote our new member greet
if ((substr ($msg->reply_to_message->text, 0, 9) eq 'Дратути, ') && if (substr ($msg->reply_to_message->text, -61) eq 'Представьтес, пожалуйста, и расскажите, что вас сюда привело.') {
(substr ($msg->reply_to_message->text, -61) eq 'Представьтес, пожалуйста, и расскажите, что вас сюда привело.')) { my @hello = (
'Дратути, ',
'Дарована, ',
'Доброе утро, день или вечер, ',
'Добро пожаловать в наше скромное коммунити, ',
'Наше вам с кисточкой тут, на канальчике, ',
);
foreach my $hi (@hello) {
if (substr ($msg->reply_to_message->text, 0, length $hi) eq $hi) {
return; return;
} else { }
}
}
# remove our name from users reply, just in case # remove our name from users reply, just in case
my $pat1 = quotemeta ('@' . $myusername); my $pat1 = quotemeta ('@' . $myusername);
my $pat2 = quotemeta $myfullname; my $pat2 = quotemeta $myfullname;
@@ -275,7 +299,6 @@ sub __on_msg {
# figure out reply :) # figure out reply :)
$reply = $hailo->{$msg->chat->id}->learn_reply ($phrase) if (length ($phrase) > 3); $reply = $hailo->{$msg->chat->id}->learn_reply ($phrase) if (length ($phrase) > 3);
}
# simple commands # simple commands
} elsif (substr ($text, 0, 1) eq $csign) { } elsif (substr ($text, 0, 1) eq $csign) {
$reply = Command ($self, $msg, $text, $chatid); $reply = Command ($self, $msg, $text, $chatid);
@@ -295,8 +318,12 @@ sub __on_msg {
if ((lc ($text) =~ /^${qname}[\,|\:]? (.+)/) or (lc ($text) =~ /^${qtname}[\,|\:]? (.+)/)){ if ((lc ($text) =~ /^${qname}[\,|\:]? (.+)/) or (lc ($text) =~ /^${qtname}[\,|\:]? (.+)/)){
$phrase = $1; $phrase = $1;
if ($phrase =~ /^кто +все +эти +люди *\?$/i) { if ($phrase =~ /^ *кто +все +эти +люди *\?$/ui) {
$reply = 'Кто здесь?'; $reply = 'Кто здесь?';
} elsif ($phrase =~ /^ *кто +я *?$/ui){
$reply = 'Где?';
} elsif ($phrase =~ /^ *кто +(здесь|тут) *\?$/ui) {
$reply = 'Здесь все: Никита, Стас, Гена, Турбо и Дюша Метёлкин.';
} else { } else {
$reply = $hailo->{$msg->chat->id}->learn_reply ($phrase); $reply = $hailo->{$msg->chat->id}->learn_reply ($phrase);
} }
@@ -304,8 +331,12 @@ sub __on_msg {
} elsif ((lc ($text) =~ /.+ ${qname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qname$/)) { } elsif ((lc ($text) =~ /.+ ${qname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qname$/)) {
$phrase = $text; $phrase = $text;
if ($phrase =~ /^кто +все +эти +люди *\?$/i) { if ($phrase =~ /^ *кто +все +эти +люди *\?$/ui) {
$reply = 'Кто здесь?'; $reply = 'Кто здесь?';
} elsif ($phrase =~ /^ *кто +я *?$/ui){
$reply = 'Где?';
} elsif ($phrase =~ /^ *кто +(здесь|тут) *\?$/ui) {
$reply = 'Здесь все: Никита, Стас, Гена, Турбо и Дюша Метёлкин.';
} else { } else {
$reply = $hailo->{$msg->chat->id}->learn_reply ($phrase); $reply = $hailo->{$msg->chat->id}->learn_reply ($phrase);
} }
@@ -313,8 +344,12 @@ sub __on_msg {
} elsif ((lc ($text) =~ /.+ ${qtname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qtname$/)) { } elsif ((lc ($text) =~ /.+ ${qtname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qtname$/)) {
$phrase = $text; $phrase = $text;
if ($phrase =~ /^кто +все +эти +люди *\?$/i) { if ($phrase =~ /^ *кто +все +эти +люди *\?$/ui) {
$reply = 'Кто здесь?'; $reply = 'Кто здесь?';
} elsif ($phrase =~ /^ *кто +я *?$/ui){
$reply = 'Где?';
} elsif ($phrase =~ /^ *кто +(здесь|тут) *\?$/ui) {
$reply = 'Здесь все: Никита, Стас, Гена, Турбо и Дюша Метёлкин.';
} else { } else {
$reply = $hailo->{$msg->chat->id}->learn_reply ($phrase); $reply = $hailo->{$msg->chat->id}->learn_reply ($phrase);
} }
@@ -330,8 +365,12 @@ sub __on_msg {
} }
# just message in chat # just message in chat
} else { } else {
if ($text =~ /^кто +все +эти +люди *\?$/i) { if ($text =~ /^ *кто +все +эти +люди *\?$/ui) {
$reply = 'Кто здесь?'; $reply = 'Кто здесь?';
} elsif ($phrase =~ /^ *кто +я *?$/ui){
$reply = 'Где?';
} elsif ($phrase =~ /^ *кто +(здесь|тут) *\?$/ui) {
$reply = 'Здесь все: Никита, Стас, Гена, Турбо и Дюша Метёлкин.';
} else { } else {
$hailo->{$msg->chat->id}->learn ($text); $hailo->{$msg->chat->id}->learn ($text);
} }