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