diff --git a/bot/bot.go b/bot/bot.go index 0ef1540..d17d42d 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -7,6 +7,7 @@ import ( "os/signal" "syscall" + "git.kill0.net/chill9/beepboop/config" "git.kill0.net/chill9/beepboop/lib" "github.com/bwmarrin/discordgo" log "github.com/sirupsen/logrus" @@ -14,12 +15,12 @@ import ( "github.com/spf13/viper" ) -var C Config +var C *config.Config type ( Bot struct { Session *discordgo.Session - Config Config + Config *config.Config } MessageHandler func(s *discordgo.Session, m *discordgo.MessageCreate) @@ -32,7 +33,7 @@ func init() { viper.BindPFlags(pflag.CommandLine) } -func NewBot(s *discordgo.Session, config Config) *Bot { +func NewBot(s *discordgo.Session, config *config.Config) *Bot { return &Bot{Session: s, Config: config} } @@ -127,7 +128,7 @@ func Run() error { } func initConfig() { - C = NewConfig() + C = config.NewConfig() viper.SetEnvPrefix("BEEPBOOP") viper.AutomaticEnv() diff --git a/bot/command.go b/bot/command.go index f9cf256..7ea1831 100644 --- a/bot/command.go +++ b/bot/command.go @@ -3,6 +3,7 @@ package bot import ( "fmt" + "git.kill0.net/chill9/beepboop/config" "git.kill0.net/chill9/beepboop/lib" "github.com/bwmarrin/discordgo" log "github.com/sirupsen/logrus" @@ -19,7 +20,7 @@ type ( Command struct { Name string - Config Config + Config *config.Config Func CommandFunc NArgs int } diff --git a/bot/config.go b/bot/config.go deleted file mode 100644 index 4ccadf5..0000000 --- a/bot/config.go +++ /dev/null @@ -1,40 +0,0 @@ -package bot - -const ( - defaultPrefix = "!" -) - -var ( - defaultReactions []string = []string{ - "👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", - "🔥", "🍒", "🎉", "🥳", "🎊", "📉", "📈", "💀", "☠️", - } -) - -type ( - Config struct { - Debug bool `mapstructure:"debug"` - Handler HandlerConfig `mapstructure:"handler"` - Prefix string `mapstructure:"prefix"` - DiscordToken string `mapstructure:"discord_token"` - OpenWeatherMapToken string `mapstructure:"open_weather_map_token"` - } - - HandlerConfig struct { - Reaction ReactionConfig `mapstructure:"reaction"` - } - - ReactionConfig struct { - Emojis []string - Channels []string - } -) - -func NewConfig() Config { - var c Config - - c.Prefix = defaultPrefix - c.Handler.Reaction.Emojis = defaultReactions - - return c -} diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..c955498 --- /dev/null +++ b/config/config.go @@ -0,0 +1,58 @@ +package config + +const ( + defaultPrefix = "!" +) + +var ( + defaultReactions []string = []string{ + "👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", + "🔥", "🍒", "🎉", "🥳", "🎊", "📉", "📈", "💀", "☠️", + } +) + +type ( + Config struct { + Debug bool `mapstructure:"debug"` + Handler HandlerConfig `mapstructure:"handler"` + Prefix string `mapstructure:"prefix"` + DiscordToken string `mapstructure:"discord_token"` + OpenWeatherMapToken string `mapstructure:"open_weather_map_token"` + Mongo MongoConfig `mapstructure:"mongo"` + Redis RedisConfig `mapstructure:"redis"` + Postgres PostgresConfig `mapstructure:"postgres"` + } + + HandlerConfig struct { + Reaction ReactionConfig `mapstructure:"reaction"` + } + + ReactionConfig struct { + Emojis []string + Channels []string + } + + MongoConfig struct { + Uri string `mapstructure:"uri"` + Database string `mapstructure:"database"` + } + + RedisConfig struct { + Addr string `mapstructure:"addr"` + Password string `mapstructure:"password"` + DB int `mapstructure:"database"` + } + + PostgresConfig struct { + Uri string `mapstructure:"uri"` + } +) + +func NewConfig() *Config { + var c *Config = &Config{} + + c.Prefix = defaultPrefix + c.Handler.Reaction.Emojis = defaultReactions + + return c +}