Added saving and loading of processed update ids.
This commit is contained in:
parent
27143c691f
commit
a156d990b9
19
F1DataBot.pm
19
F1DataBot.pm
@ -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');
|
||||
$Self->processMessage( Message => $Message, );
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user