Adding /karma command.

This commit is contained in:
sergiotarxz 2022-02-08 01:28:57 +01:00
parent 667dfcfb5d
commit 69cb88acb7

View File

@ -64,9 +64,28 @@ sub process_message_with_text {
if ( $text eq '+1' && defined $reply_to_message ) {
add_karma_to_replied_message_user($message);
}
if ($text eq '-1' && defined $reply_to_message) {
substract_karma_to_replied_message_user ($message);
if ( $text eq '-1' && defined $reply_to_message ) {
substract_karma_to_replied_message_user($message);
}
if ( $text eq '/karma' ) {
show_karma($message);
}
}
sub show_karma {
my $message = shift;
my $reply_to_message = $message->{reply_to_message};
my $user_id = $reply_to_message->{from}{id} // $message->{from}{id};
my $chat_id = $message->{chat}{id};
my $user_dao = DoctorKarma::DAO::User->new( dbh => $db );
my $user = $user_dao->recover_id( id => $user_id );
$telegram->send_message(
chat_id => $chat_id,
text =>
"@{[$user->first_name]} has @{[$user->karma =~ s/-/\\-/r]} points of karma\\."
);
}
sub substract_karma_to_replied_message_user {