Add database to config

This commit is contained in:
Joren 2024-07-06 16:59:12 +02:00
parent b63a368c35
commit 7d8a2db77b
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55

20
main.go
View File

@ -13,10 +13,24 @@ import (
var client *discordgo.Session var client *discordgo.Session
type Config struct { type Config struct {
Token string `toml:"token"` Discord Discord `toml:"discord"`
GuildID string `toml:"guildId"` Database Database `toml:"database"`
} }
type Discord struct {
Token string `toml:"client"`
GuildID string `toml:"guildid"`
}
type Database struct {
Host string `toml:"host"`
Port int `toml:"port"`
Name string `toml:"name"`
Username string `toml:"username"`
Password string `toml:"password"`
}
func loadConfig(filename string) (Config, error) { func loadConfig(filename string) (Config, error) {
var config Config var config Config
_, err := toml.DecodeFile(filename, &config) _, err := toml.DecodeFile(filename, &config)
@ -30,7 +44,7 @@ func init() {
return return
} }
client, err = discordgo.New("Bot " + config.Token) client, err = discordgo.New("Bot " + config.Discord.Token)
if err != nil { if err != nil {
fmt.Println("Error initializing bot:", err) fmt.Println("Error initializing bot:", err)
return return