From 64fa3120eb834091abd7ffb0bceeac4d52226474 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 29 May 2020 20:12:37 +0200 Subject: [PATCH] mv append screen-name to transform --- README.md | 6 +++--- src/main/mastodon_bot/mastodon_api.cljs | 9 +++------ src/main/mastodon_bot/transform.cljs | 5 +++-- src/test/mastodon_bot/transform_test.cljs | 1 + 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3a703cc..76a6692 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,6 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w :visibility "unlisted" ;; optional limit for the post length :max-post-length 300 - ;; optional flag specifying wether the name of the account - ;; will be appended in the post, defaults to false - :append-screen-name? false ;; optionally try to resolve URLs in posts to skip URL shorteners ;; defaults to false :resolve-urls? true @@ -82,6 +79,9 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w ;; accounts you wish to mirror :accounts ["arstechnica" "WIRED"]} :target {:type :mastodon-target + ;; optional flag specifying wether the name of the account + ;; will be appended in the post, defaults to false + :append-screen-name? false ;; optional signature for posts :signature "#newsbot"}}] } diff --git a/src/main/mastodon_bot/mastodon_api.cljs b/src/main/mastodon_bot/mastodon_api.cljs index 78096be..4308850 100755 --- a/src/main/mastodon_bot/mastodon_api.cljs +++ b/src/main/mastodon_bot/mastodon_api.cljs @@ -29,12 +29,13 @@ (s/def ::content-filters (s/* ::content-filter)) (s/def ::keyword-filters (s/* ::keyword-filter)) (def mastodon-auth? (s/keys :req-un [::account-id ::access_token ::api_url])) -(def mastodon-target? (s/keys :req-un [ +(def mastodon-target? (s/keys :opt-un [ ;::content-filters ::keyword-filters ;::max-post-length ::signature ;::visibility - ;::append-screen-name? ::sensitive? ::resolve-urls? + ::append-screen-name? + ;::sensitive? ::resolve-urls? ;::nitter-urls? ::replacements ])) (def mastodon-config? (s/merge mastodon-auth? mastodon-target?)) @@ -48,10 +49,6 @@ [mastodon-config mastodon-config?] (mapv re-pattern (:keyword-filters mastodon-config))) -(defn-spec append-screen-name? ::append-screen-name? - [mastodon-config mastodon-config?] - (boolean (:append-screen-name? mastodon-config))) - (defn-spec max-post-length ::max-post-length [mastodon-config mastodon-config?] (:max-post-length mastodon-config)) diff --git a/src/main/mastodon_bot/transform.cljs b/src/main/mastodon_bot/transform.cljs index b29b882..173b6d7 100644 --- a/src/main/mastodon_bot/transform.cljs +++ b/src/main/mastodon_bot/transform.cljs @@ -47,15 +47,16 @@ :else text)) +; TODO: move this to mastodon-api - seems to belong strongly to mastodon (defn-spec intermediate-to-mastodon mastodon-output? [mastodon-auth masto/mastodon-auth? target masto/mastodon-target? input input?] (let [{:keys [created-at text media-links screen_name untrimmed-text]} input - {:keys [signature]} target + {:keys [signature append-screen-name?]} target untrimmed (if (some? untrimmed-text) (str " " untrimmed-text) "") - sname (if (masto/append-screen-name? mastodon-auth) + sname (if (some? append-screen-name?) (str "\n#" screen_name) "") signature_text (if (some? signature) (str "\n" signature) diff --git a/src/test/mastodon_bot/transform_test.cljs b/src/test/mastodon_bot/transform_test.cljs index 856b3f3..8f181b8 100755 --- a/src/test/mastodon_bot/transform_test.cljs +++ b/src/test/mastodon_bot/transform_test.cljs @@ -14,4 +14,5 @@ :include-rts? true :accounts ["an-twitter-account"]} :target {:type :mastodon-target + :append-screen-name? true :signature "my-bot"}}])))