aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/utilities.go
blob: 6be4e586a309cb5fe5948d84a52aaa7595b5c98b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2021-2021 Fuwn
// SPDX-License-Identifier: GPL-3.0-only

package utilities

import (
	"math/rand"
	"os"
	"time"

	"github.com/spf13/viper"
)

func init() {
	rand.Seed(time.Now().UnixNano())
}

func GetRandomQuote() string {
	quotes := viper.GetStringSlice("space.footer.quotes")

	return quotes[rand.Intn(len(quotes))]
}

func GetCopyright() string {
	return viper.GetString("space.footer.copyright")
}

// Check if the following files exist, return files that don't exist
func DoesFilesExist(files []string) []string {
	nonExistant := []string{}

	for _, file := range files {
		// https://stackoverflow.com/a/12518877
		if _, err := os.Stat(file); os.IsNotExist(err) {
			nonExistant = append(nonExistant, file)
		}
	}

	return nonExistant
}