Added saving and loading of processed update ids.

This commit is contained in:
Stefan Härter 2023-07-07 18:44:07 +02:00
parent 27143c691f
commit a156d990b9

View File

@ -1,5 +1,5 @@
# Important for switch feature
use v5.34;
use v5.32;
use utf8;
use strict;
@ -13,6 +13,7 @@ use Encode;
# CPAN packages
use JSON;
use Log::Log4perl;
use YAML;
# Package name
package F1DataBot;
@ -36,6 +37,9 @@ sub new {
Telegram => 'https://api.telegram.org',
};
# load remembered update ids
$Self->{UpdateIDs} = YAML::LoadFile('update_ids.yml');
return $Self;
}
@ -386,11 +390,20 @@ sub fetchMessages {
my @Messages = $MessageDataRaw->{result}->@*;
$Self->{LogObject}
->info( 'fetchMessages: Messages returned are ' . Dumper( \@Messages ) );
MESSAGE:
for my $Message (@Messages) {
$Self->{LogObject}->info('fetchMessages: Calling processMessage');
if ($Self->{UpdateIDs}{$Message->{update_id}}) {
$Self->{LogObject}->info('fetchMessages: Skipping known update_id');
next MESSAGE;
}
else {
$Self->{UpdateIDs}{$Message->{update_id}} = 1;
$Self->processMessage( Message => $Message, );
}
}
YAML::DumpFile('update_ids.yml', $Self->{UpdateIDs});
}
1;