From 00fc8e1d2a70a64f9332a58ee2bf7d70c2705175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 10 Jul 2023 17:05:56 +0200 Subject: [PATCH 1/2] Issue #1: Initiator script now using config file. --- bot_script.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bot_script.pl b/bot_script.pl index 1c70c51..025acce 100644 --- a/bot_script.pl +++ b/bot_script.pl @@ -5,9 +5,22 @@ use v5.32; use strict; use warnings; -use lib '/home/demiguise/telegram_bot'; +use FindBin; +use YAML; + +my $Conf; +BEGIN { $Conf = YAML::LoadFile("$FindBin::Bin/.f1bot.cnf"); } + +if ( !$Conf->%* ) { + print STDERR "No valid config was found. Exiting...\n"; + exit; +} + +use lib $Conf->{Lib}; use F1DataBot; -my $F1DataBotObject = F1DataBot->new(); +my $F1DataBotObject = F1DataBot->new($Conf->%*); $F1DataBotObject->fetchMessages(); + +exit; -- 2.45.2 From b4a5a915ba8f74c003595865c154f52f5e582b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 10 Jul 2023 17:07:46 +0200 Subject: [PATCH 2/2] Issue #1: Bot module now also able to use config file. --- F1DataBot.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/F1DataBot.pm b/F1DataBot.pm index 63fdc00..8d5c4d6 100644 --- a/F1DataBot.pm +++ b/F1DataBot.pm @@ -9,6 +9,7 @@ no warnings qw(experimental); # core packages use Encode; +use FindBin; # CPAN packages use JSON; @@ -19,7 +20,7 @@ use YAML; package F1DataBot; # Constants and initalisations -Log::Log4perl->init('log.conf'); +Log::Log4perl->init("$FindBin::Bin/log.conf"); sub new { my ( $Type, %Param ) = @_; @@ -38,7 +39,7 @@ sub new { }; # load remembered update ids - $Self->{MessageIDs} = YAML::LoadFile('message_ids.yml'); + $Self->{MessageIDs} = YAML::LoadFile("$FindBin::Bin/message_ids.yml"); return $Self; } -- 2.45.2