Move config to bot package

This commit is contained in:
Ryan Cavicchioni 2022-08-23 11:52:36 -05:00
parent cf3fece52c
commit 435884b61a
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
7 changed files with 28 additions and 19 deletions

View File

@ -1,4 +1,4 @@
package command package bot
const ( const (
defaultPrefix = "!" defaultPrefix = "!"
@ -25,6 +25,10 @@ type (
Emojis []string Emojis []string
Channels []string Channels []string
} }
WeatherConfig struct {
Token string `mapstructure:"token"`
}
) )
func NewConfig() Config { func NewConfig() Config {

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"syscall" "syscall"
"git.kill0.net/chill9/beepboop/bot"
"git.kill0.net/chill9/beepboop/command" "git.kill0.net/chill9/beepboop/command"
"git.kill0.net/chill9/beepboop/lib" "git.kill0.net/chill9/beepboop/lib"
@ -22,9 +23,7 @@ import (
) )
var ( var (
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"} C bot.Config
C command.Config
handlers []command.CommandHandler = []command.CommandHandler{ handlers []command.CommandHandler = []command.CommandHandler{
command.NewCoinHandler(), command.NewCoinHandler(),
@ -53,7 +52,6 @@ func main() {
lib.SeedMathRand() lib.SeedMathRand()
viper.SetDefault("handler.reaction.emojis", defaultReactions)
viper.SetEnvPrefix("BEEPBOOP") viper.SetEnvPrefix("BEEPBOOP")
viper.AutomaticEnv() viper.AutomaticEnv()
viper.SetConfigName("config") viper.SetConfigName("config")

View File

@ -1,8 +1,11 @@
package command package command
import "github.com/bwmarrin/discordgo" import (
"git.kill0.net/chill9/beepboop/bot"
"github.com/bwmarrin/discordgo"
)
type CommandHandler interface { type CommandHandler interface {
Handle(s *discordgo.Session, m *discordgo.MessageCreate) Handle(s *discordgo.Session, m *discordgo.MessageCreate)
SetConfig(config Config) SetConfig(config bot.Config)
} }

View File

@ -3,13 +3,14 @@ package command
import ( import (
"strings" "strings"
"git.kill0.net/chill9/beepboop/bot"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
type ( type (
PingHandler struct { PingHandler struct {
config Config config bot.Config
} }
) )
@ -17,7 +18,7 @@ func NewPingHandler() *PingHandler {
return new(PingHandler) return new(PingHandler)
} }
func (h *PingHandler) SetConfig(config Config) { func (h *PingHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.kill0.net/chill9/beepboop/bot"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -35,14 +36,14 @@ type (
} }
CoinHandler struct { CoinHandler struct {
config Config config bot.Config
} }
RollHandler struct { RollHandler struct {
config Config config bot.Config
} }
RouletteHandler struct { RouletteHandler struct {
config Config config bot.Config
} }
) )
@ -153,7 +154,7 @@ func NewRollHandler() *RollHandler {
return new(RollHandler) return new(RollHandler)
} }
func (h *RollHandler) SetConfig(config Config) { func (h *RollHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }
@ -199,7 +200,7 @@ func NewRouletteHandler() *RouletteHandler {
return new(RouletteHandler) return new(RouletteHandler)
} }
func (h *RouletteHandler) SetConfig(config Config) { func (h *RouletteHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }
@ -229,7 +230,7 @@ func NewCoinHandler() *CoinHandler {
return new(CoinHandler) return new(CoinHandler)
} }
func (h *CoinHandler) SetConfig(config Config) { func (h *CoinHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }

View File

@ -5,13 +5,14 @@ import (
"strings" "strings"
"time" "time"
"git.kill0.net/chill9/beepboop/bot"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
type ( type (
TimeHandler struct { TimeHandler struct {
config Config config bot.Config
} }
) )
@ -19,7 +20,7 @@ func NewTimeHandler() *TimeHandler {
return new(TimeHandler) return new(TimeHandler)
} }
func (h *TimeHandler) SetConfig(config Config) { func (h *TimeHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"git.kill0.net/chill9/beepboop/bot"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
@ -13,7 +14,7 @@ const (
type ( type (
VersionHandler struct { VersionHandler struct {
config Config config bot.Config
Name string Name string
} }
) )
@ -24,7 +25,7 @@ func NewVersionHandler(s string) *VersionHandler {
return h return h
} }
func (h *VersionHandler) SetConfig(config Config) { func (h *VersionHandler) SetConfig(config bot.Config) {
h.config = config h.config = config
} }