Adding /help.

This commit is contained in:
sergiotarxz 2022-02-09 19:09:18 +01:00
parent bca8c0c8d1
commit 9bc1419231

View File

@ -24,12 +24,11 @@ my $logger = DoctorKarma::Logger->new;
my $telegram = my $telegram =
DoctorKarma::Telegram->new( telegram_token => $config->telegram_token ); DoctorKarma::Telegram->new( telegram_token => $config->telegram_token );
my $db = DoctorKarma::DB->dbh; my $db = DoctorKarma::DB->dbh;
$telegram->set_my_commands( my @commands = (
commands => [
{ {
command => 'karma', command => 'karma',
description => description =>
'Shows your karma or the one of the user you are replying to', 'Shows your karma or the one of the user you are replying to.',
}, },
{ {
command => 'doctortop', command => 'doctortop',
@ -46,10 +45,14 @@ $telegram->set_my_commands(
}, },
{ {
command => 'donate', command => 'donate',
description => 'Shows how to donate', description => 'Shows how to donate.',
},
{
command => 'help',
description => 'Shows this help.',
} }
]
); );
$telegram->set_my_commands( commands => [@commands] );
while (1) { while (1) {
my $updates = $telegram->get_updates; my $updates = $telegram->get_updates;
@ -116,12 +119,30 @@ sub process_message_with_text {
show_donate($message); show_donate($message);
return; return;
} }
if ( $text =~ m{^/help(?:@\w+)?$} ) {
show_help($message);
return;
}
if ( defined $reply_to_message && $text =~ /^(?:-|\+)\d+$/ ) { if ( defined $reply_to_message && $text =~ /^(?:-|\+)\d+$/ ) {
error_too_much_karma($message); error_too_much_karma($message);
return; return;
} }
} }
sub show_help {
my $message = shift;
my $chat_id = $message->{chat}{id};
my $html = "<b><u>List of commands</u></b>\n\n";
for my $command (@commands) {
$html .= "<b>@{[xml_escape('/'.$command->{command})]}</b> @{[xml_escape($command->{description})]}\n";
}
$telegram->send_message(
text => $html,
chat_id => $chat_id,
);
}
sub show_donate { sub show_donate {
my $message = shift; my $message = shift;
my $chat_id = $message->{chat}{id}; my $chat_id = $message->{chat}{id};