Allow configuring 'replacements'

This commit is contained in:
Arnout Engelen 2020-04-11 12:15:31 +02:00
parent dfb1685569
commit 3f9cd958f5
No known key found for this signature in database
GPG key ID: 061107B0F74A6DAA
4 changed files with 27 additions and 1 deletions

View file

@ -131,10 +131,15 @@
(exit-with-error error)
(callback response)))))
(defn perform-replacements [post]
(assoc post :text (reduce-kv string/replace (:text post) (:replacements mastodon-config)))
)
(defn post-items [last-post-time items]
(doseq [{:keys [text media-links]} (->> items
(remove #(blocked-content? (:text %)))
(filter #(> (:created-at %) last-post-time)))]
(filter #(> (:created-at %) last-post-time))
(map perform-replacements))]
(if media-links
(post-status-with-images text media-links)
(when-not (:media-only? mastodon-config)

View file

@ -26,6 +26,12 @@
(:text (core/parse-tweet (readfile "testdata/twitter/normal-tweet.edn")))
)))
(deftest test-replacements
(is (=
"💠 Check out what has been going on during March in the world of @ReproBuilds! 💠 https://t.co/k6NsSO115z @opensuse@fosstodon.org @conservancy@mastodon.technology @PrototypeFund@mastodon.social @debian@fosstodon.org "
(:text (core/perform-replacements (core/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn"))))
)))
(cljs.test/run-tests)
; Don't run core's -main when testing

View file

@ -51,5 +51,19 @@
;; optional keyword filter regexes
;; any posts not matching the regexes will be filtered out
:keyword-filters [".*clojure.*"]
;; optional replacements
:replacements {"@openSUSE " "@opensuse@fosstodon.org ",
"@archlinux " "",
"@lolamby " "",
"@conservancy " "@conservancy@mastodon.technology ",
"@prototypefund " "@PrototypeFund@mastodon.social ",
"@coreboot_org " "",
"@OpenTechFund " "",
"@OpenWrtSummit " "",
"@OpenMirage " "",
"@debian " "@debian@fosstodon.org ",
"@nixos_org " "",
"@lwnnet " "",
"@guixhpc" ""}
;; Replace Twitter links by Nitter
:nitter-urls? false}}

1
testdata/twitter/tweet-mentions.edn vendored Normal file

File diff suppressed because one or more lines are too long