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