Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3a8a1724c | ||
|
|
e100b00838 | ||
|
|
499da4fe84 | ||
|
|
f4d738697c |
@@ -14,8 +14,6 @@
|
|||||||
# Perl::Critic::Policy::ProhibitImplicitImport
|
# Perl::Critic::Policy::ProhibitImplicitImport
|
||||||
# Perl::Critic::Policy::CodeLayout::RequireUseUTF8
|
# Perl::Critic::Policy::CodeLayout::RequireUseUTF8
|
||||||
|
|
||||||
severity = 5
|
|
||||||
verbose = 8
|
|
||||||
|
|
||||||
# minorify some of warnings that are not really critical
|
# minorify some of warnings that are not really critical
|
||||||
[-InputOutput::RequireCheckedClose]
|
[-InputOutput::RequireCheckedClose]
|
||||||
@@ -131,3 +129,5 @@ lib_sections = NAME | VERSION | DESCRIPTION | AUTHOR | LICENSE AND COPYRIGHT
|
|||||||
max_length = 256
|
max_length = 256
|
||||||
|
|
||||||
[-Miscellanea::ProhibitUnrestrictedNoCritic]
|
[-Miscellanea::ProhibitUnrestrictedNoCritic]
|
||||||
|
|
||||||
|
[-RegularExpressions::ProhibitFixedStringMatches]
|
||||||
@@ -47,7 +47,10 @@ my $runAsUid = $UID;
|
|||||||
|
|
||||||
my $piddir = '/var/run/' . basename (abs_path ($PROGRAM_NAME));
|
my $piddir = '/var/run/' . basename (abs_path ($PROGRAM_NAME));
|
||||||
my $C = LoadConf ();
|
my $C = LoadConf ();
|
||||||
my $loglevel = $C->{'loglevel'} // 'notice';
|
|
||||||
|
my $loglevel = 'notice';
|
||||||
|
$loglevel = $C->{'loglevel'} if defined $C->{'loglevel'};
|
||||||
|
|
||||||
my $logfile;
|
my $logfile;
|
||||||
|
|
||||||
if (defined $C->{'log'}) {
|
if (defined $C->{'log'}) {
|
||||||
@@ -136,6 +139,7 @@ close $MYPID; ## no critic (InputOutput::
|
|||||||
# подстраховка на случай ядерной войны.
|
# подстраховка на случай ядерной войны.
|
||||||
local $SIG{INT} = \&__signal_handler;
|
local $SIG{INT} = \&__signal_handler;
|
||||||
local $SIG{TERM} = \&__signal_handler;
|
local $SIG{TERM} = \&__signal_handler;
|
||||||
|
local $SIG{QUIT} = \&__signal_handler;
|
||||||
|
|
||||||
# Поставим правильное имя процесса в proctitle
|
# Поставим правильное имя процесса в proctitle
|
||||||
$PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::RequireLocalizedPunctuationVars)
|
$PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::RequireLocalizedPunctuationVars)
|
||||||
@@ -152,7 +156,7 @@ exit 0;
|
|||||||
sub daemonize {
|
sub daemonize {
|
||||||
__fork ();
|
__fork ();
|
||||||
setsid ();
|
setsid ();
|
||||||
open STDIN, '<', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
open STDIN, '<', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
||||||
__fork ();
|
__fork ();
|
||||||
umask 0;
|
umask 0;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ sub brains (@);
|
|||||||
sub RunCraniac ();
|
sub RunCraniac ();
|
||||||
|
|
||||||
my $c = LoadConf ();
|
my $c = LoadConf ();
|
||||||
my $fwd_cnt = $c->{'forward_max'} // 5;
|
my $fwd_cnt = 5;
|
||||||
|
|
||||||
|
if (defined $c->{'forward_max'}) {
|
||||||
|
$fwd_cnt = $c->{'forward_max'};
|
||||||
|
}
|
||||||
|
|
||||||
my $hailo;
|
my $hailo;
|
||||||
|
|
||||||
@@ -128,49 +132,49 @@ my $parse_message = sub {
|
|||||||
my $reply;
|
my $reply;
|
||||||
|
|
||||||
if (defined $answer->{misc}) {
|
if (defined $answer->{misc}) {
|
||||||
unless (defined $answer->{misc}->{answer}) {
|
unless (defined $answer->{misc}->{answer}) {
|
||||||
$answer->{misc}->{answer} = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{bot_nick}) {
|
|
||||||
$answer->{misc}->{bot_nick} = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{csign}) {
|
|
||||||
$answer->{misc}->{csign} = $c->{csign};
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{fwd_cnt}) {
|
|
||||||
$answer->{misc}->{fwd_cnt} = 1;
|
|
||||||
} else {
|
|
||||||
if ($answer->{misc}->{fwd_cnt} > $fwd_cnt) {
|
|
||||||
$log->error ('[ERROR] Forward loop detected, discarding message.');
|
|
||||||
$log->debug (Dumper $m);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
$answer->{misc}->{fwd_cnt}++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{good_morning}) {
|
|
||||||
$answer->{misc}->{good_morning} = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{msg_format}) {
|
|
||||||
$answer->{misc}->{msg_format} = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined $answer->{misc}->{username}) {
|
|
||||||
$answer->{misc}->{username} = 'user';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$answer->{misc}->{answer} = 1;
|
$answer->{misc}->{answer} = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{bot_nick}) {
|
||||||
$answer->{misc}->{bot_nick} = '';
|
$answer->{misc}->{bot_nick} = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{csign}) {
|
||||||
$answer->{misc}->{csign} = $c->{csign};
|
$answer->{misc}->{csign} = $c->{csign};
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{fwd_cnt}) {
|
||||||
$answer->{misc}->{fwd_cnt} = 1;
|
$answer->{misc}->{fwd_cnt} = 1;
|
||||||
|
} else {
|
||||||
|
if ($answer->{misc}->{fwd_cnt} > $fwd_cnt) {
|
||||||
|
$log->error ('[ERROR] Forward loop detected, discarding message.');
|
||||||
|
$log->debug (Dumper $m);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$answer->{misc}->{fwd_cnt}++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{good_morning}) {
|
||||||
$answer->{misc}->{good_morning} = 0;
|
$answer->{misc}->{good_morning} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{msg_format}) {
|
||||||
$answer->{misc}->{msg_format} = 0;
|
$answer->{misc}->{msg_format} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (defined $answer->{misc}->{username}) {
|
||||||
$answer->{misc}->{username} = 'user';
|
$answer->{misc}->{username} = 'user';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$answer->{misc}->{answer} = 1;
|
||||||
|
$answer->{misc}->{bot_nick} = '';
|
||||||
|
$answer->{misc}->{csign} = $c->{csign};
|
||||||
|
$answer->{misc}->{fwd_cnt} = 1;
|
||||||
|
$answer->{misc}->{good_morning} = 0;
|
||||||
|
$answer->{misc}->{msg_format} = 0;
|
||||||
|
$answer->{misc}->{username} = 'user';
|
||||||
}
|
}
|
||||||
|
|
||||||
my $csign = $answer->{misc}->{csign};
|
my $csign = $answer->{misc}->{csign};
|
||||||
@@ -446,6 +450,7 @@ sub RunCraniac () {
|
|||||||
|
|
||||||
Mojo::IOLoop::Signal->on (TERM => $__signal_handler);
|
Mojo::IOLoop::Signal->on (TERM => $__signal_handler);
|
||||||
Mojo::IOLoop::Signal->on (INT => $__signal_handler);
|
Mojo::IOLoop::Signal->on (INT => $__signal_handler);
|
||||||
|
Mojo::IOLoop::Signal->on (QUIT => $__signal_handler);
|
||||||
|
|
||||||
do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running;
|
do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user