ccchatbot/schalter/bot.go

28 lines
528 B
Go
Raw Permalink Normal View History

2019-08-06 20:31:58 +02:00
package schalter
import (
"fmt"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
)
2019-08-07 12:27:18 +02:00
func (s *Schalter) HandleBotMessage(c xmpp.Sender, msg stanza.Message) bool {
2019-08-06 20:31:58 +02:00
if msg.Body == ".status" {
jid, _ := xmpp.NewJid(msg.From)
reply := stanza.Message{
Attrs: stanza.Attrs{Type: msg.Type,
To: msg.From,
},
2019-08-06 21:05:15 +02:00
Body: s.stateString(),
2019-08-06 20:31:58 +02:00
}
if msg.Type == stanza.MessageTypeGroupchat {
reply.To = jid.Bare()
reply.Body = fmt.Sprintf("%s: %s", jid.Resource, reply.Body)
}
2019-08-07 12:27:18 +02:00
c.Send(reply)
return true
2019-08-06 20:31:58 +02:00
}
2019-08-07 12:27:18 +02:00
return false
2019-08-06 20:31:58 +02:00
}