40 lines
825 B
Go
40 lines
825 B
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{}) []*model.Message {
|
|
if !strings.EqualFold(strings.TrimSpace(msg.Text), "ping") {
|
|
return nil
|
|
}
|
|
|
|
response := &model.Message{
|
|
Text: "pong",
|
|
Chat: msg.Chat,
|
|
ReplyTo: msg.ID,
|
|
Channel: msg.Channel,
|
|
}
|
|
|
|
return []*model.Message{response}
|
|
}
|