2 Commits

2 changed files with 8 additions and 7 deletions

View File

@@ -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,18 +23,17 @@ 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;
$phrase = trim ($phrase);
if ((! defined $phrase) || $phrase eq '') { if ((! defined $phrase) || $phrase eq '') {
$phrase = ' '; $phrase = ' ';
} }
$phrase = trim ($phrase);
my $cache = CHI->new ( my $cache = CHI->new (
driver => 'BerkeleyDB', driver => 'BerkeleyDB',
root_dir => $cachedir, root_dir => $cachedir,
@@ -80,12 +80,12 @@ sub KarmaGet (@) {
my $chatid = shift; my $chatid = shift;
my $phrase = shift; my $phrase = shift;
$phrase = trim ($phrase);
if ((! defined $phrase) || $phrase eq '') { if ((! defined $phrase) || $phrase eq '') {
$phrase = ' '; $phrase = ' ';
} }
$phrase = trim ($phrase);
my $cache = CHI->new ( my $cache = CHI->new (
driver => 'BerkeleyDB', driver => 'BerkeleyDB',
root_dir => $cachedir, root_dir => $cachedir,

View File

@@ -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;