Compare commits

..

2 Commits

Author SHA1 Message Date
366f740795 Added lovely quotes for certain users. 2023-07-12 19:47:20 +02:00
5a1c720181 Issue #2: Added whitelist filtering. 2023-07-10 17:44:20 +02:00

View File

@ -12,7 +12,6 @@ use Encode;
use FindBin;
# CPAN packages
use Cache::FastMmap;
use JSON;
use Log::Log4perl;
use YAML;
@ -22,12 +21,6 @@ package F1DataBot;
# Constants and initalisations
Log::Log4perl->init("$FindBin::Bin/log.conf");
my $CACHE = Cache::FastMmap->new(
share_file => '/tmp/f1_bot',
serializer => 'json',
unlink_on_exit => 0,
expire_time => 86400,
);
sub new {
my ( $Type, %Param ) = @_;
@ -193,28 +186,20 @@ sub statistics {
my $StatIdentifier = $+{statidentifier};
given ($StatIdentifier) {
when ('standings') {
my $Standings;
if ( $CACHE->get('driver_standings') ) {
$Standings = $CACHE->get('driver_standings');
}
else {
$Standings = json POST(
join( '/',
( $Self->{URL}{Ergast}, 'current', 'driverStandings.json' )
),
{}
);
$CACHE->set('driver_standings', $Standings);
}
my $Standings = json POST(
join( '/',
( $Self->{URL}{Ergast}, 'current', 'driverStandings.json' )
),
{}
);
my %DriverStandings;
my $DriverStandingsFormatted = sprintf( "%2s %3s %-5s%7s\n",
my $DriverStandingsFormatted = sprintf( "%-3s%-4s%-5s%7s\n",
"#", "No.", "Code", "Points" );
for my $Driver ( $Standings->{MRData}->{StandingsTable}
->{StandingsLists}->[0]->{DriverStandings}->@* )
{
$DriverStandingsFormatted .= sprintf(
"%2d %3d %-5s%7d\n",
"%-3d%-4d%-5s%7d\n",
$Driver->{positionText},
$Driver->{Driver}->{permanentNumber},
$Driver->{Driver}->{code},
@ -250,38 +235,30 @@ sub statistics {
my $StatIdentifier = $+{statidentifier};
given ($StatIdentifier) {
when ('standings') {
my $Standings;
if ( $CACHE->get('constructor_standings') ) {
$Standings = $CACHE->get('constructor_standings');
}
else {
$Standings = json POST(
join( '/',
( $Self->{URL}{Ergast}, 'current', 'constructorStandings.json' )
),
{}
);
$CACHE->set('constructor_standings', $Standings);
}
my $Standings = json POST(
join(
'/',
(
$Self->{URL}{Ergast}, 'current',
'constructorStandings.json'
)
),
{}
);
$Self->{LogObject}
->info( 'statistics: Fetched standings are '
. Dumper($Standings) );
my $ConstructorStandingsFormatted = sprintf( "%2s %-15s%7s\n",
"#", "Name", "Points" );
my %ConstructorStandings;
my $ConstructorStandingsFormatted = '';
for my $Constructor ( $Standings->{MRData}->{StandingsTable}
->{StandingsLists}->[0]->{ConstructorStandings}->@* )
{
$ConstructorStandingsFormatted .= sprintf(
"%2d %-15s%7d\n",
$Constructor->{positionText},
$Constructor->{Constructor}->{name},
$Constructor->{points}
);
$ConstructorStandingsFormatted .=
"Position: $Constructor->{positionText}, Name: $Constructor->{Constructor}->{name} - Points: $Constructor->{points}\n";
}
$ConstructorStandingsFormatted =~ s/^/<pre>/;
$ConstructorStandingsFormatted =~ s/$/<\/pre>/;
$ReturnData{text} = $ConstructorStandingsFormatted;
$ReturnData{parse_mode} = 'HTML';
$ReturnData{text} = $ConstructorStandingsFormatted;
}
default {
$ReturnData{text} =
@ -457,8 +434,6 @@ sub fetchMessages {
if ( !$Self->{Whitelist}{$Message->{message}{from}{id}} ) {
$Self->{LogObject}
->info( 'fetchMessages: User not whitelisted, skipping message ' . Dumper($MessageDataRaw) );
$Self->{MessageIDs}{$Message->{message}{message_id}} = 1;
next MESSAGE;
}
if ($Self->{MessageIDs}{$Message->{message}{message_id}}) {
@ -471,7 +446,7 @@ sub fetchMessages {
$Self->processMessage( Message => $Message, );
}
}
YAML::DumpFile("$FindBin::Bin/message_ids.yml", $Self->{MessageIDs});
YAML::DumpFile('message_ids.yml', $Self->{MessageIDs});
}
1;