Added contact information and quiet mode.

This commit is contained in:
Martin Dosch 2019-05-31 12:04:53 +02:00
parent e098d6f2e2
commit 34004d8e01
3 changed files with 44 additions and 4 deletions

View file

@ -44,9 +44,11 @@ If the flag `-config` is not used the configuration is expected at
"Password": "ChangeThis!",
"Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot",
"Contact": "xmpp:botadmin@example.com",
"MaxArticles": 5,
"RefreshTime": 30,
"NoExcerpt": false,
"Quiet": false,
"Filter": [ "submitted by", "[link]" ],
"Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long",
@ -58,5 +60,13 @@ If the flag `-config` is not used the configuration is expected at
feed and query. If `NoExcerpt` is set to *true* no excerpt will be
posted. `RefreshTime` defines the intervall for checking the feeds
in seconds.
With `Filter` you can specify strings for filtering out lines
beginning with those strings.
`Contact` is for providing contact information about who is running
the bot.
If you don't want additional noise in the MUC you can set `Quiet`
to disable bot queries (e.g. *contact*) in the MUC (queries per
private message are still available).

View file

@ -4,10 +4,13 @@
"Password": "ChangeThis!",
"Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot",
"Contact": "xmpp:botadmin@example.com",
"MaxArticles": 5,
"RefreshTime": 30,
"NoExcerpt": false,
"Quiet": false,
"Filter": [ "submitted by", "[link]" ],
"Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ]
"https://www.debian.org/security/dsa-long",
"https://www.reddit.com/r/FDroidUpdates/new.rss" ]
}

View file

@ -38,6 +38,8 @@ func main() {
MaxArticles int
RefreshTime time.Duration
NoExcerpt bool
Quiet bool
Contact string
Filter []string
Feeds []string
}
@ -139,7 +141,7 @@ func main() {
go pingMUC(client, config.BotJid, config.Muc, config.MucNick)
// Starting goroutine to process received stanzas.
go processStanzas(client, config.Muc, config.MucNick, config.Feeds)
go processStanzas(client, config.Muc, config.MucNick, config.Feeds, config.Quiet, config.Contact)
// Set RefreshTime to 30 seconds if not defined.
if config.RefreshTime == 0 {
@ -214,7 +216,7 @@ func pingServer(client *xmpp.Client, server string, botJid string) {
}
}
func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []string) {
func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []string, quiet bool, contact string) {
for { // Receive stanzas. ToDo: Receive stanzas continiously without 30s delay.
stanza, err := client.Recv()
if err != nil {
@ -229,6 +231,10 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
// Check for room mention of the bots nick if the the message type is groupchat.
if v.Type == "groupchat" {
// Leave if option quiet is set.
if quiet == true {
break
}
// Get first word of the message and transform it to lower case.
mention := strings.ToLower(strings.Split(v.Text, " ")[0])
@ -264,6 +270,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
case "help":
reply := "The following commands are available:\n" +
"\"contact\": Show contact for this bot.\n" +
"\"feeds\": List feeds I'm following.\n" +
"\"ping\": Sends back a pong.\n" +
"\"source\": Show source code URL."
@ -342,6 +349,26 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
}
}
case "contact":
if contact == "" {
contact = "Sorry, no contact information provided."
}
if v.Type == "groupchat" {
_, err = client.Send(xmpp.Chat{Remote: muc,
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + contact})
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: contact})
if err != nil {
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
}
}
}
// Reply to pings and disco queries.