Fix karma, fix private commands, actually add !помощь command
* Fix zero length !karma parsing * In private chat commands not working except !help * Miss to add !помощь to parser, so it was noop
This commit is contained in:
@@ -266,11 +266,14 @@ sub command {
|
|||||||
} elsif (substr ($text, 1) eq 'lat' || substr ($text, 1) eq 'лат') {
|
} elsif (substr ($text, 1) eq 'lat' || substr ($text, 1) eq 'лат') {
|
||||||
$reply = latAnswer();
|
$reply = latAnswer();
|
||||||
} elsif (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ' || substr($text, 1) eq 'karma' || substr($text, $1) eq 'карма') {
|
} elsif (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ' || substr($text, 1) eq 'karma' || substr($text, $1) eq 'карма') {
|
||||||
my $mytext = substr ($text, 7);
|
my $mytext = '';
|
||||||
|
|
||||||
if ($mytext ne '') {
|
if (length($text) >= 7) {
|
||||||
|
$mytext = substr ($text, 7);
|
||||||
chomp ($mytext);
|
chomp ($mytext);
|
||||||
$mytext = trim ($mytext);
|
$mytext = trim ($mytext);
|
||||||
|
} else {
|
||||||
|
$mytext = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$reply = karmaGet ($chatid, $mytext);
|
$reply = karmaGet ($chatid, $mytext);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Mojo::Base 'Teapot::Bot::Brain';
|
|||||||
use conf qw(loadConf);
|
use conf qw(loadConf);
|
||||||
use botlib qw(weather logger trim randomCommonPhrase command);
|
use botlib qw(weather logger trim randomCommonPhrase command);
|
||||||
use telegramlib qw(visavi);
|
use telegramlib qw(visavi);
|
||||||
|
use karma qw(karmaSet);
|
||||||
|
|
||||||
use Exporter qw(import);
|
use Exporter qw(import);
|
||||||
our @EXPORT_OK = qw(run_telegrambot);
|
our @EXPORT_OK = qw(run_telegrambot);
|
||||||
@@ -219,7 +220,7 @@ sub __on_msg {
|
|||||||
my $reply = 'Давайте ещё пообщаемся, а то я ещё не научилась от вас плохому.';
|
my $reply = 'Давайте ещё пообщаемся, а то я ещё не научилась от вас плохому.';
|
||||||
|
|
||||||
if (substr ($text, 0, 1) eq $c->{telegrambot}->{csign}) {
|
if (substr ($text, 0, 1) eq $c->{telegrambot}->{csign}) {
|
||||||
if (substr ($text, 1) eq 'help') {
|
if (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {
|
||||||
my $send_args;
|
my $send_args;
|
||||||
$send_args->{text} = << 'MYHELP';
|
$send_args->{text} = << 'MYHELP';
|
||||||
```
|
```
|
||||||
@@ -237,30 +238,44 @@ MYHELP
|
|||||||
$send_args->{chat_id} = $userid;
|
$send_args->{chat_id} = $userid;
|
||||||
Teapot::Bot::Brain::sendMessage ($self, $send_args);
|
Teapot::Bot::Brain::sendMessage ($self, $send_args);
|
||||||
return;
|
return;
|
||||||
} esle {
|
} else {
|
||||||
$reply = command($text, $userid);
|
$reply = command($text, $userid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $str = $hailo->{$msg->chat->id}->learn_reply ($text);
|
my $just_message_in_chat = 0;
|
||||||
|
|
||||||
if (defined ($str) && $str ne '') {
|
if (substr ($text, -2) eq '++' || substr ($text, -2) eq '--') {
|
||||||
$reply = $str;
|
my @arr = split(/\n/, $text);
|
||||||
# TODO: move it to telegramlib.pm/botlib.pm!
|
|
||||||
$phrase = trim ($text);
|
|
||||||
|
|
||||||
while ($phrase =~ /[\.|\,|\?|\!]$/) {
|
if ($#arr < 1) {
|
||||||
chop $phrase;
|
$reply = karmaSet ($chatid, substr ($text, 0, -2), substr ($text, -2));
|
||||||
|
} else {
|
||||||
|
$just_message_in_chat = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$phrase = lc ($phrase);
|
if ($just_message_in_chat) {
|
||||||
|
my $str = $hailo->{$msg->chat->id}->learn_reply ($text);
|
||||||
|
|
||||||
if (lc ($reply) eq $phrase) {
|
if (defined ($str) && $str ne '') {
|
||||||
$reply = randomCommonPhrase();
|
$reply = $str;
|
||||||
} elsif (lc ($reply) eq substr ($phrase, 0, -1)) {
|
# TODO: move it to telegramlib.pm/botlib.pm!
|
||||||
# in case of trailing dot
|
$phrase = trim ($text);
|
||||||
$reply = randomCommonPhrase();
|
|
||||||
} elsif (substr (lc ($reply), 0, -1) eq $phrase) {
|
while ($phrase =~ /[\.|\,|\?|\!]$/) {
|
||||||
$reply = randomCommonPhrase();
|
chop $phrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
$phrase = lc ($phrase);
|
||||||
|
|
||||||
|
if (lc ($reply) eq $phrase) {
|
||||||
|
$reply = randomCommonPhrase();
|
||||||
|
} elsif (lc ($reply) eq substr ($phrase, 0, -1)) {
|
||||||
|
# in case of trailing dot
|
||||||
|
$reply = randomCommonPhrase();
|
||||||
|
} elsif (substr (lc ($reply), 0, -1) eq $phrase) {
|
||||||
|
$reply = randomCommonPhrase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +345,7 @@ MYHELP
|
|||||||
# simple commands
|
# simple commands
|
||||||
# TODO: Log commands and answers
|
# TODO: Log commands and answers
|
||||||
} elsif (substr ($text, 0, 1) eq $c->{telegrambot}->{csign}) {
|
} elsif (substr ($text, 0, 1) eq $c->{telegrambot}->{csign}) {
|
||||||
if (substr ($text, 1) eq 'help') {
|
if (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {
|
||||||
my $send_args;
|
my $send_args;
|
||||||
$send_args->{text} = << 'MYHELP';
|
$send_args->{text} = << 'MYHELP';
|
||||||
```
|
```
|
||||||
@@ -372,7 +387,7 @@ MYHELP
|
|||||||
} elsif ((lc ($text) =~ /.+ ${qtname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qtname$/)) {
|
} elsif ((lc ($text) =~ /.+ ${qtname}[\,|\!|\?|\.| ]/) or (lc ($text) =~ / $qtname$/)) {
|
||||||
$phrase = $text;
|
$phrase = $text;
|
||||||
$reply = $hailo->{$msg->chat->id}->reply ($phrase);
|
$reply = $hailo->{$msg->chat->id}->reply ($phrase);
|
||||||
} elsif ((substr ($text, -2) eq '++') || (substr ($text, -2) eq '--')) {
|
} elsif (substr ($text, -2) eq '++' || substr ($text, -2) eq '--') {
|
||||||
my @arr = split(/\n/, $text);
|
my @arr = split(/\n/, $text);
|
||||||
|
|
||||||
if ($#arr < 1) {
|
if ($#arr < 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user