From dd62eab56bfac7a08a63aef4723f28d0d2c34cbf Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 29 May 2020 21:32:41 +0200 Subject: [PATCH] mv media-only? & max-post-length to transform --- README.md | 10 +++++----- src/main/mastodon_bot/core.cljs | 2 +- src/main/mastodon_bot/mastodon_api.cljs | 12 +++++++----- src/main/mastodon_bot/transform.cljs | 2 +- src/test/mastodon_bot/transform_test.cljs | 2 ++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8396226..e2531e2 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,6 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w ;; e.g: https://mastodon.social/web/accounts/294795 :account-id "XXXX" :api_url "https://botsin.space/api/v1/" - ;; optional boolean defaults to false - ;; only sources containing media will be posted when set to true - :media-only? true - ;; optional limit for the post length - :max-post-length 300 ;; optionally try to resolve URLs in posts to skip URL shorteners ;; defaults to false :resolve-urls? true @@ -82,6 +77,11 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w :visibility "unlisted" ;; optional boolean to mark content as sensitive :sensitive? true + ;; optional boolean defaults to false + ;; only sources containing media will be posted when set to true + :media-only? true + ;; optional limit for the post length + :max-post-length 300 ;; optional signature for posts :signature "#newsbot"}}] } diff --git a/src/main/mastodon_bot/core.cljs b/src/main/mastodon_bot/core.cljs index 11b5c53..da5bd60 100755 --- a/src/main/mastodon_bot/core.cljs +++ b/src/main/mastodon_bot/core.cljs @@ -61,7 +61,7 @@ {:created-at (js/Date. (or isoDate pubDate)) :text (str (transform/trim-text title - (masto/max-post-length (mastodon-auth config))) + (masto/max-post-length (:target (first (transform config))))) "\n\n" (twitter/strip-utm link))}))))) (defn -main [] diff --git a/src/main/mastodon_bot/mastodon_api.cljs b/src/main/mastodon_bot/mastodon_api.cljs index f1e69d3..20e53d6 100755 --- a/src/main/mastodon_bot/mastodon_api.cljs +++ b/src/main/mastodon_bot/mastodon_api.cljs @@ -17,6 +17,7 @@ (s/def ::append-screen-name? boolean?) (s/def ::signature string?) (s/def ::sensitive? boolean?) +(s/def ::media-only? boolean?) (s/def ::resolve-urls? boolean?) (s/def ::nitter-urls? boolean?) (s/def ::visibility #{"direct" "private" "unlisted" "public"}) @@ -31,11 +32,12 @@ (def mastodon-auth? (s/keys :req-un [::account-id ::access_token ::api_url])) (def mastodon-target? (s/keys :opt-un [ ;::content-filters ::keyword-filters - ;::max-post-length + ::max-post-length ::signature ::visibility ::append-screen-name? - ::sensitive? + ::sensitive? + ::media-only? ;::resolve-urls? ;::nitter-urls? ::replacements ])) @@ -51,8 +53,8 @@ (mapv re-pattern (:keyword-filters mastodon-config))) (defn-spec max-post-length ::max-post-length - [mastodon-config mastodon-config?] - (:max-post-length mastodon-config)) + [target mastodon-target?] + (:max-post-length target)) (defn-spec perform-replacements string? [mastodon-config mastodon-config? @@ -163,7 +165,7 @@ (filter #(> (:created-at %) last-post-time)))] (if media-links (post-status-with-images mastodon-auth target text media-links) - (when-not (::media-only? mastodon-auth) + (when-not (:media-only? target) (post-status mastodon-auth target text))))) (defn-spec get-mastodon-timeline any? diff --git a/src/main/mastodon_bot/transform.cljs b/src/main/mastodon_bot/transform.cljs index d2b1c3a..cc21cb0 100644 --- a/src/main/mastodon_bot/transform.cljs +++ b/src/main/mastodon_bot/transform.cljs @@ -61,7 +61,7 @@ signature_text (if (some? signature) (str "\n" signature) "") - trim-length (- (masto/max-post-length mastodon-auth) + trim-length (- (masto/max-post-length target) (count untrimmed) (count sname) (count signature_text))] diff --git a/src/test/mastodon_bot/transform_test.cljs b/src/test/mastodon_bot/transform_test.cljs index a6b5960..5865476 100755 --- a/src/test/mastodon_bot/transform_test.cljs +++ b/src/test/mastodon_bot/transform_test.cljs @@ -15,6 +15,8 @@ :accounts ["an-twitter-account"]} :target {:type :mastodon-target :append-screen-name? true + :media-only? false + :max-post-length 500 :visibility "unlisted" :sensitive? true :signature "my-bot"}}])))