From acbdaefba7c1d2b1c5df8788be5e0d04b97ece7e Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Wed, 16 Mar 2022 00:36:15 +0100 Subject: [PATCH] Adding a better error handling. --- bin/doctor_karma.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bin/doctor_karma.pl b/bin/doctor_karma.pl index aeed7ce..a76e3f5 100755 --- a/bin/doctor_karma.pl +++ b/bin/doctor_karma.pl @@ -55,20 +55,22 @@ my @commands = ( description => 'Shows this help.', } ); -$telegram->set_my_commands( commands => [@commands] ); +my $i = 0; while (1) { - my $updates = $telegram->get_updates; - for my $update ( $updates->@* ) { - eval { + eval { + $telegram->set_my_commands( commands => [@commands] ) if $i == 0; + my $updates = $telegram->get_updates; + for my $update ( $updates->@* ) { my $message = $update->{message}; if ( defined $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 $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 ) { $user_dao->update_last_karma_given_date( @@ -148,7 +150,8 @@ sub check_can_modify_karma { return 1; } 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( chat_id => $chat_id, text => "You cannot give karma yet wait a bit.