First run of Teapot::Bot fixes.
* Fix typos in Brain.pm * Fix typos in User.pm * Implement typing methods in Message object and make use of it * Fix incorrect syntax of unless loops in telegrambot.pm * Add Log::Any as it required by Teapot::Bot * Do not use --update in bootstrap.sh * Add data/lat to .gitignore * Load ChatMember and ChatPermissions in Message object, so we can use 'em and avoid crash * Supply missing $send_args to _post_request
This commit is contained in:
@@ -9,7 +9,7 @@ use warnings;
|
||||
|
||||
use Mojo::IOLoop;
|
||||
use Mojo::UserAgent;
|
||||
use Carp qw/croak, cluck, confess/; # use croak where we return error up to app that supply something wrong
|
||||
use Carp qw/croak cluck confess/; # use croak where we return error up to app that supply something wrong
|
||||
# use cluck where we want to say that something bad but non-critical happen in
|
||||
# lower layer (Mojo loop)
|
||||
# use confess where we want to say that fatal error happen in lower layer (Mojo loop)
|
||||
@@ -111,7 +111,7 @@ sub getChatMember {
|
||||
my $token = $self->token || croak "no token?";
|
||||
|
||||
my $url = "https://api.telegram.org/bot${token}/getChatMember";
|
||||
my $api_response = $self->_post_request($url);
|
||||
my $api_response = $self->_post_request($url, $send_args);
|
||||
|
||||
if ($api_response) {
|
||||
return Teapot::Bot::Object::ChatMember->create_from_hash($api_response, $self);
|
||||
@@ -133,7 +133,7 @@ sub getChat {
|
||||
my $token = $self->token || croak "no token?";
|
||||
|
||||
my $url = "https://api.telegram.org/bot${token}/getChat";
|
||||
my $api_response = $self->_post_request($url);
|
||||
my $api_response = $self->_post_request($url, $send_args);
|
||||
|
||||
if ($api_response) {
|
||||
return Teapot::Bot::Object::Chat->create_from_hash($api_response, $self);
|
||||
|
||||
@@ -5,6 +5,8 @@ use Mojo::Base 'Teapot::Bot::Object::Base';
|
||||
|
||||
use Teapot::Bot::Object::User;
|
||||
use Teapot::Bot::Object::Chat;
|
||||
use Teapot::Bot::Object::ChatMember;
|
||||
use Teapot::Bot::Object::ChatPermissions;
|
||||
use Teapot::Bot::Object::MessageEntity;
|
||||
use Teapot::Bot::Object::Audio;
|
||||
use Teapot::Bot::Object::Document;
|
||||
@@ -135,6 +137,11 @@ sub reply {
|
||||
return $self->_brain->sendMessage({chat_id => $self->chat->id, text => $text});
|
||||
}
|
||||
|
||||
sub typing {
|
||||
my $self = shift;
|
||||
return $self->_brain->sendChatAction({chat_id => $self->chat->id});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
@@ -12,9 +12,9 @@ has 'first_name';
|
||||
has 'last_name'; # optional
|
||||
has 'username'; # optional
|
||||
has 'language_code'; # optional
|
||||
has 'can_join_groups' # optional, only for getMe() method
|
||||
has 'can_read_all_group_messages' # optional, only for getMe() method
|
||||
has 'supports_inline_queries' # optional, only for getMe() method
|
||||
has 'can_join_groups'; # optional, only for getMe() method
|
||||
has 'can_read_all_group_messages';# optional, only for getMe() method
|
||||
has 'supports_inline_queries'; # optional, only for getMe() method
|
||||
|
||||
sub fields {
|
||||
return { scalar => [qw/id is_bot first_name last_name username language_code can_join_groups
|
||||
|
||||
@@ -58,7 +58,7 @@ sub __on_msg {
|
||||
unless ($myid) {
|
||||
my $myObj = Teapot::Bot::Brain::getMe ($self);
|
||||
|
||||
unless ($myObj) do {
|
||||
unless ($myObj) {
|
||||
sleep 3;
|
||||
$myObj = Teapot::Bot::Brain::getMe ($self);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ sub __on_msg {
|
||||
if ($chatid < 0) {
|
||||
my $chatobj = Teapot::Bot::Brain::getChat ($self, { 'chat_id' => $chatid });
|
||||
|
||||
unless ($chatobj) do {
|
||||
unless ($chatobj) {
|
||||
sleep 3;
|
||||
$chatobj = Teapot::Bot::Brain::getChat ($self, { 'chat_id' => $chatid });
|
||||
}
|
||||
@@ -117,7 +117,7 @@ sub __on_msg {
|
||||
$group_talk = int ($chatobj->{permissions}->{can_send_messages});
|
||||
my $me = Teapot::Bot::Brain::getChatMember ($self, { 'chat_id' => $chatid, 'user_id' => $myid });
|
||||
|
||||
unless ($me) do {
|
||||
unless ($me) {
|
||||
sleep 3;
|
||||
$me = Teapot::Bot::Brain::getChatMember ($self, { 'chat_id' => $chatid, 'user_id' => $myid });
|
||||
}
|
||||
@@ -182,7 +182,7 @@ sub __on_msg {
|
||||
sleep (int ( rand (2) + 1));
|
||||
|
||||
for (0..(4 + int (rand (3)))) {
|
||||
Teapot::Bot::Brain::sendChatAction ($self, $chatid);
|
||||
$msg->typing();
|
||||
sleep(3);
|
||||
sleep 3 unless ($_);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ sub __on_msg {
|
||||
}
|
||||
}
|
||||
|
||||
Teapot::Bot::Brain::sendChatAction ($self, $chatid);
|
||||
$msg->typing();
|
||||
sleep 1;
|
||||
logger sprintf ("Private chat bot reply to $vis_a_vi: %s", $reply);
|
||||
$msg->reply ($reply);
|
||||
@@ -402,7 +402,7 @@ MYHELP
|
||||
$reply = randomCommonPhrase();
|
||||
}
|
||||
|
||||
Teapot::Bot::Brain::sendChatAction ($self, $chatid);
|
||||
$msg->typing();
|
||||
sleep (int (rand (2)));
|
||||
logger sprintf ('In public chat %s (%s) bot reply to %s: %s', $chatname, $chatid, $vis_a_vi, $reply);
|
||||
$msg->reply ($reply);
|
||||
|
||||
Reference in New Issue
Block a user