Inject config into each command handler
This commit is contained in:
8
command/command.go
Normal file
8
command/command.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package command
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
type CommandHandler interface {
|
||||
Handle(s *discordgo.Session, m *discordgo.MessageCreate)
|
||||
SetConfig(config Config)
|
||||
}
|
@@ -4,18 +4,23 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type (
|
||||
PingHandler struct{}
|
||||
PingHandler struct {
|
||||
config Config
|
||||
}
|
||||
)
|
||||
|
||||
func NewPingHandler() *PingHandler {
|
||||
return new(PingHandler)
|
||||
}
|
||||
|
||||
func (h *PingHandler) SetConfig(config Config) {
|
||||
h.config = config
|
||||
}
|
||||
|
||||
func (h *PingHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
|
@@ -34,9 +34,16 @@ type (
|
||||
N int
|
||||
}
|
||||
|
||||
CoinHandler struct{}
|
||||
RollHandler struct{}
|
||||
RouletteHandler struct{}
|
||||
CoinHandler struct {
|
||||
config Config
|
||||
}
|
||||
RollHandler struct {
|
||||
config Config
|
||||
}
|
||||
|
||||
RouletteHandler struct {
|
||||
config Config
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -146,6 +153,10 @@ func NewRollHandler() *RollHandler {
|
||||
return new(RollHandler)
|
||||
}
|
||||
|
||||
func (h *RollHandler) SetConfig(config Config) {
|
||||
h.config = config
|
||||
}
|
||||
|
||||
func (h *RollHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
var (
|
||||
err error
|
||||
@@ -188,6 +199,10 @@ func NewRouletteHandler() *RouletteHandler {
|
||||
return new(RouletteHandler)
|
||||
}
|
||||
|
||||
func (h *RouletteHandler) SetConfig(config Config) {
|
||||
h.config = config
|
||||
}
|
||||
|
||||
func (h *RouletteHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
@@ -214,6 +229,10 @@ func NewCoinHandler() *CoinHandler {
|
||||
return new(CoinHandler)
|
||||
}
|
||||
|
||||
func (h *CoinHandler) SetConfig(config Config) {
|
||||
h.config = config
|
||||
}
|
||||
|
||||
func (h *CoinHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
var (
|
||||
c Coin
|
||||
|
@@ -10,13 +10,19 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
TimeHandler struct{}
|
||||
TimeHandler struct {
|
||||
config Config
|
||||
}
|
||||
)
|
||||
|
||||
func NewTimeHandler() *TimeHandler {
|
||||
return new(TimeHandler)
|
||||
}
|
||||
|
||||
func (h *TimeHandler) SetConfig(config Config) {
|
||||
h.config = config
|
||||
}
|
||||
|
||||
func (h *TimeHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
var (
|
||||
t time.Time
|
||||
|
Reference in New Issue
Block a user