Adding command list.

This commit is contained in:
sergiotarxz 2022-02-09 18:30:50 +01:00
parent cf2fa3df1e
commit 70b7362ab8
2 changed files with 42 additions and 4 deletions

View File

@ -24,6 +24,22 @@ 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.',
}
]
);
while (1) {
my $updates = $telegram->get_updates;
@ -70,15 +86,15 @@ sub process_message_with_text {
substract_karma_to_replied_message_user($message);
return;
}
if ( $text eq '/karma' ) {
if ( $text =~ m{^/karma(?:@\w+)?$} ) {
show_karma($message);
return;
}
if ( $text eq '/doctortop' ) {
if ( $text =~ m{^/doctortop(?:@\w+)?$} ) {
show_top_ten($message);
return;
}
if ( $text eq '/doctorhate' ) {
if ( $text =~ m{^/doctorhate(?:@\w+)?$} ) {
show_top_ten_hate($message);
return;
}

View File

@ -5,7 +5,7 @@ use v5.30.0;
use strict;
use warnings;
use Types::Standard qw/Str Int Ref/;
use Types::Standard qw/Str Int Ref ArrayRef/;
use Params::ValidationCompiler qw(validation_for);
use Mojo::UserAgent;
@ -72,6 +72,28 @@ sub _user_agent {
}
}
{
my $validator = validation_for(
params => {
commands => { type => ArrayRef }
}
);
sub set_my_commands {
my $self = shift;
my %params = $validator->(@_);
my $commands = $params{commands};
my $response = $self->_request(
method => q/setMyCommands/,
body => {
commands => $commands,
}
);
return $response;
}
}
{
my $validator = validation_for(
params => {