Make use of replyMd() in newcommer greet, add botsleep() utility sub
This commit is contained in:
@@ -22,7 +22,7 @@ use archeologist qw (dig);
|
|||||||
|
|
||||||
use vars qw/$VERSION/;
|
use vars qw/$VERSION/;
|
||||||
use Exporter qw(import);
|
use Exporter qw(import);
|
||||||
our @EXPORT_OK = qw(weather trim randomCommonPhrase command highlight);
|
our @EXPORT_OK = qw(weather trim randomCommonPhrase command highlight botsleep);
|
||||||
$VERSION = '1.0';
|
$VERSION = '1.0';
|
||||||
|
|
||||||
my $c = loadConf();
|
my $c = loadConf();
|
||||||
@@ -274,6 +274,8 @@ sub command {
|
|||||||
$reply = fortune_status ($chatid);
|
$reply = fortune_status ($chatid);
|
||||||
} elsif (substr ($text, 1) eq 'dig' || substr ($text, 1) eq 'копать') {
|
} elsif (substr ($text, 1) eq 'dig' || substr ($text, 1) eq 'копать') {
|
||||||
$reply = dig ($highlight);
|
$reply = dig ($highlight);
|
||||||
|
$msg->typing ();
|
||||||
|
sleep (int ( rand (2) + 1));
|
||||||
$msg->replyMd ($reply);
|
$msg->replyMd ($reply);
|
||||||
return;
|
return;
|
||||||
} elsif (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {
|
} elsif (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {
|
||||||
@@ -343,6 +345,23 @@ sub highlight {
|
|||||||
|
|
||||||
return ($userid, $username, $fullname, $highlight, $visavi);
|
return ($userid, $username, $fullname, $highlight, $visavi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub botsleep {
|
||||||
|
# TODO: Parametrise this with fuzzy sleep time in seconds
|
||||||
|
my $msg = shift;
|
||||||
|
# let's emulate real human and delay answer
|
||||||
|
sleep (int ( rand (2) + 1));
|
||||||
|
|
||||||
|
for (0..(4 + int (rand (3)))) {
|
||||||
|
$msg->typing ();
|
||||||
|
sleep(3);
|
||||||
|
sleep 3 unless ($_);
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep ( 3 + int ( rand (2)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use File::Path qw(mkpath);
|
|||||||
use Hailo;
|
use Hailo;
|
||||||
use Mojo::Base 'Teapot::Bot::Brain';
|
use Mojo::Base 'Teapot::Bot::Brain';
|
||||||
use conf qw(loadConf);
|
use conf qw(loadConf);
|
||||||
use botlib qw(weather trim randomCommonPhrase command highlight);
|
use botlib qw(weather trim randomCommonPhrase command highlight botsleep);
|
||||||
use karma qw(karmaSet);
|
use karma qw(karmaSet);
|
||||||
use fortune qw(fortune fortune_toggle_list);
|
use fortune qw(fortune fortune_toggle_list);
|
||||||
|
|
||||||
@@ -103,30 +103,8 @@ sub __on_msg {
|
|||||||
|
|
||||||
# Newcommer event, greet our new member and suggest to introduce themself.
|
# Newcommer event, greet our new member and suggest to introduce themself.
|
||||||
if ($msg->can ('new_chat_members') && defined ($msg->new_chat_members)) {
|
if ($msg->can ('new_chat_members') && defined ($msg->new_chat_members)) {
|
||||||
if (defined ($username)) {
|
$phrase = "Дратути, $highlight. Представьтес, пожалуйста, и расскажите, что вас сюда привело.";
|
||||||
if (defined ($fullname)) {
|
botsleep($msg);
|
||||||
carp "[DEBUG] Newcommer in $chatname ($chatid): \@$username, $fullname ($userid)" if $c->{debug};
|
|
||||||
$phrase = "Дратути, [$fullname](tg://user?id=$userid). Представьтес, пожалуйста, и расскажите, что вас сюда привело.";
|
|
||||||
} else {
|
|
||||||
carp "[DEBUG] Newcommer in $chatname ($chatid): \@$username ($userid)" if $c->{debug};
|
|
||||||
$phrase = "Дратути, [$username](tg://user?id=$userid). Представьтес, пожалуйста, и расскажите, что вас сюда привело.";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
carp "[DEBUG] Newcommer in $chatname ($chatid): $fullname ($userid)" if $c->{debug};
|
|
||||||
$phrase = "Дратути, [$fullname](tg://user?id=$userid). Представьтес, пожалуйста, и расскажите, что вас сюда привело.";
|
|
||||||
}
|
|
||||||
|
|
||||||
# let's emulate real human and delay answer
|
|
||||||
sleep (int ( rand (2) + 1));
|
|
||||||
|
|
||||||
for (0..(4 + int (rand (3)))) {
|
|
||||||
$msg->typing ();
|
|
||||||
sleep(3);
|
|
||||||
sleep 3 unless ($_);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep ( 3 + int ( rand (2)));
|
|
||||||
|
|
||||||
$msg->replyMd ($phrase);
|
$msg->replyMd ($phrase);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user