Do not answer publicly for private messages.

change-name
Robert Jacob 5 years ago
parent 05df498087
commit 8f4ce84bb0
  1. 34
      xmpp/xmpp.go

@ -25,6 +25,8 @@ const (
Gern geschehen.`
errorNonPublic = "Bitte mach das öffentlich, damit jeder weiß von wem die Information ist."
stateUnknown = "Ich weiß leider nicht ob der Space offen ist."
stateOpen = "Space ist OFFEN."
stateClosed = "Space ist zu."
@ -74,7 +76,7 @@ func AddXMPPListener(storage *spaceapi.Storage, jid, password, target, handle st
case xmpp.Chat:
switch v.Text {
case commandHelp:
if err := sendGroupMessage(client, target, helpMessage); err != nil {
if err := sendMessage(client, v.Remote, helpMessage); err != nil {
log.Printf("Error sending message: %s", err)
}
case commandState:
@ -90,10 +92,24 @@ func AddXMPPListener(storage *spaceapi.Storage, jid, password, target, handle st
}
}
if err := sendGroupMessage(client, target, msg); err != nil {
sendFunc := sendGroupMessage
replyTarget := target
if v.Type != "groupchat" {
sendFunc = sendMessage
replyTarget = v.Remote
}
if err := sendFunc(client, replyTarget, msg); err != nil {
log.Printf("Error sending message: %s", err)
}
case commandClose:
if v.Type != "groupchat" {
if err := sendMessage(client, v.Remote, errorNonPublic); err != nil {
log.Printf("Error sending message: %s", err)
}
continue
}
open := false
storage.Modify(func(status *spaceapi.SpaceStatus) {
status.State.Open = &open
@ -146,6 +162,20 @@ func lookupHost(jid string) (string, error) {
return fmt.Sprintf("%s:%d", addrs[0].Target, addrs[0].Port), nil
}
func sendMessage(client *xmpp.Client, target, msg string) error {
chat := xmpp.Chat{
Remote: target,
Type: "chat",
Text: msg,
}
if _, err := client.Send(chat); err != nil {
return err
}
return nil
}
func sendGroupMessage(client *xmpp.Client, target, msg string) error {
chat := xmpp.Chat{
Remote: target,

Loading…
Cancel
Save