Added saving and loading of processed update ids.
This commit is contained in:
parent
27143c691f
commit
a156d990b9
17
F1DataBot.pm
17
F1DataBot.pm
@ -1,5 +1,5 @@
|
|||||||
# Important for switch feature
|
# Important for switch feature
|
||||||
use v5.34;
|
use v5.32;
|
||||||
|
|
||||||
use utf8;
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
@ -13,6 +13,7 @@ use Encode;
|
|||||||
# CPAN packages
|
# CPAN packages
|
||||||
use JSON;
|
use JSON;
|
||||||
use Log::Log4perl;
|
use Log::Log4perl;
|
||||||
|
use YAML;
|
||||||
|
|
||||||
# Package name
|
# Package name
|
||||||
package F1DataBot;
|
package F1DataBot;
|
||||||
@ -36,6 +37,9 @@ sub new {
|
|||||||
Telegram => 'https://api.telegram.org',
|
Telegram => 'https://api.telegram.org',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# load remembered update ids
|
||||||
|
$Self->{UpdateIDs} = YAML::LoadFile('update_ids.yml');
|
||||||
|
|
||||||
return $Self;
|
return $Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,11 +390,20 @@ sub fetchMessages {
|
|||||||
my @Messages = $MessageDataRaw->{result}->@*;
|
my @Messages = $MessageDataRaw->{result}->@*;
|
||||||
$Self->{LogObject}
|
$Self->{LogObject}
|
||||||
->info( 'fetchMessages: Messages returned are ' . Dumper( \@Messages ) );
|
->info( 'fetchMessages: Messages returned are ' . Dumper( \@Messages ) );
|
||||||
|
|
||||||
|
MESSAGE:
|
||||||
for my $Message (@Messages) {
|
for my $Message (@Messages) {
|
||||||
$Self->{LogObject}->info('fetchMessages: Calling processMessage');
|
$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, );
|
$Self->processMessage( Message => $Message, );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
YAML::DumpFile('update_ids.yml', $Self->{UpdateIDs});
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user