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:
@@ -16,7 +16,7 @@ use conf qw(loadConf);
|
|||||||
use vars qw/$VERSION/;
|
use vars qw/$VERSION/;
|
||||||
|
|
||||||
use Exporter qw(import);
|
use Exporter qw(import);
|
||||||
our @EXPORT = qw(weather logger);
|
our @EXPORT = qw(weather logger trim randomCommonPhrase);
|
||||||
|
|
||||||
$VERSION = "1.0";
|
$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;
|
1;
|
||||||
|
|
||||||
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:
|
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:
|
||||||
|
|||||||
@@ -137,6 +137,15 @@ sub __on_msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined($reply) && $reply ne '') {
|
if (defined($reply) && $reply ne '') {
|
||||||
|
if (lc($reply) eq lc(trim($text))) {
|
||||||
|
$reply = randomCommonPhrase();
|
||||||
|
}
|
||||||
|
|
||||||
|
# in case of trailing dot
|
||||||
|
if (lc($reply) eq substr(lc(trim($text)), 0, -1)) {
|
||||||
|
$reply = randomCommonPhrase();
|
||||||
|
}
|
||||||
|
|
||||||
logger ("reply with: $reply");
|
logger ("reply with: $reply");
|
||||||
$msg->reply($reply);
|
$msg->reply($reply);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user