From 45d787105895b91e3e773b3c193c5ada9a65dbd2 Mon Sep 17 00:00:00 2001 From: "Sotnikov, Dmitri" Date: Tue, 9 Oct 2018 11:59:50 -0400 Subject: [PATCH] added :keyword-filters flag --- README.md | 5 ++++- mastodon-bot.cljs | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff2dbec..7dae171 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,10 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206) :resolve-urls? true ;; optional content filter regexes ;; any posts matching the regexes will be filtered out - :content-filters [".*bannedsite.*"]}} + :content-filters [".*bannedsite.*"] + ;; optional keyword filter regexes + ;; any posts not matching the regexes will be filtered out + :keyword-filters [".*clojure.*"]}} ``` * the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument diff --git a/mastodon-bot.cljs b/mastodon-bot.cljs index 18eefdd..372797f 100755 --- a/mastodon-bot.cljs +++ b/mastodon-bot.cljs @@ -31,12 +31,17 @@ (def content-filter-regexes (mapv re-pattern (:content-filters mastodon-config))) +(def keyword-filter-regexes (mapv re-pattern (:keyword-filters mastodon-config))) + (def append-screen-name? (boolean (:append-screen-name? mastodon-config))) (def max-post-length (:max-post-length mastodon-config)) (defn blocked-content? [text] - (boolean (some #(re-find % text) content-filter-regexes))) + (boolean + (or (some #(re-find % text) content-filter-regexes) + (when (not-empty keyword-filter-regexes) + (empty? (some #(re-find % text) keyword-filter-regexes)))))) (defn js->edn [data] (js->clj data :keywordize-keys true))