From a3b51d1e5cf08875ca13f31a15766a00e0d8ee8d Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 6 May 2020 10:20:55 +0200 Subject: [PATCH] 'perform-replacements' after 'resolve-urls' This simplifies things overall, and avoids resolve-urls replacing mentions like '@foo@bar.org' with links to the 'about' page of the instance. Unfortunately this wasn't easy to add a test for. --- mastodon_bot/core.cljs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mastodon_bot/core.cljs b/mastodon_bot/core.cljs index 9e02d6a..ee3bee0 100755 --- a/mastodon_bot/core.cljs +++ b/mastodon_bot/core.cljs @@ -92,6 +92,9 @@ (:nitter-urls? mastodon-config) (string/replace #"https://twitter.com" "https://nitter.net"))) +(defn perform-replacements [text] + (reduce-kv string/replace text (:replacements mastodon-config))) + (defn set-signature [text] (if-let [signature (:signature mastodon-config )] (str text "\n" signature) @@ -103,7 +106,7 @@ ([status-text media-ids] (let [{:keys [sensitive? signature visibility]} mastodon-config] (.post mastodon-client "statuses" - (clj->js (merge {:status (-> status-text resolve-urls set-signature)} + (clj->js (merge {:status (-> status-text resolve-urls perform-replacements set-signature)} (when media-ids {:media_ids media-ids}) (when sensitive? {:sensitive sensitive?}) (when visibility {:visibility visibility}))))))) @@ -131,15 +134,10 @@ (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)) - (map perform-replacements))] + (filter #(> (:created-at %) last-post-time)))] (if media-links (post-status-with-images text media-links) (when-not (:media-only? mastodon-config)