make all handlers a struct

This commit is contained in:
Ryan Cavicchioni 2022-07-27 23:43:08 -05:00
parent 826ac3292f
commit d0ddca7fe1
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
4 changed files with 26 additions and 9 deletions

View File

@ -94,11 +94,11 @@ func main() {
log.Fatalf("error creating Discord session: %v\n", err) log.Fatalf("error creating Discord session: %v\n", err)
} }
dg.AddHandler(command.PingHandler) dg.AddHandler(command.NewPingHandler().Handle)
dg.AddHandler(reactionHandler) dg.AddHandler(reactionHandler)
dg.AddHandler(praiseHandler) dg.AddHandler(praiseHandler)
dg.AddHandler(command.RollHandler) dg.AddHandler(command.NewRollHandler().Handle)
dg.AddHandler(command.RouletteHandler) dg.AddHandler(command.NewRouletteHandler().Handle)
h := command.NewWeatherHandler(C.Handler.Weather) h := command.NewWeatherHandler(C.Handler.Weather)
dg.AddHandler(h.Handle) dg.AddHandler(h.Handle)

View File

@ -8,7 +8,15 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func PingHandler(s *discordgo.Session, m *discordgo.MessageCreate) { type (
PingHandler struct{}
)
func NewPingHandler() *PingHandler {
return new(PingHandler)
}
func (h *PingHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID { if m.Author.ID == s.State.User.ID {
return return
} }

View File

@ -34,7 +34,9 @@ type (
N int N int
} }
CoinHandler struct{} CoinHandler struct{}
RollHandler struct{}
RouletteHandler struct{}
) )
var ( var (
@ -140,7 +142,11 @@ func (g *Gun) IsEmpty() bool {
return true return true
} }
func RollHandler(s *discordgo.Session, m *discordgo.MessageCreate) { func NewRollHandler() *RollHandler {
return new(RollHandler)
}
func (h *RollHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
var ( var (
err error err error
msg, roll string msg, roll string
@ -178,7 +184,11 @@ func RollHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, msg) s.ChannelMessageSend(m.ChannelID, msg)
} }
func RouletteHandler(s *discordgo.Session, m *discordgo.MessageCreate) { func NewRouletteHandler() *RouletteHandler {
return new(RouletteHandler)
}
func (h *RouletteHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID { if m.Author.ID == s.State.User.ID {
return return
} }

View File

@ -14,8 +14,7 @@ type (
) )
func NewTimeHandler() *TimeHandler { func NewTimeHandler() *TimeHandler {
var h *TimeHandler = new(TimeHandler) return new(TimeHandler)
return h
} }
func (h *TimeHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { func (h *TimeHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {