Replaced function hash with variable function names and correct calls.

Replaced constants with calls to $Self data.
This commit is contained in:
Stefan Härter 2023-05-22 18:29:32 +02:00
parent a1a4a58048
commit d26d928afc

View File

@ -91,7 +91,7 @@ sub build {
},
);
my $ResponseResult = plain POST(
join( '/', ( $TELEGRAM_URL, $TOKEN, 'sendMessage' ) ),
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'sendMessage' ) ),
{
'chat_id' => $Param{Message}->{chat}->{id},
'reply_to_message_id' => $Param{Message}->{id},
@ -137,7 +137,7 @@ sub statistics {
when ('standings') {
my $Standings = json POST(
join( '/',
( $ERGAST_URL, 'current', 'driverStandings.json' )
( $Self->{URL}{Ergast}, 'current', 'driverStandings.json' )
),
{}
);
@ -188,7 +188,7 @@ sub statistics {
join(
'/',
(
$ERGAST_URL, 'current',
$Self->{URL}{Ergast}, 'current',
'constructorStandings.json'
)
),
@ -248,12 +248,6 @@ sub processMessage {
use Data::Dumper;
use LWP::Simple::REST qw(POST plain json);
my %Commands = (
'greet' => \&greet,
'statistics' => \&statistics,
'build' => \&build,
);
if ( !defined $Param{Message} ) {
$Self->{LogObject}->error('processMessage: Message not defined!');
return;
@ -274,7 +268,7 @@ sub processMessage {
{
my $Command = $+{command};
my $ArgumentsString = $+{arguments};
$ResponseData = $Commands{$Command}(
$ResponseData = $Self->$Command(
Message => $Message,
Arguments => $ArgumentsString,
);
@ -294,7 +288,7 @@ sub processMessage {
}
my $ResponseResult = plain POST(
join( '/', ( $TELEGRAM_URL, $TOKEN, 'sendMessage' ) ),
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'sendMessage' ) ),
{
chat_id => $Message->{chat}->{id},
$ResponseData->%*,
@ -306,7 +300,7 @@ sub processMessage {
# mark message as read
my $SeenResult = plain POST(
join( '/', ( $TELEGRAM_URL, $TOKEN, 'readMessageContents' ) ),
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'readMessageContents' ) ),
{
id => $Message->{id},
}
@ -324,7 +318,7 @@ sub fetchMessages {
$Self->{LogObject}->info('fetchMessages: Initiating getUpdates');
my $MessageDataRaw =
json GET( join( '/', ( $TELEGRAM_URL, $TOKEN, $Method ) ), {} );
json GET( join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, $Method ) ), {} );
$Self->{LogObject}
->info( 'fetchMessages: Messages raw are ' . Dumper($MessageDataRaw) );
my @Messages = $MessageDataRaw->{result}->@*;
@ -332,7 +326,7 @@ sub fetchMessages {
->info( 'fetchMessages: Messages returned are ' . Dumper( \@Messages ) );
for my $Message (@Messages) {
$Self->{LogObject}->info('fetchMessages: Calling processMessage');
processMessage( Message => $Message, );
$Self->processMessage( Message => $Message, );
}
}