ccchatbot/schalter/bot.go
2019-08-06 21:05:15 +02:00

26 lines
563 B
Go

package schalter
import (
"fmt"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
)
func (s *Schalter) HandleBotMessage(c xmpp.Sender, msg stanza.Message) error {
if msg.Body == ".status" {
jid, _ := xmpp.NewJid(msg.From)
reply := stanza.Message{
Attrs: stanza.Attrs{Type: msg.Type,
To: msg.From,
},
Body: s.stateString(),
}
if msg.Type == stanza.MessageTypeGroupchat {
reply.To = jid.Bare()
reply.Body = fmt.Sprintf("%s: %s", jid.Resource, reply.Body)
}
return c.Send(reply)
}
return fmt.Errorf("not handled by this bot: %v", msg)
}