Add test client for redis
This commit is contained in:
39
bin/redis_msg_gen.pl
Normal file
39
bin/redis_msg_gen.pl
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use 5.018;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
|
||||
my $workdir;
|
||||
|
||||
# before we run, change working dir
|
||||
BEGIN {
|
||||
use Cwd qw (chdir abs_path);
|
||||
my @CWD = split /\//xms, abs_path ($PROGRAM_NAME);
|
||||
|
||||
if ($#CWD > 1) {
|
||||
$#CWD = $#CWD - 1;
|
||||
}
|
||||
|
||||
$workdir = join '/', @CWD;
|
||||
chdir $workdir;
|
||||
}
|
||||
|
||||
use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5");
|
||||
use Cli qw (RunCli);
|
||||
|
||||
# set correct proctitle
|
||||
$PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::RequireLocalizedPunctuationVars)
|
||||
|
||||
# run cli, at last
|
||||
RunCli ();
|
||||
|
||||
exit 0;
|
||||
|
||||
__END__
|
||||
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:
|
||||
44
lib/Cli.pm
Normal file
44
lib/Cli.pm
Normal file
@@ -0,0 +1,44 @@
|
||||
package Cli;
|
||||
|
||||
# общие модули - синтаксис, кодировки итд
|
||||
use 5.018;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use open qw (:std :utf8);
|
||||
|
||||
# модули для работы приложения
|
||||
use Mojo::Redis;
|
||||
|
||||
use Conf qw (LoadConf);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (RunCli);
|
||||
|
||||
my $c = LoadConf ();
|
||||
|
||||
sub RunCli {
|
||||
my $redis = Mojo::Redis->new (
|
||||
sprintf 'redis://%s:%s/1', $c->{redis_server}, $c->{redis_port}
|
||||
);
|
||||
|
||||
my $send_to = 'telegram';
|
||||
|
||||
$redis->json ($send_to)->notify (
|
||||
$send_to => {
|
||||
from => 'redis_msg_gen.pl',
|
||||
userid => '0',
|
||||
chatid => 'some_chat_id',
|
||||
plugin => 'redis_msg_gen.pl_plugin',
|
||||
message => 'ping?',
|
||||
mode => 'mode',
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:
|
||||
@@ -13,6 +13,7 @@ use Hailo;
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::Base 'Teapot::Bot::Brain';
|
||||
use Mojo::Redis;
|
||||
use BotLib::Admin qw (FortuneToggleList);
|
||||
use BotLib qw (RandomCommonPhrase Command Highlight BotSleep IsCensored);
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
@@ -32,7 +33,7 @@ my $myusername;
|
||||
my $myfirst_name;
|
||||
my $mylast_name;
|
||||
my $myfullname;
|
||||
my $redis_mutex;
|
||||
my $redis;
|
||||
|
||||
has token => $c->{telegrambot}->{token};
|
||||
|
||||
@@ -359,9 +360,9 @@ sub __on_msg {
|
||||
}
|
||||
|
||||
sub __redisListener {
|
||||
return if ($redis_mutex);
|
||||
return if (defined $redis);
|
||||
|
||||
my $redis = Mojo::Redis->new (
|
||||
$redis = Mojo::Redis->new (
|
||||
sprintf 'redis://%s:%s/1', $c->{redis_server}, $c->{redis_port}
|
||||
);
|
||||
|
||||
@@ -376,7 +377,6 @@ sub __redisListener {
|
||||
);
|
||||
}
|
||||
|
||||
$redis_mutex = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user