From 54c5bfce0b307f69f1ec56946058829271d2ecbb Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Fri, 31 May 2019 10:48:12 +0200 Subject: [PATCH] Added ping command. --- feed-to-muc.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/feed-to-muc.go b/feed-to-muc.go index 160e34a..cb3bbd7 100644 --- a/feed-to-muc.go +++ b/feed-to-muc.go @@ -264,6 +264,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" { @@ -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.