added support for filtering out content

This commit is contained in:
Sotnikov, Dmitri 2018-04-23 17:47:41 -04:00
parent 9ed32f147c
commit 6dab0a4ebd
2 changed files with 12 additions and 2 deletions

View file

@ -37,7 +37,10 @@ the bot will post the timeline from the specified Twitter/Tumblr accounts and RS
:api_url "https://botsin.space/api/v1/"
:max-post-length 300
;; optional signature for posts
:signature "#newsbot"}}
:signature "#newsbot"
;; optional content filter regexes
;; any posts matching the regexes will be filtered out
:content-filters [".*bannedsite.*"]}}
```
* 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

View file

@ -20,6 +20,11 @@
(def config (-> (find-config) fs/readFileSync str edn/read-string))
(def content-filter-regexes (mapv re-pattern (-> config :mastodon :content-filters)))
(defn blocked-content? [text]
(boolean (some #(re-matches % text) content-filter-regexes)))
(def max-post-length (or (-> config :mastodon :max-post-length) 300))
(def mastodon-client (or (some-> config :mastodon clj->js mastodon.)
@ -72,7 +77,9 @@
(.then (.get mastodon-client "timelines/home" #js {}) #(-> % .-data js->edn callback)))
(defn post-items [last-post-time items]
(doseq [{:keys [text media-links]} (filter #(> (:created-at %) last-post-time) items)]
(doseq [{:keys [text media-links]} (->> items
(remove #(blocked-content? (:text %)))
(filter #(> (:created-at %) last-post-time)))]
(if media-links
(post-status-with-images text media-links)
(post-status text))))