1

Compare commits

..

3 Commits

Author SHA1 Message Date
eleksir
ab27431e83 Edit spelling and enhance README.md 2020-09-19 14:57:05 +03:00
eleksir
d53ee53ad8 Use Cwd::utf8 to cope with returning string ut8-ness
* Use Cwd::utf8
* Sort cpanfile require, remove duplicates, add Cwd::utf8
* Add check on first call of abs_path()
2020-09-19 14:48:29 +03:00
eleksir
9461042ec4 Use botlib own trim() 2020-09-19 14:43:48 +03:00
4 changed files with 20 additions and 13 deletions

View File

@@ -12,8 +12,8 @@ Bot can be run via **bin/aleesa-telegam-bot** and acts as daemon.
## Installation ## Installation
In order to run this application, you need to "bootstrap" it - download all In order to run this application, you need to "bootstrap" it - download and build
dependencies and libraries. all required dependencies and libraries.
You'll need "Development Tools" or similar group of packages, perl, perl-devel, You'll need "Development Tools" or similar group of packages, perl, perl-devel,
perl-local-lib, perl-app-cpanm, sqlite-devel, zlib-devel, openssl-devel, perl-local-lib, perl-app-cpanm, sqlite-devel, zlib-devel, openssl-devel,
@@ -25,12 +25,12 @@ After installng required dependencies it is possible to run:
bash bootstrap.sh bash bootstrap.sh
``` ```
and all libraries should be downloaded and built. and all libraries should be downloaded, built, tested and installed.
## N.B. ## N.B.
If bot is unable to post to channel due to limitated permissions, it will die. If bot is unable to post to channel due to limited permissions, it will die.
It if possible to change this behavior by patching Telegram/Bot/Brain.pm: It is possible to change this behavior by patching Telegram/Bot/Brain.pm:
```diff ```diff
--- Brain.pm 2019-07-01 04:04:17.000000000 +0300 --- Brain.pm 2019-07-01 04:04:17.000000000 +0300

View File

@@ -18,6 +18,8 @@ BEGIN {
} }
use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5");
no Cwd;
use Cwd::utf8 qw(chdir abs_path);
use POSIX qw(setgid setuid setsid); use POSIX qw(setgid setuid setsid);
use File::Path qw(make_path); use File::Path qw(make_path);
use File::Basename qw(basename dirname); use File::Basename qw(basename dirname);
@@ -70,8 +72,13 @@ if ($< == 0) {
# double fork attach to /dev/null all stdio and go background # double fork attach to /dev/null all stdio and go background
daemonize (); daemonize ();
unless (defined($apath)) {
logger ("Unable to get abs_path: $!");
die "Unable to get abs_path: $!\n";
};
# write pidfile # write pidfile
my $pidfile = sprintf ("%s/%s.pid", $piddir, basename (abs_path ($0))); my $pidfile = sprintf ("%s/%s.pid", $piddir, basename ($apath));
logger ("Creating pidfile at $pidfile"); logger ("Creating pidfile at $pidfile");
open (PID, ">", $pidfile) or die "Error opening $pidfile: $!\n"; open (PID, ">", $pidfile) or die "Error opening $pidfile: $!\n";
print PID $$ or die "Error writing to $pidfile: $!\n"; print PID $$ or die "Error writing to $pidfile: $!\n";

View File

@@ -1,14 +1,15 @@
requires 'local::lib'; requires 'Cwd::utf8';
requires 'JSON';
requires 'Hailo';
requires 'Telegram::Bot';
requires 'DB_File'; requires 'DB_File';
requires 'Digest::MD5'; requires 'Digest::MD5';
requires 'Encode'; requires 'Encode';
requires 'File::Path';
requires 'File::Basename'; requires 'File::Basename';
requires 'File::Path';
requires 'HTTP::Tiny'; requires 'HTTP::Tiny';
requires 'Hailo'; requires 'Hailo';
requires 'JSON';
requires 'JSON::XS'; requires 'JSON::XS';
requires 'JSON::PP';
requires 'Mojo::Base'; requires 'Mojo::Base';
requires 'Telegram::Bot';
requires 'URI::URL'; requires 'URI::URL';
requires 'local::lib';

View File

@@ -25,8 +25,7 @@ my $c = loadConf();
sub weather($) { sub weather($) {
my $city = shift; my $city = shift;
while (substr($city, -1) eq "\n") { chomp($city); } $city = trim($city);
while (substr($city, 0, 1) eq "\n") { $city = substr($city, 1); }
return "Мне нужно ИМЯ города." if ($city eq ''); return "Мне нужно ИМЯ города." if ($city eq '');
return "Длинновато для названия города." if (length($city) > 80); return "Длинновато для названия города." if (length($city) > 80);