Added ping command.

This commit is contained in:
Martin Dosch 2019-05-31 10:48:12 +02:00 committed by Martin Dosch
parent 0e7f42fcc1
commit 54c5bfce0b

View file

@ -264,6 +264,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
reply := ": The following commands are available:\n" + reply := ": The following commands are available:\n" +
"\"feeds\": List feeds I'm following.\n" + "\"feeds\": List feeds I'm following.\n" +
"\"ping\": Sends back a pong.\n" +
"\"source\": Show source code URL." "\"source\": Show source code URL."
if v.Type == "groupchat" { if v.Type == "groupchat" {
@ -323,6 +324,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. // Reply to pings and disco queries.