#!/usr/bin/env perl use v5.30.0; use strict; use warnings; use JSON; use Path::Tiny; use DoctorAgustin::Logger; my $logger = DoctorAgustin::Logger->new; my $term = Term::ReadLine->new('DoctorAgustin'); if (! -e $CONFIG_FILE ) { $logger->log_info(q(Config file not detected)); create_config_file; } if (! -f $CONFIG_FILE ) { $logger->log_error(qq($CONFIG_FILE is not a plain file.)); die; } sub create_config_file { if (! -e $CONFIG_DIR ) { $logger->log_info(qq(Creating $CONFIG_DIR)); eval { path($CONFIG_DIR)->mkpath; }; if ($@) { $logger->log_error(qq(Unable to create directory $CONFIG_DIR: $@)); die; } } my $token = $term->readline('Telegram token:'); my $config_contents = { token => $token }; $config_contents = encode_json ($config_contents); path($CONFIG_FILE)->spew_utf8($config_contents); }