Added ping command.

This commit is contained in:
Martin Dosch 2019-05-31 10:48:12 +02:00
parent c65088b455
commit 0e5d19bf5b

View file

@ -265,6 +265,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
reply := ": The following commands are available:\n" +
"\"feeds\": List feeds I'm following.\n" +
"\"ping\": Sends back a pong.\n" +
"\"source\": Show source code URL."
if v.Type == "groupchat" {
@ -324,6 +325,23 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
}
}
case "ping":
reply := "pong"
if v.Type == "groupchat" {
_, err = client.Send(xmpp.Chat{Remote: muc,
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply})
if err != nil {
log.Fatal("Error: Failed sending message to MUC:", err)
}
} else if v.Type == "chat" {
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
Type: "chat", Text: reply})
if err != nil {
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
}
}
}
// Reply to pings and disco queries.