Add database to config
This commit is contained in:
		
							
								
								
									
										20
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.go
									
									
									
									
									
								
							@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user