1

Add trim() and random pre-generated phrase answer

+ Add php-inspired trim() function
+ Add randomCommonPhrase() in order not to repeat given sentense if unable to produce relevant phrase from vocabulary generator
This commit is contained in:
eleksir
2020-09-09 14:54:38 +03:00
parent 20bbfab333
commit c3d2d76ad4
2 changed files with 36 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ use conf qw(loadConf);
use vars qw/$VERSION/;
use Exporter qw(import);
our @EXPORT = qw(weather logger);
our @EXPORT = qw(weather logger trim randomCommonPhrase);
$VERSION = "1.0";
@@ -202,6 +202,32 @@ sub logger {
}
}
sub trim($) {
my $str = shift;
while (substr ($str, 0, 1) =~ /^\s$/) {
$str = substr($str, 1);
}
while (substr ($str, -1, 1) =~ /^\s$/) {
chop ($str);
}
return $str;
}
sub randomCommonPhrase() {
my @myphrase = (
"Так, блядь...",
"*Закатывает рукава* И ради этого ты меня позвал?",
"Ну чего ты начинаешь, нормально же общались",
"Повтори свой вопрос, не поняла",
"Выйди и зайди нормально"
);
return ($myphrase[rand($#myphrase -1)]);
}
1;
# vim: set ft=perl noet ai ts=4 sw=4 sts=4: