butterrobot/internal/plugin/ping/ping.go
Felipe M. ae3c9f665d
Some checks failed
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/tag/release Pipeline was successful
feat: hltb plugin
2025-06-12 14:49:15 +02:00

49 lines
1 KiB
Go

package ping
import (
"strings"
"git.nakama.town/fmartingr/butterrobot/internal/model"
"git.nakama.town/fmartingr/butterrobot/internal/plugin"
)
// PingPlugin is a simple ping/pong plugin
type PingPlugin struct {
plugin.BasePlugin
}
// New creates a new PingPlugin instance
func New() *PingPlugin {
return &PingPlugin{
BasePlugin: plugin.BasePlugin{
ID: "dev.ping",
Name: "Ping",
Help: "Responds to 'ping' with 'pong'",
},
}
}
// OnMessage handles incoming messages
func (p *PingPlugin) OnMessage(msg *model.Message, config map[string]interface{}, cache model.CacheInterface) []*model.MessageAction {
if !strings.EqualFold(strings.TrimSpace(msg.Text), "ping") {
return nil
}
// Create the response message
response := &model.Message{
Text: "pong",
Chat: msg.Chat,
ReplyTo: msg.ID,
Channel: msg.Channel,
}
// Create an action to send the message
action := &model.MessageAction{
Type: model.ActionSendMessage,
Message: response,
Chat: msg.Chat,
Channel: msg.Channel,
}
return []*model.MessageAction{action}
}