Perlcritic overhaul, apply to Teapot lib too

This commit is contained in:
eleksir
2022-02-12 17:31:09 +03:00
parent e84241c340
commit a9bb74b440
54 changed files with 493 additions and 263 deletions

View File

@@ -1,14 +1,13 @@
package BotLib::Admin;
use 5.018;
use 5.018; ## no critic (ProhibitImplicitImport)
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use English qw ( -no_match_vars );
use Carp qw (cluck croak);
use CHI;
use CHI::Driver::BerkeleyDB;
use CHI ();
use CHI::Driver::BerkeleyDB ();
use BotLib::Conf qw (LoadConf);
use BotLib::Util qw (utf2sha1);
@@ -33,7 +32,7 @@ sub GetForbiddenTypes {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid),
);
foreach (@ForbiddenMessageTypes) {
@@ -60,7 +59,7 @@ sub AddForbiddenType {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid),
);
$cache->set ($type, 1, 'never');
@@ -74,7 +73,7 @@ sub DelForbiddenType {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid),
);
$cache->remove ($type);
@@ -88,7 +87,7 @@ sub ListForbidden {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'censor' . '_' . utf2sha1 ($chatid),
);
foreach (@ForbiddenMessageTypes) {
@@ -116,7 +115,7 @@ sub FortuneToggle (@) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'fortune'
namespace => __PACKAGE__ . '_' . 'fortune',
);
my $state = $cache->get ($chatid);
@@ -152,7 +151,7 @@ sub FortuneStatus ($) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'fortune'
namespace => __PACKAGE__ . '_' . 'fortune',
);
my $state = $cache->get ($chatid);
@@ -170,7 +169,7 @@ sub FortuneToggleList () {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'fortune'
namespace => __PACKAGE__ . '_' . 'fortune',
);
return $cache->get_keys ();
@@ -184,7 +183,7 @@ sub ChanMsgToggle (@) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'chan_msg'
namespace => __PACKAGE__ . '_' . 'chan_msg',
);
my $state = $cache->get ($chatid);
@@ -227,7 +226,7 @@ sub ChanMsgStatus ($) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'chan_msg'
namespace => __PACKAGE__ . '_' . 'chan_msg',
);
my $state = $cache->get ($chatid);
@@ -251,7 +250,7 @@ sub ChanMsgEnabled ($) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'chan_msg'
namespace => __PACKAGE__ . '_' . 'chan_msg',
);
my $state = $cache->get ($chatid);
@@ -271,7 +270,7 @@ sub ChanMsgToggleList () {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'chan_msg'
namespace => __PACKAGE__ . '_' . 'chan_msg',
);
return $cache->get_keys ();
@@ -285,7 +284,7 @@ sub PluginStatus (@) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid),
);
my $state = $cache->get ($plugin);
@@ -315,7 +314,7 @@ sub PluginEnabled (@) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid),
);
my $state = $cache->get ($plugin);
@@ -336,7 +335,7 @@ sub PluginToggle (@) {
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid)
namespace => __PACKAGE__ . '_' . 'plugin' . '_' . utf2sha1 ($chatid),
);
my $state = $cache->get ($plugin);

View File

@@ -1,13 +1,13 @@
package BotLib::Conf;
# loads config
# Загружает конфиг файл
use 5.018;
use 5.018; ## no critic (ProhibitImplicitImport)
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use English qw ( -no_match_vars );
use JSON::XS;
use JSON::XS ();
use version; our $VERSION = qw (1.0);
use Exporter qw (import);
@@ -15,7 +15,12 @@ our @EXPORT_OK = qw (LoadConf);
sub LoadConf {
my $c = 'data/config.json';
open my $CH, '<', $c or die "[FATAL] No conf at $c: $OS_ERROR\n";
my $CH;
unless (open $CH, '<', $c) {
die "[FATAL] No conf at $c: $OS_ERROR\n";
}
my $len = (stat $c) [7];
my $json;
my $readlen = read $CH, $json, $len;

View File

@@ -1,16 +1,16 @@
package BotLib::Util;
use 5.018;
use 5.018; ## no critic (ProhibitImplicitImport)
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use English qw ( -no_match_vars );
use Digest::SHA qw (sha1_base64);
use Encode;
use MIME::Base64;
use Encode qw (encode_utf8);
use MIME::Base64 qw (encode_base64);
use Text::Fuzzy qw (distance_edits);
use URI::URL;
use URI::URL qw (url);
use version; our $VERSION = qw (1.0);
use Exporter qw (import);