diff --git a/README.md b/README.md index 85b45b5..4311799 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mastodon-bot.cljs b/mastodon-bot.cljs index 790e750..5afdd54 100755 --- a/mastodon-bot.cljs +++ b/mastodon-bot.cljs @@ -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))))