Move config to bot package

This commit is contained in:
2022-08-23 11:52:36 -05:00
parent cf3fece52c
commit 435884b61a
7 changed files with 28 additions and 19 deletions

View File

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

View File

@ -1,37 +0,0 @@
package command
const (
defaultPrefix = "!"
)
var (
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
)
type (
Config struct {
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"`
Weather WeatherConfig `mapstructure:"weather"`
}
ReactionConfig struct {
Emojis []string
Channels []string
}
)
func NewConfig() Config {
var c Config
c.Prefix = defaultPrefix
c.Handler.Reaction.Emojis = defaultReactions
return c
}

View File

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

View File

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

View File

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

View File

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