ccchatbot/schalter/bot.go

28 lines
528 B
Go
Raw Normal View History

2019-08-06 13:31:58 -05:00
package schalter
import (
"fmt"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
)
2019-08-07 05:27:18 -05:00
func (s *Schalter) HandleBotMessage(c xmpp.Sender, msg stanza.Message) bool {
2019-08-06 13:31:58 -05: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 14:05:15 -05:00
Body: s.stateString(),
2019-08-06 13:31:58 -05:00
}
if msg.Type == stanza.MessageTypeGroupchat {
reply.To = jid.Bare()
reply.Body = fmt.Sprintf("%s: %s", jid.Resource, reply.Body)
}
2019-08-07 05:27:18 -05:00
c.Send(reply)
return true
2019-08-06 13:31:58 -05:00
}
2019-08-07 05:27:18 -05:00
return false
2019-08-06 13:31:58 -05:00
}