diff --git a/README.md b/README.md index cd3ade6..33c9a3b 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ If the flag `-config` is not used the configuration is expected at "NoExcerpt": false, "Quiet": false, "Filter": [ "submitted by", "[link]" ], +"FilterMessage": [ "Block me!", "Block me too!" ], "Feeds": [ "https://www.debian.org/News/news", "https://www.debian.org/security/dsa-long", "https://www.reddit.com/r/FDroidUpdates/new.rss" ] @@ -62,7 +63,8 @@ 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. +beginning with those strings, with `FilterMessage` you can filter +out complete postings containing the string. `Contact` is for providing contact information about who is running the bot. diff --git a/getArticles.go b/getArticles.go index 52b059a..09b1b1c 100644 --- a/getArticles.go +++ b/getArticles.go @@ -18,7 +18,7 @@ import ( ) // Get new articles for specified feed. -func getArticles(feedURL string, max int, noExcerpt bool, filter []string) (string, error) { +func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filterMessage []string) (string, error) { type feedCache struct { LastChange string @@ -203,6 +203,18 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string) (stri // Only send title and link if option noExcerpt is set, // otherwise add the description. if noExcerpt { + // Stop processing the title if it contains the string + // configured in FilterMessage + filterStrike := false + for _, filterString := range filterMessage { + if strings.Contains(feed.Title, filterString) { + filterStrike = true + } + } + if filterStrike { + continue + } + output = output + feed.Title + ": *" + article.Title + "*\n" + cleanURL } else { @@ -224,6 +236,18 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string) (stri } } + // Stop processing the article if it contains the string + // configured in FilterMessage + filterStrike := false + for _, filterString := range filterMessage { + if strings.Contains(description, filterString) { + filterStrike = true + } + } + if filterStrike { + continue + } + // Remove lines only consisting of "> "; thank you reddit. description = strings.Replace(description, "> \n", "", -1) diff --git a/main.go b/main.go index b3093ba..027e4b2 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ type configuration struct { Quiet bool Contact string Filter []string + FilterMessage []string Feeds []string } @@ -83,7 +84,7 @@ func main() { // Check all configured feeds for new articles and send // new articles to configured MUC. for i := 0; i < len(config.Feeds); i++ { - output, err := getArticles(config.Feeds[i], config.MaxArticles, config.NoExcerpt, config.Filter) + output, err := getArticles(config.Feeds[i], config.MaxArticles, config.NoExcerpt, config.Filter, config.FilterMessage) if err != nil { // Exit if an error occurs checking the feeds. log.Fatal("Error: Can't check feeds for new articles: ", err)