This commit is contained in:
r4
2021-07-28 17:30:01 +02:00
parent 6dfb9bc0b1
commit d2fae31d1a
12 changed files with 1501 additions and 0 deletions

45
config.go Normal file
View File

@@ -0,0 +1,45 @@
package main
import (
"encoding/json"
"errors"
"os"
)
type Config struct {
Prefix string `json:"prefix"`
Token string `json:"token"`
YtdlPath string `json:"youtube-dl_path"`
FfmpegPath string `json:"ffmpeg_path"`
}
const configFile = "config.json"
const tokenDefaultString = "insert your discord bot token here"
func ReadConfig(cfg *Config) error {
configData, err := os.ReadFile(configFile)
if err != nil {
return errors.New("unable to read config file: " + err.Error())
}
json.Unmarshal(configData, cfg)
if err != nil {
return errors.New("unable to decode config file: " + err.Error())
}
return nil
}
func WriteDefaultConfig() error {
data, err := json.MarshalIndent(Config{
Prefix: "!",
Token: tokenDefaultString,
YtdlPath: "youtube-dl",
FfmpegPath: "ffmpeg",
}, "", "\t")
if err != nil {
return err
}
return os.WriteFile(configFile, data, 0666)
}