Compare commits
3 Commits
7ddd97710c
...
v1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba69f9d9df | ||
|
|
4d9cde38be | ||
|
|
61ad8278d5 |
16
lib/Karma.pm
16
lib/Karma.pm
@@ -1,4 +1,5 @@
|
|||||||
package Karma;
|
package Karma;
|
||||||
|
# Хранит и выдаёт карму фразы
|
||||||
|
|
||||||
use 5.018; ## no critic (ProhibitImplicitImport)
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
@@ -22,15 +23,19 @@ my $c = LoadConf ();
|
|||||||
my $cachedir = $c->{cachedir};
|
my $cachedir = $c->{cachedir};
|
||||||
my $max = 5;
|
my $max = 5;
|
||||||
|
|
||||||
# swallow phrase and return answer
|
|
||||||
sub KarmaSet (@) {
|
sub KarmaSet (@) {
|
||||||
my $chatid = shift;
|
my $chatid = shift;
|
||||||
my $phrase = shift;
|
my $phrase = shift;
|
||||||
my $action = shift;
|
my $action = shift;
|
||||||
|
|
||||||
|
unless (defined $phrase) {
|
||||||
|
$phrase = '';
|
||||||
|
}
|
||||||
|
|
||||||
$phrase = trim ($phrase);
|
$phrase = trim ($phrase);
|
||||||
|
|
||||||
if ((! defined $phrase) || $phrase eq '') {
|
# Костылёк для кармы пустоты
|
||||||
|
if ($phrase eq '') {
|
||||||
$phrase = ' ';
|
$phrase = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +85,14 @@ sub KarmaGet (@) {
|
|||||||
my $chatid = shift;
|
my $chatid = shift;
|
||||||
my $phrase = shift;
|
my $phrase = shift;
|
||||||
|
|
||||||
|
unless (defined $phrase) {
|
||||||
|
$phrase = '';
|
||||||
|
}
|
||||||
|
|
||||||
$phrase = trim ($phrase);
|
$phrase = trim ($phrase);
|
||||||
|
|
||||||
if ((! defined $phrase) || $phrase eq '') {
|
# Костылёк для кармы пустоты
|
||||||
|
if ($phrase eq '') {
|
||||||
$phrase = ' ';
|
$phrase = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ my $parse_message = sub {
|
|||||||
} else {
|
} else {
|
||||||
$reply = trim (Fortune ());
|
$reply = trim (Fortune ());
|
||||||
}
|
}
|
||||||
} elsif (length ($cmd) >= length ('karma ') && substr ($cmd, 0, length ('karma ') eq 'karma ')) {
|
} elsif (length ($cmd) >= length ('karma ') && substr ($cmd, 0, length ('karma ')) eq 'karma ') {
|
||||||
# По-умолчанию достаём карму пустоты
|
# По-умолчанию достаём карму пустоты
|
||||||
my $text = undef;
|
my $text = undef;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ my $parse_message = sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$reply = KarmaGet ($m->{chatid}, $text);
|
$reply = KarmaGet ($m->{chatid}, $text);
|
||||||
} elsif (length ($cmd) >= length ('карма ') && substr ($cmd, 0, length ('карма ') eq 'карма ')) {
|
} elsif (length ($cmd) >= length ('карма ') && substr ($cmd, 0, length ('карма ')) eq 'карма ') {
|
||||||
# По-умолчанию достаём карму пустоты
|
# По-умолчанию достаём карму пустоты
|
||||||
my $text = undef;
|
my $text = undef;
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ my $parse_message = sub {
|
|||||||
$reply = KarmaGet ($m->{chatid}, undef);
|
$reply = KarmaGet ($m->{chatid}, undef);
|
||||||
}
|
}
|
||||||
# Скорее всего изменение кармы, но это не точно
|
# Скорее всего изменение кармы, но это не точно
|
||||||
} elsif ($m->{message} > length ('++')) {
|
} elsif (length ($m->{message}) > length ('++')) {
|
||||||
if (substr ($m->{message}, 0 - length ('++')) eq '++' || substr ($m->{message}, 0 - length ('--')) eq '--') {
|
if (substr ($m->{message}, 0 - length ('++')) eq '++' || substr ($m->{message}, 0 - length ('--')) eq '--') {
|
||||||
my @arr = split /\n/s, $m->{message};
|
my @arr = split /\n/s, $m->{message};
|
||||||
|
|
||||||
@@ -142,14 +142,15 @@ my $parse_message = sub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$log->debug ("[DEBUG] Sending message to channel $send_to " . Dumper ($answer));
|
|
||||||
|
|
||||||
if (defined $reply && $answer->{misc}->{answer}) {
|
if (defined $reply && $answer->{misc}->{answer}) {
|
||||||
$answer->{message} = $reply;
|
$answer->{message} = $reply;
|
||||||
|
$log->debug ("[DEBUG] Sending message to channel $send_to " . Dumper ($answer));
|
||||||
|
|
||||||
$self->json ($send_to)->notify (
|
$self->json ($send_to)->notify (
|
||||||
$send_to => $answer,
|
$send_to => $answer,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$log->debug ('[DEBUG] No reply generated, skip sending message.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user