Adding a better error handling.

This commit is contained in:
sergiotarxz 2022-03-16 00:36:15 +01:00
parent be6c2f2201
commit acbdaefba7
1 changed files with 12 additions and 9 deletions

View File

@ -55,20 +55,22 @@ my @commands = (
description => 'Shows this help.', description => 'Shows this help.',
} }
); );
$telegram->set_my_commands( commands => [@commands] );
my $i = 0;
while (1) { while (1) {
my $updates = $telegram->get_updates; eval {
for my $update ( $updates->@* ) { $telegram->set_my_commands( commands => [@commands] ) if $i == 0;
eval { my $updates = $telegram->get_updates;
for my $update ( $updates->@* ) {
my $message = $update->{message}; my $message = $update->{message};
if ( defined $message ) { if ( defined $message ) {
proccess_new_message($message); proccess_new_message($message);
} }
};
if ($@) {
$logger->log_error($@);
} }
$i++;
};
if ($@) {
$logger->log_error($@);
} }
} }
@ -138,7 +140,7 @@ sub check_can_modify_karma {
my $chat_id = $message->{chat}{id}; my $chat_id = $message->{chat}{id};
my $user_dao = DoctorKarma::DAO::User->new( dbh => $db ); my $user_dao = DoctorKarma::DAO::User->new( dbh => $db );
my $user = $user_dao->recover_id( id => $user_id ); my $user = $user_dao->recover_id( id => $user_id );
if ( $user->can_modify_karma ) { if ( $user->can_modify_karma ) {
$user_dao->update_last_karma_given_date( $user_dao->update_last_karma_given_date(
@ -148,7 +150,8 @@ sub check_can_modify_karma {
return 1; return 1;
} }
my $last_karma_given_date = $user->last_karma_given_date; my $last_karma_given_date = $user->last_karma_given_date;
my $time_to_post = $last_karma_given_date->add(minutes => 1) - DateTime->now(); my $time_to_post =
$last_karma_given_date->add( minutes => 1 ) - DateTime->now();
$telegram->send_message( $telegram->send_message(
chat_id => $chat_id, chat_id => $chat_id,
text => "You cannot give karma yet wait a bit. text => "You cannot give karma yet wait a bit.