Move config to a separate package
This commit is contained in:
parent
b8b994157e
commit
7a0c90a5f7
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
58
config/config.go
Normal file
58
config/config.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user