From 91888e1c24239e514593bcfbe47f3b41e8b723e4 Mon Sep 17 00:00:00 2001 From: eleksir Date: Sat, 27 Mar 2021 13:14:58 +0300 Subject: [PATCH] Dee-Jay files around, rename subs according perlcritic convertions, update .gitignore --- .gitignore | 1 + bin/aleesa-jabber-bot | 8 +- bin/flickr_init.pl | 4 +- bin/fortune_seed.pl | 4 +- bin/friday_seed.pl | 4 +- bin/train_lat.pl | 4 +- cpanfile | 1 + lib/{botlib.pm => BotLib.pm} | 82 +++++++++---------- .../Archeologist.pm} | 6 +- lib/{buni.pm => BotLib/Buni.pm} | 6 +- lib/{conf.pm => BotLib/Conf.pm} | 6 +- lib/{drink.pm => BotLib/Drink.pm} | 6 +- lib/{fisher.pm => BotLib/Fisher.pm} | 6 +- lib/{fortune.pm => BotLib/Fortune.pm} | 12 +-- lib/{fox.pm => BotLib/Fox.pm} | 8 +- lib/{friday.pm => BotLib/Friday.pm} | 12 +-- lib/{image.pm => BotLib/Image.pm} | 18 ++-- lib/{flickr.pm => BotLib/Image/Flickr.pm} | 18 ++-- lib/{karma.pm => BotLib/Karma.pm} | 14 ++-- lib/{kitty.pm => BotLib/Kitty.pm} | 6 +- lib/{lat.pm => BotLib/Lat.pm} | 12 +-- lib/{monkeyuser.pm => BotLib/Monkeyuser.pm} | 6 +- lib/{util.pm => BotLib/Util.pm} | 2 +- lib/{weather.pm => BotLib/Weather.pm} | 12 +-- lib/{xkcd.pm => BotLib/Xkcd.pm} | 6 +- lib/{jabberbot.pm => JabberBot.pm} | 26 +++--- 26 files changed, 142 insertions(+), 148 deletions(-) rename lib/{botlib.pm => BotLib.pm} (91%) rename lib/{archeologist.pm => BotLib/Archeologist.pm} (98%) rename lib/{buni.pm => BotLib/Buni.pm} (94%) rename lib/{conf.pm => BotLib/Conf.pm} (93%) rename lib/{drink.pm => BotLib/Drink.pm} (97%) rename lib/{fisher.pm => BotLib/Fisher.pm} (98%) rename lib/{fortune.pm => BotLib/Fortune.pm} (92%) rename lib/{fox.pm => BotLib/Fox.pm} (88%) rename lib/{friday.pm => BotLib/Friday.pm} (93%) rename lib/{image.pm => BotLib/Image.pm} (64%) rename lib/{flickr.pm => BotLib/Image/Flickr.pm} (98%) rename lib/{karma.pm => BotLib/Karma.pm} (94%) rename lib/{kitty.pm => BotLib/Kitty.pm} (93%) rename lib/{lat.pm => BotLib/Lat.pm} (91%) rename lib/{monkeyuser.pm => BotLib/Monkeyuser.pm} (94%) rename lib/{util.pm => BotLib/Util.pm} (98%) rename lib/{weather.pm => BotLib/Weather.pm} (97%) rename lib/{xkcd.pm => BotLib/Xkcd.pm} (90%) rename lib/{jabberbot.pm => JabberBot.pm} (91%) diff --git a/.gitignore b/.gitignore index 6dd8346..2a46dc6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ data/*.sqlite data/cache/** data/fortune/** data/friday/** +data/image/** data/karma/** data/lat/** TODO diff --git a/bin/aleesa-jabber-bot b/bin/aleesa-jabber-bot index bf100ba..054f394 100755 --- a/bin/aleesa-jabber-bot +++ b/bin/aleesa-jabber-bot @@ -31,8 +31,8 @@ use File::Path qw (make_path); use File::Basename qw (basename dirname); use Log::Any::Adapter; use Log::Any::For::Std; -use conf qw (loadConf); -use jabberbot qw (run_jabberbot); +use BotLib::Conf qw (LoadConf); +use JabberBot qw (RunJabberBot); sub daemonize (); sub __fork (); @@ -42,7 +42,7 @@ local $OUTPUT_AUTOFLUSH = 1; my $runAsUid = $UID; my $piddir = '/var/run/' . basename (abs_path $PROGRAM_NAME); -my $C = loadConf (); +my $C = LoadConf (); my $logfile; if (defined $C->{'log'}) { @@ -114,7 +114,7 @@ local $SIG{TERM} = \&__signal_handler; # set correct proctitle $PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::RequireLocalizedPunctuationVars) -run_jabberbot (); +RunJabberBot (); if (-f $pidfile) { unlink $pidfile; diff --git a/bin/flickr_init.pl b/bin/flickr_init.pl index 9b50657..0d58b19 100644 --- a/bin/flickr_init.pl +++ b/bin/flickr_init.pl @@ -20,9 +20,9 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use flickr qw (flickr_init); +use BotLib::Image::Flickr qw (FlickrInit); -if (flickr_init ()) { +if (FlickrInit ()) { exit 0; } else { exit 1; diff --git a/bin/fortune_seed.pl b/bin/fortune_seed.pl index 9c0c556..43f6006 100644 --- a/bin/fortune_seed.pl +++ b/bin/fortune_seed.pl @@ -21,8 +21,8 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use fortune qw (seed); +use BotLib::Fortune qw (Seed); -seed (); +Seed (); exit 0; diff --git a/bin/friday_seed.pl b/bin/friday_seed.pl index b333248..20f55d7 100644 --- a/bin/friday_seed.pl +++ b/bin/friday_seed.pl @@ -20,8 +20,8 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use friday qw (seed); +use BotLib::Friday qw (Seed); -seed (); +Seed (); exit 0; diff --git a/bin/train_lat.pl b/bin/train_lat.pl index 1d6f8de..84c501e 100644 --- a/bin/train_lat.pl +++ b/bin/train_lat.pl @@ -20,7 +20,7 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use lat qw (train); +use Lat qw (Train); -train (); +Train (); exit 0; diff --git a/cpanfile b/cpanfile index f48dacb..96c2d68 100644 --- a/cpanfile +++ b/cpanfile @@ -14,6 +14,7 @@ requires 'IO::Socket::SSL'; requires 'POSIX'; requires 'Text::Fuzzy'; requires 'URI::URL'; +requires 'URI::Encode::XS'; requires 'local::lib'; requires 'Log::Any'; requires 'Log::Any::Adapter'; diff --git a/lib/botlib.pm b/lib/BotLib.pm similarity index 91% rename from lib/botlib.pm rename to lib/BotLib.pm index 20c5d89..ba31092 100644 --- a/lib/botlib.pm +++ b/lib/BotLib.pm @@ -1,6 +1,4 @@ -package botlib; -# TODO: исправить #/bin/bash и #/bin/env -# TODO: добавить сов и кроликов flickr и imgur +package BotLib; use 5.018; use strict; @@ -10,30 +8,30 @@ use open qw (:std :utf8); use English qw ( -no_match_vars ); use Carp qw (carp); use Math::Random::Secure qw (irand); -use archeologist qw (dig); -use buni qw (buni); -use conf qw (loadConf); -use drink qw (drink); -use fisher qw (fish); -use fortune qw (fortune); -use fox qw (fox); -use friday qw (friday); -use image wq (rabbit owl); -use karma qw (karmaGet); -use kitty qw (kitty); -use lat qw (latAnswer); -use monkeyuser qw (monkeyuser); -use util qw (trim utf2sha1); -use weather qw (weather); -use xkcd qw (xkcd); +use BotLib::Archeologist qw (Dig); +use BotLib::Buni qw (Buni); +use BotLib::Conf qw (LoadConf); +use BotLib::Drink qw (Drink); +use BotLib::Fisher qw (Fish); +use BotLib::Fortune qw (Fortune); +use BotLib::Fox qw (Fox); +use BotLib::Friday qw (Friday); +use BotLib::Image qw (Rabbit Owl); +use BotLib::Karma qw (KarmaGet); +use BotLib::Kitty qw (Kitty); +use BotLib::Lat qw (Lat); +use BotLib::Monkeyuser qw (Monkeyuser); +use BotLib::Util qw (trim utf2sha1); +use BotLib::Weather qw (Weather); +use BotLib::Xkcd qw (Xkcd); use version; our $VERSION = qw (1.0); -use Exporter qw(import); -our @EXPORT_OK = qw(command randomCommonPhrase realjid); +use Exporter qw (import); +our @EXPORT_OK = qw (Command RandomCommonPhrase RealJID); -my $c = loadConf (); +my $c = LoadConf (); -sub randomCommonPhrase () { +sub RandomCommonPhrase () { my @myphrase = ( 'Так, блядь...', '*Закатывает рукава* И ради этого ты меня позвал?', @@ -50,11 +48,11 @@ sub randomCommonPhrase () { return $myphrase[irand ($#myphrase + 1)]; } -sub command { +sub Command { my %hash = @_; my $bot = $hash{bot_object}; my $text = $hash{body}; - my %jid = realjid (%hash); + my %jid = RealJID (%hash); my $chattername = $jid{'name'}; my $chatid; @@ -180,7 +178,7 @@ sub command { $reply = '/me наливает абсент в стопку. Смочив кубик сахара в абсенте кладёт его на дырявую ложечку и пожигает. Как только пламя потухнет, ' . $bot->{'alias'} . ' размешивает оплавившийся кубик в абсенте и подносит стопку ' . $target . '.'; } elsif (substr ($text, 1, 2) eq 'w ' || substr ($text, 1, 2) eq 'п ') { my $city = substr $text, 2; - $reply = weather ($city) =~ tr/\n/ /r; + $reply = Weather ($city) =~ tr/\n/ /r; } elsif (substr ($text, 1) eq 'version' || substr ($text, 1) eq 'ver') { $reply = 'Версия нуль.чего-то_там.чего-то_там'; } elsif (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') { @@ -214,27 +212,27 @@ ${csign}xkcd - комикс-стрип с xkcb.ru EOL } elsif (substr ($text, 1) eq 'lat' || substr ($text, 1) eq 'лат') { - $reply = latAnswer (); + $reply = Lat (); } elsif (substr ($text, 1) eq 'cat' || substr ($text, 1) eq 'кис') { - $reply = kitty (); + $reply = Kitty (); } elsif (substr ($text, 1) eq 'fox' || substr ($text, 1) eq 'лис') { - $reply = fox (); + $reply = Fox (); } elsif (substr ($text, 1) eq 'dig' || substr ($text, 1) eq 'копать') { - $reply = dig ($chattername); + $reply = Dig ($chattername); } elsif (substr ($text, 1) eq 'fish' || substr ($text, 1) eq 'fisher' || substr ($text, 1) eq 'рыба' || substr ($text, 1) eq 'рыбка' || substr ($text, 1) eq 'рыбалка') { - $reply = fish ($chattername); + $reply = Fish ($chattername); } elsif (substr ($text, 1) eq 'buni') { - $reply = buni (); + $reply = Buni (); } elsif (substr ($text, 1) eq 'xkcd') { - $reply = xkcd (); + $reply = Xkcd (); } elsif (substr ($text, 1) eq 'monkeyuser') { - $reply = monkeyuser (); + $reply = Monkeyuser (); } elsif (substr ($text, 1) eq 'drink' || substr ($text, 1) eq 'праздник') { - $reply = drink (); + $reply = Drink (); } elsif (substr ($text, 1) eq 'bunny' || substr ($text, 1) eq 'rabbit' || substr ($text, 1) eq 'кролик') { - $reply = rabbit (); + $reply = Rabbit (); } elsif (substr ($text, 1) eq 'owl' || substr ($text, 1) eq 'сова') { - $reply = owl (); + $reply = Owl (); } elsif ((length ($text) >= 6 && (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ')) || substr ($text, 1) eq 'karma' || substr ($text, 1) eq 'карма') { my $mytext = ''; @@ -246,11 +244,11 @@ EOL $mytext = ''; } - $reply = karmaGet ($chatid, $mytext); + $reply = KarmaGet ($chatid, $mytext); } elsif (substr ($text, 1) eq 'friday' || substr ($text, 1) eq 'пятница') { - $reply = friday (); + $reply = Friday (); } elsif (substr ($text, 1) eq 'fortune' || substr ($text, 1) eq 'фортунка' || substr ($text, 1) eq 'f' || substr ($text, 1) eq 'ф') { - my $phrase = fortune (); + my $phrase = Fortune (); # workaround Net::Jabber::Bot outgoing message ![:print:] replacement $phrase =~ s/\s\s+\-\-/\n \-\-/xmsg; $reply = $phrase; @@ -269,15 +267,13 @@ EOL $reply = ':)'; } elsif (substr ($text, 1) eq '=)' || substr ($text, 1) eq ':)' || substr ($text, 1) eq '(:') { $reply = ':D'; - } elsif (substr ($text, 1, 11) eq '#/bin/bash' || substr ($text, 1, 9) eq '#/bin/sh' || substr ($text, 1, 14) eq '#/usr/bin/env') { - $reply = 'Кажется, вы ошиблись окном, это не паста.'; } return $reply; } # in this particular case real jid is really hidden :) and i hope that i found where it is hiding. -sub realjid { +sub RealJID { my %hash = @_; my $bot = $hash{'bot_object'}; my $myjid = $hash{'from_full'}; # in case of real jid myjid is name@server/resource in case of "groupchat" jid it is group@conf_server/name diff --git a/lib/archeologist.pm b/lib/BotLib/Archeologist.pm similarity index 98% rename from lib/archeologist.pm rename to lib/BotLib/Archeologist.pm index 2848625..4a3a8be 100644 --- a/lib/archeologist.pm +++ b/lib/BotLib/Archeologist.pm @@ -1,4 +1,4 @@ -package archeologist; +package BotLib::Archeologist; use 5.018; use strict; @@ -10,9 +10,9 @@ use Math::Random::Secure qw (irand); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (dig); +our @EXPORT_OK = qw (Dig); -sub dig { +sub Dig { my $name = shift; my @artifact = ( diff --git a/lib/buni.pm b/lib/BotLib/Buni.pm similarity index 94% rename from lib/buni.pm rename to lib/BotLib/Buni.pm index b18f4b3..ce1b345 100644 --- a/lib/buni.pm +++ b/lib/BotLib/Buni.pm @@ -1,4 +1,4 @@ -package buni; +package BotLib::Buni; use 5.018; use strict; @@ -12,9 +12,9 @@ use HTML::TokeParser; use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (buni); +our @EXPORT_OK = qw (Buni); -sub buni { +sub Buni { my $r; my $ret = 'Нету Buni'; diff --git a/lib/conf.pm b/lib/BotLib/Conf.pm similarity index 93% rename from lib/conf.pm rename to lib/BotLib/Conf.pm index df580ed..c2aeb26 100644 --- a/lib/conf.pm +++ b/lib/BotLib/Conf.pm @@ -1,4 +1,4 @@ -package conf; +package BotLib::Conf; # loads config use 5.018; @@ -11,9 +11,9 @@ use JSON::XS; use version; our $VERSION = qw (1.0); use Exporter qw(import); -our @EXPORT_OK = qw(loadConf); +our @EXPORT_OK = qw(LoadConf); -sub loadConf { +sub LoadConf { my $c = 'data/config.json'; open my $CH, '<', $c or die "[FATA] No conf at $c: $OS_ERROR\n"; my $len = (stat $c) [7]; diff --git a/lib/drink.pm b/lib/BotLib/Drink.pm similarity index 97% rename from lib/drink.pm rename to lib/BotLib/Drink.pm index 44452a3..76b4709 100644 --- a/lib/drink.pm +++ b/lib/BotLib/Drink.pm @@ -1,4 +1,4 @@ -package drink; +package BotLib::Drink; use 5.018; use strict; @@ -13,11 +13,11 @@ use HTML::TokeParser; use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (drink drink2); +our @EXPORT_OK = qw (Drink Drink2); my @MONTH = qw (yanvar fevral mart aprel may iyun iyul avgust sentyabr oktyabr noyabr dekabr); -sub drink { +sub Drink { my $r; my $ret = 'Не знаю праздников - вджобываю весь день на шахтах, как проклятая.'; my ($dayNum, $monthNum) = (localtime ())[3, 4]; diff --git a/lib/fisher.pm b/lib/BotLib/Fisher.pm similarity index 98% rename from lib/fisher.pm rename to lib/BotLib/Fisher.pm index 1cdbfb8..1d6a9d8 100644 --- a/lib/fisher.pm +++ b/lib/BotLib/Fisher.pm @@ -1,4 +1,4 @@ -package fisher; +package BotLib::Fisher; use 5.018; use strict; @@ -10,10 +10,10 @@ use Math::Random::Secure qw (irand); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (fish); +our @EXPORT_OK = qw (Fish); -sub fish { +sub Fish { my $name = shift; my @artifact = ( diff --git a/lib/fortune.pm b/lib/BotLib/Fortune.pm similarity index 92% rename from lib/fortune.pm rename to lib/BotLib/Fortune.pm index 1f3ef4c..cbf87dc 100644 --- a/lib/fortune.pm +++ b/lib/BotLib/Fortune.pm @@ -1,4 +1,4 @@ -package fortune; +package BotLib::Fortune; # Any fortune_mod sources are suitable. Text file with "\n%\n" sentence delimiters. use 5.018; @@ -12,17 +12,17 @@ use SQLite_File; use Math::Random::Secure qw (irand); use MIME::Base64; use File::Path qw (make_path); -use conf qw (loadConf); +use BotLib::Conf qw (LoadConf); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (seed fortune); +our @EXPORT_OK = qw (Seed Fortune); -my $c = loadConf (); +my $c = LoadConf (); my $dir = $c->{fortune}->{dir}; my $srcdir = $c->{fortune}->{srcdir}; -sub seed () { +sub Seed () { unless (-d $dir) { make_path ($dir) || croak "Unable to create $dir: $OS_ERROR"; } @@ -65,7 +65,7 @@ sub seed () { } # just return answer -sub fortune () { +sub Fortune () { my $backingfile = sprintf '%s/fortune.sqlite', $dir; tie my @array, 'SQLite_File', $backingfile || do { diff --git a/lib/fox.pm b/lib/BotLib/Fox.pm similarity index 88% rename from lib/fox.pm rename to lib/BotLib/Fox.pm index a2ab2f8..f89bf4b 100644 --- a/lib/fox.pm +++ b/lib/BotLib/Fox.pm @@ -1,4 +1,4 @@ -package fox; +package BotLib::Fox; use 5.018; use strict; @@ -12,10 +12,10 @@ use HTTP::Tiny; use vars qw/$VERSION/; use Exporter qw (import); -our @EXPORT_OK = qw (fox); +our @EXPORT_OK = qw (Fox); $VERSION = '1.0'; -sub fox { +sub Fox { my $r; my $ret = 'Нету лисичек, все разбежались.'; @@ -36,7 +36,7 @@ sub fox { }; unless (defined $jfox) { - cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR"; + carp "[ERROR] Unable to decode JSON: $EVAL_ERROR"; } else { if ($jfox->{image}) { $jfox->{image} =~ s/\\//xmsg; diff --git a/lib/friday.pm b/lib/BotLib/Friday.pm similarity index 93% rename from lib/friday.pm rename to lib/BotLib/Friday.pm index a6c9de4..195ba9c 100644 --- a/lib/friday.pm +++ b/lib/BotLib/Friday.pm @@ -1,4 +1,4 @@ -package friday; +package BotLib::Friday; # for friday data stolen from https://raw.githubusercontent.com/isida/vi/master/data/friday.txt use 5.018; @@ -11,18 +11,18 @@ use Carp qw (carp croak); use File::Path qw (make_path); use Math::Random::Secure qw (irand); use SQLite_File; -use conf qw (loadConf); +use BotLib::Conf qw (LoadConf); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (seed friday); +our @EXPORT_OK = qw (Seed Friday); -my $c = loadConf (); +my $c = LoadConf (); my $dir = $c->{friday}->{dir}; my $srcfile = $c->{friday}->{src}; my @dow = qw (monday tuesday wednesday thursday friday saturday sunday); -sub seed () { +sub Seed () { unless (-d $dir) { make_path ($dir) || croak "Unable to create $dir: $OS_ERROR"; } @@ -75,7 +75,7 @@ sub seed () { } # just return answer -sub friday () { +sub Friday () { my $today = (localtime (time))[6] - 1; my $backingfile = sprintf '%s/%s.sqlite', $dir, $dow[$today]; diff --git a/lib/image.pm b/lib/BotLib/Image.pm similarity index 64% rename from lib/image.pm rename to lib/BotLib/Image.pm index 6f5edc2..e5622dd 100644 --- a/lib/image.pm +++ b/lib/BotLib/Image.pm @@ -1,23 +1,19 @@ -package image; +package BotLib::Image; use 5.018; use strict; use warnings; use utf8; use open qw (:std :utf8); -use flickr qw (flickr_by_tags); +use BotLib::Image::Flickr qw (FlickrByTags); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (rabbit owl); +our @EXPORT_OK = qw (Rabbit Owl); -my $c = loadConf (); -my $dir = $c->{image}->{dir}; - - -sub rabbit { +sub Rabbit { # rabbit, but bunny - my $url = flickr_by_tags ('animal,bunny'); + my $url = FlickrByTags ('animal,bunny'); if (defined $url) { return $url; @@ -26,8 +22,8 @@ sub rabbit { } } -sub owl { - my $url = flickr_by_tags ('bird,owl'); +sub Owl { + my $url = FlickrByTags ('bird,owl'); if (defined $url) { return $url; diff --git a/lib/flickr.pm b/lib/BotLib/Image/Flickr.pm similarity index 98% rename from lib/flickr.pm rename to lib/BotLib/Image/Flickr.pm index f09e6b1..431c31c 100644 --- a/lib/flickr.pm +++ b/lib/BotLib/Image/Flickr.pm @@ -1,4 +1,4 @@ -package flickr; +package BotLib::Image::Flickr; use 5.018; use strict; @@ -16,16 +16,16 @@ use MIME::Base64; use SQLite_File; use URI::Encode::XS qw (uri_encode); -use conf qw (loadConf); -use util qw (urlencode); +use BotLib::Conf qw (LoadConf); +use BotLib::Util qw (urlencode); use Data::Dumper; use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (flickr_init flickr_by_tags flickr_by_text flickr_test_login); +our @EXPORT_OK = qw (FlickrInit FlickrByTags FlickrByText FlickrTestLogin); -my $c = loadConf (); +my $c = LoadConf (); my $dir = $c->{image}->{dir}; my $flickr_consumer_key = $c->{image}->{flickr}->{consumer_key}; @@ -464,7 +464,7 @@ sub flickrSearchByTags { } } -sub flickr_init { +sub FlickrInit { my $backingfile = sprintf '%s/secrets.sqlite', $dir; unless (-d $dir) { @@ -527,7 +527,7 @@ sub flickr_init { return 0; } -sub flickr_test_login { +sub FlickrTestLogin { my $text = shift; my $backingfile = sprintf '%s/secrets.sqlite', $dir; @@ -554,7 +554,7 @@ sub flickr_test_login { } } -sub flickr_by_tags { +sub FlickrByTags { my $text = shift; my $backingfile = sprintf '%s/secrets.sqlite', $dir; @@ -595,7 +595,7 @@ sub flickr_by_tags { } } -sub flickr_by_text { +sub FlickrByText { my $text = shift; my $backingfile = sprintf '%s/secrets.sqlite', $dir; diff --git a/lib/karma.pm b/lib/BotLib/Karma.pm similarity index 94% rename from lib/karma.pm rename to lib/BotLib/Karma.pm index 6f23ee0..bd475a0 100644 --- a/lib/karma.pm +++ b/lib/BotLib/Karma.pm @@ -1,4 +1,4 @@ -package karma; +package BotLib::Karma; use 5.018; use strict; @@ -9,19 +9,19 @@ use English qw ( -no_match_vars ); use Carp qw (carp); use DB_File; use File::Path qw (make_path); -use conf qw (loadConf); -use util qw (utf2sha1 trim); +use BotLib::Conf qw (LoadConf); +use BotLib::Util qw (utf2sha1 trim); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (karmaSet karmaGet); +our @EXPORT_OK = qw (KarmaSet KarmaGet); -my $c = loadConf (); +my $c = LoadConf (); my $karmadir = $c->{karma}->{dir}; my $max = 5; # swallow phrase and return answer -sub karmaSet (@) { +sub KarmaSet (@) { my $chatid = shift; my $phrase = shift; my $action = shift; @@ -84,7 +84,7 @@ sub karmaSet (@) { } # just return answer -sub karmaGet (@) { +sub KarmaGet (@) { my $chatid = shift; my $phrase = shift; $phrase = trim $phrase; diff --git a/lib/kitty.pm b/lib/BotLib/Kitty.pm similarity index 93% rename from lib/kitty.pm rename to lib/BotLib/Kitty.pm index 995a89b..90c1873 100644 --- a/lib/kitty.pm +++ b/lib/BotLib/Kitty.pm @@ -1,4 +1,4 @@ -package kitty; +package BotLib::Kitty; use 5.018; use strict; @@ -12,9 +12,9 @@ use HTTP::Tiny; use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (kitty); +our @EXPORT_OK = qw (Kitty); -sub kitty { +sub Kitty { my $r; my $ret = 'Нету кошечек, все разбежались.'; diff --git a/lib/lat.pm b/lib/BotLib/Lat.pm similarity index 91% rename from lib/lat.pm rename to lib/BotLib/Lat.pm index fece0f3..c40eda1 100644 --- a/lib/lat.pm +++ b/lib/BotLib/Lat.pm @@ -1,4 +1,4 @@ -package lat; +package BotLib::Lat; # famous latin phases taken from https://ru.wikipedia.org/wiki/Список_крылатых_латинских_выражений use 5.018; @@ -11,17 +11,17 @@ use Carp qw (carp); use File::Basename qw (dirname); use File::Path qw (make_path); use Hailo; -use conf qw (loadConf); +use BotLib::Conf qw (LoadConf); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (train latAnswer); +our @EXPORT_OK = qw (Train Lat); -my $c = loadConf (); +my $c = LoadConf (); my $brain = $c->{lat}->{brain}; my $srcfile = $c->{lat}->{src}; -sub train () { +sub Train () { my $braindir = dirname $brain; unless (-d $braindir) { @@ -45,7 +45,7 @@ sub train () { } # just return answer -sub latAnswer () { +sub Lat () { my $braindir = dirname $brain; unless (-d $braindir) { diff --git a/lib/monkeyuser.pm b/lib/BotLib/Monkeyuser.pm similarity index 94% rename from lib/monkeyuser.pm rename to lib/BotLib/Monkeyuser.pm index c2b2536..ab1c6ec 100644 --- a/lib/monkeyuser.pm +++ b/lib/BotLib/Monkeyuser.pm @@ -1,4 +1,4 @@ -package monkeyuser; +package BotLib::Monkeyuser; use 5.018; use strict; @@ -13,9 +13,9 @@ use Math::Random::Secure qw (irand); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (monkeyuser); +our @EXPORT_OK = qw (Monkeyuser); -sub monkeyuser { +sub Monkeyuser { my $r; my $ret = 'Нету Monkey User-ов, они все спрятались.'; my @link; diff --git a/lib/util.pm b/lib/BotLib/Util.pm similarity index 98% rename from lib/util.pm rename to lib/BotLib/Util.pm index 47fe003..70a6a36 100644 --- a/lib/util.pm +++ b/lib/BotLib/Util.pm @@ -1,4 +1,4 @@ -package util; +package BotLib::Util; use 5.018; use strict; diff --git a/lib/weather.pm b/lib/BotLib/Weather.pm similarity index 97% rename from lib/weather.pm rename to lib/BotLib/Weather.pm index b4b3a9e..7eb4d01 100644 --- a/lib/weather.pm +++ b/lib/BotLib/Weather.pm @@ -1,4 +1,4 @@ -package weather; +package BotLib::Weather; use 5.018; use strict; @@ -12,16 +12,16 @@ use Digest::MD5 qw (md5_base64); use File::Path qw (make_path); use HTTP::Tiny; use JSON::XS; -use conf qw (loadConf); -use util qw (trim urlencode); +use BotLib::Conf qw (LoadConf); +use BotLib::Util qw (trim urlencode); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (weather); +our @EXPORT_OK = qw (Weather); -my $c = loadConf (); +my $c = LoadConf (); -sub weather { +sub Weather { my $city = shift; $city = trim $city; diff --git a/lib/xkcd.pm b/lib/BotLib/Xkcd.pm similarity index 90% rename from lib/xkcd.pm rename to lib/BotLib/Xkcd.pm index a9a1ad2..535c3e8 100644 --- a/lib/xkcd.pm +++ b/lib/BotLib/Xkcd.pm @@ -1,4 +1,4 @@ -package xkcd; +package BotLib::Xkcd; use 5.018; use strict; @@ -9,9 +9,9 @@ use HTTP::Tiny; use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (xkcd); +our @EXPORT_OK = qw (Xkcd); -sub xkcd { +sub Xkcd { my $http = HTTP::Tiny->new (timeout => 5, max_redirect => 0); my $r = $http->get ('https://xkcd.ru/random/'); diff --git a/lib/jabberbot.pm b/lib/JabberBot.pm similarity index 91% rename from lib/jabberbot.pm rename to lib/JabberBot.pm index f9f83a5..0bf6c0d 100644 --- a/lib/jabberbot.pm +++ b/lib/JabberBot.pm @@ -1,7 +1,7 @@ # note http://www.gentoo.ru/node/21449 # необходимо закомментировать строку $response{authzid} = $authzid; # в vendor_perl/5.24.3/Authen/SASL/Perl/DIGEST_MD5.pm -package jabberbot; +package JabberBot; use 5.018; use strict; @@ -13,16 +13,16 @@ use Carp qw(carp); use File::Path qw (make_path); use Hailo; use Net::Jabber::Bot; -use botlib qw (command randomCommonPhrase realjid); -use conf qw (loadConf); -use karma qw (karmaSet); -use util qw (trim utf2sha1); +use BotLib qw (Command RandomCommonPhrase RealJID); +use BotLib::Conf qw (LoadConf); +use BotLib::Karma qw (KarmaSet); +use BotLib::Util qw (trim utf2sha1); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (run_jabberbot); +our @EXPORT_OK = qw (RunJabberBot); -my $c = loadConf (); +my $c = LoadConf (); my $hailo; my $imonline = 0; @@ -47,8 +47,7 @@ sub __new_bot_message { } my $text = $hash{body}; - - my %jid = realjid %hash; + my %jid = RealJID (%hash); my $chattername = $jid{'name'}; my $chatid; @@ -93,14 +92,12 @@ sub __new_bot_message { $reply = 'Чего тебе?'; } elsif (($text =~ /^$qname[\,|\:]? (.+)/) && ($hash{'type'} eq 'groupchat')) { $reply = $hailo->{$chatid}->learn_reply ($1); - } elsif (substr ($text, 0, 1) eq $c->{jabberbot}->{aleesa}->{csign}) { - $reply = command %hash; # karma adjustment } elsif (substr ($text, -2) eq '++' || substr ($text, -2) eq '--') { my @arr = split /\n/, $text; if ($#arr < 1) { - $reply = karmaSet ($chatid, trim (substr ($text, 0, -2)), substr ($text, -2)); + $reply = KarmaSet ($chatid, trim (substr ($text, 0, -2)), substr ($text, -2)); } else { # just message in chat # in groupchat we answer only to phrases that mention us @@ -111,6 +108,8 @@ sub __new_bot_message { $reply = $hailo->{$chatid}->learn_reply ($text); } } + } elsif (substr ($text, 0, 1) eq $c->{jabberbot}->{aleesa}->{csign}) { + $reply = Command (%hash); # just message in chat } else { # in groupchat we answer only to phrases that mention us @@ -134,7 +133,7 @@ sub __new_bot_message { } -sub run_jabberbot { +sub RunJabberBot { my %conflist = (); $conflist{$c->{jabberbot}->{aleesa}->{room}} = []; my $qname = quotemeta $c->{jabberbot}->{aleesa}->{mucname}; @@ -173,6 +172,7 @@ sub run_jabberbot { return; } + 1; # vim: set ft=perl noet ai ts=4 sw=4 sts=4: