2 Commits

4 changed files with 24 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env perlcritic #!/usr/bin/env perlcritic
# Задействованные модули критика: # Задействованные модули критика:
# #
# Perl::Critic::More # Perl::Critic::More
@@ -9,6 +10,9 @@
# Perl::Critic::Policy::CompileTime # Perl::Critic::Policy::CompileTime
# Perl::Critic::Policy::ProhibitImplicitImport # Perl::Critic::Policy::ProhibitImplicitImport
# Perl::Critic::Policy::Dynamic::NoIndirect # Perl::Critic::Policy::Dynamic::NoIndirect
# Perl::Critic::StricterSubs
# Perl::Critic::Policy::ProhibitImplicitImport
# Perl::Critic::Policy::CodeLayout::RequireUseUTF8
[-ControlStructures::ProhibitUnlessBlocks] [-ControlStructures::ProhibitUnlessBlocks]
# oh. c'mon. just a little bit # oh. c'mon. just a little bit

View File

@@ -83,8 +83,8 @@ if ($UID == 0) {
make_path ( make_path (
$logdir, { $logdir, {
uid => $uid, uid => $uid,
group => $gid group => $gid,
} },
) or die "Unable to create $logdir: $OS_ERROR\n"; ) or die "Unable to create $logdir: $OS_ERROR\n";
} }
} }
@@ -115,7 +115,7 @@ my $apath = abs_path $PROGRAM_NAME;
unless (defined $apath) { unless (defined $apath) {
$log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n"); $log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n");
exit 1; exit 1;
}; }
my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath; my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath;
$log->info ("[INFO] Creating pidfile at $pidfile"); $log->info ("[INFO] Creating pidfile at $pidfile");

View File

@@ -28,12 +28,17 @@ sub KarmaSet (@) {
my $phrase = shift; my $phrase = shift;
my $action = shift; my $action = shift;
if ((! defined $phrase) || $phrase eq '') { unless (defined $phrase) {
$phrase = ' '; $phrase = '';
} }
$phrase = trim ($phrase); $phrase = trim ($phrase);
# Костылёк для кармы пустоты
if ($phrase eq '') {
$phrase = ' ';
}
my $cache = CHI->new ( my $cache = CHI->new (
driver => 'BerkeleyDB', driver => 'BerkeleyDB',
root_dir => $cachedir, root_dir => $cachedir,
@@ -80,12 +85,17 @@ sub KarmaGet (@) {
my $chatid = shift; my $chatid = shift;
my $phrase = shift; my $phrase = shift;
if ((! defined $phrase) || $phrase eq '') { unless (defined $phrase) {
$phrase = ' '; $phrase = '';
} }
$phrase = trim ($phrase); $phrase = trim ($phrase);
# Костылёк для кармы пустоты
if ($phrase eq '') {
$phrase = ' ';
}
my $cache = CHI->new ( my $cache = CHI->new (
driver => 'BerkeleyDB', driver => 'BerkeleyDB',
root_dir => $cachedir, root_dir => $cachedir,

View File

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