hook2xmpp/xmpp/main.go

37 lines
738 B
Go
Raw Normal View History

2017-06-09 10:55:47 +02:00
package xmpp
import (
"github.com/genofire/golang-lib/log"
2017-06-10 16:31:56 +02:00
"github.com/genofire/hook2xmpp/config"
2017-06-09 10:55:47 +02:00
xmpp "github.com/mattn/go-xmpp"
)
func Start(client *xmpp.Client) {
for {
m, err := client.Recv()
if err != nil {
continue
}
switch v := m.(type) {
case xmpp.Chat:
if v.Type == "chat" {
log.Log.Infof("from %s: %s", v.Remote, v.Text)
}
if v.Type == "groupchat" {
}
case xmpp.Presence:
// do nothing
}
}
}
func Notify(client *xmpp.Client, hook config.Hook, msg string) {
for _, muc := range hook.NotifyMuc {
client.SendHtml(xmpp.Chat{Remote: muc, Type: "groupchat", Text: msg})
}
for _, user := range hook.NotifyUser {
client.SendHtml(xmpp.Chat{Remote: user, Type: "chat", Text: msg})
}
}