diff --git a/bin/doctor_karma.pl b/bin/doctor_karma.pl index a2787cd..e51f9cf 100755 --- a/bin/doctor_karma.pl +++ b/bin/doctor_karma.pl @@ -23,33 +23,36 @@ my $config = DoctorKarma::Config->new; my $logger = DoctorKarma::Logger->new; my $telegram = DoctorKarma::Telegram->new( telegram_token => $config->telegram_token ); -my $db = DoctorKarma::DB->dbh; -$telegram->set_my_commands( - commands => [ - { - command => 'karma', - description => - 'Shows your karma or the one of the user you are replying to', - }, - { - command => 'doctortop', - description => 'Shows the most popular users.', - }, - { - command => 'doctorhate', - description => 'Shows the most hated users.', - }, - { - command => 'about', - description => - 'Shows license information, author and where to find the code.', - }, - { - command => 'donate', - description => 'Shows how to donate', - } - ] +my $db = DoctorKarma::DB->dbh; +my @commands = ( + { + command => 'karma', + description => + 'Shows your karma or the one of the user you are replying to.', + }, + { + command => 'doctortop', + description => 'Shows the most popular users.', + }, + { + command => 'doctorhate', + description => 'Shows the most hated users.', + }, + { + command => 'about', + description => + 'Shows license information, author and where to find the code.', + }, + { + command => 'donate', + description => 'Shows how to donate.', + }, + { + command => 'help', + description => 'Shows this help.', + } ); +$telegram->set_my_commands( commands => [@commands] ); while (1) { my $updates = $telegram->get_updates; @@ -116,14 +119,32 @@ sub process_message_with_text { show_donate($message); return; } + if ( $text =~ m{^/help(?:@\w+)?$} ) { + show_help($message); + return; + } if ( defined $reply_to_message && $text =~ /^(?:-|\+)\d+$/ ) { error_too_much_karma($message); return; } } +sub show_help { + my $message = shift; + my $chat_id = $message->{chat}{id}; + + my $html = "List of commands\n\n"; + for my $command (@commands) { + $html .= "@{[xml_escape('/'.$command->{command})]} @{[xml_escape($command->{description})]}\n"; + } + $telegram->send_message( + text => $html, + chat_id => $chat_id, + ); +} + sub show_donate { - my $message =shift; + my $message = shift; my $chat_id = $message->{chat}{id}; my $html = <<'EOF'; @@ -152,7 +173,7 @@ If you are interested in donate use the /donate command. EOF $telegram->send_message( chat_id => $chat_id, - text => $html, + text => $html, ); }