Adding /help.

This commit is contained in:
sergiotarxz 2022-02-09 19:09:18 +01:00
parent bca8c0c8d1
commit 9bc1419231
1 changed files with 49 additions and 28 deletions

View File

@ -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 = "<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 {
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,
);
}