bb/bot/handler/ping.go

40 lines
685 B
Go
Raw Normal View History

2022-08-24 09:06:00 -05:00
package handler
2022-07-26 09:28:02 -05:00
import (
2022-08-23 11:52:36 -05:00
"git.kill0.net/chill9/beepboop/bot"
2022-08-27 09:00:35 -05:00
"git.kill0.net/chill9/beepboop/lib"
2022-07-26 09:28:02 -05:00
"github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus"
)
2022-07-27 23:43:08 -05:00
type (
PingHandler struct {
2022-08-23 11:52:36 -05:00
config bot.Config
2022-08-27 09:00:35 -05:00
Name string
}
2022-07-27 23:43:08 -05:00
)
2022-08-27 09:00:35 -05:00
func NewPingHandler(s string) *PingHandler {
h := new(PingHandler)
h.Name = s
return h
2022-07-27 23:43:08 -05:00
}
2022-08-23 11:52:36 -05:00
func (h *PingHandler) SetConfig(config bot.Config) {
h.config = config
}
2022-07-27 23:43:08 -05:00
func (h *PingHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
2022-07-26 09:28:02 -05:00
if m.Author.ID == s.State.User.ID {
return
}
2022-08-27 09:00:35 -05:00
if !lib.HasCommand(m.Content, h.config.Prefix, h.Name) {
2022-07-26 09:28:02 -05:00
return
}
log.Debug("received ping")
s.ChannelMessageSend(m.ChannelID, "pong")
}