Change `die` instances to more suitable funcs

`die` on no usable questions now outputs a helpful warning
`die` on one question left is now a `warn` that warns about the lack of usable questions
`die` at end is now a simple messageless exit
This commit is contained in:
ngoomie 2023-03-27 10:58:12 +00:00
parent e65f71b09f
commit 5233888734
1 changed files with 3 additions and 3 deletions

View File

@ -19,7 +19,7 @@ my $dbh = DBI->connect("dbi:SQLite:questions.sqlite", '', '', { AutoCommit => 1,
# Fetch ID of unsent questions from DB and pass to @questions array. If no questions are left then instead send an error to Discord and close DB connection # Fetch ID of unsent questions from DB and pass to @questions array. If no questions are left then instead send an error to Discord and close DB connection
my @questions = @{ $dbh->selectcol_arrayref("SELECT id FROM data WHERE used = 0") }; my @questions = @{ $dbh->selectcol_arrayref("SELECT id FROM data WHERE used = 0") };
if (@questions == 0) { if (@questions == 0) {
$webhook->execute( content => 'There are no more questions left to post — please add more or you will get this message again tomorrow!');$dbh->disconnect; die} $webhook->execute( content => 'There are no more questions left to post — please add more or you will get this message again tomorrow!');$dbh->disconnect; die "No available unused questions, stopped"}
else { else {
# Pick one fetched ID at random and pass to $q_id # Pick one fetched ID at random and pass to $q_id
my $q_id = $questions[rand @questions]; my $q_id = $questions[rand @questions];
@ -42,5 +42,5 @@ else {
if ($#questions == 0) { if ($#questions == 0) {
$webhook->execute( content => '**You\'re out of questions!** Please add more or no question will be posted tomorrow.'); $webhook->execute( content => '**You\'re out of questions!** Please add more or no question will be posted tomorrow.');
$dbh->disconnect; die $dbh->disconnect; warn "Last available question used, finished"
} else { $dbh->disconnect; die }} } else { $dbh->disconnect; exit }}