Adding command list.
This commit is contained in:
parent
cf2fa3df1e
commit
70b7362ab8
@ -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;
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user