49 lines
1 KiB
Go
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{}) []*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}
|
|
}
|