mv media-only? & max-post-length to transform

master
jem 4 years ago
parent 6ec1930a71
commit dd62eab56b

@ -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 ;; e.g: https://mastodon.social/web/accounts/294795
:account-id "XXXX" :account-id "XXXX"
:api_url "https://botsin.space/api/v1/" :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 ;; optionally try to resolve URLs in posts to skip URL shorteners
;; defaults to false ;; defaults to false
:resolve-urls? true :resolve-urls? true
@ -82,6 +77,11 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
:visibility "unlisted" :visibility "unlisted"
;; optional boolean to mark content as sensitive ;; optional boolean to mark content as sensitive
:sensitive? true :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 ;; optional signature for posts
:signature "#newsbot"}}] :signature "#newsbot"}}]
} }

@ -61,7 +61,7 @@
{:created-at (js/Date. (or isoDate pubDate)) {:created-at (js/Date. (or isoDate pubDate))
:text (str (transform/trim-text :text (str (transform/trim-text
title title
(masto/max-post-length (mastodon-auth config))) (masto/max-post-length (:target (first (transform config)))))
"\n\n" (twitter/strip-utm link))}))))) "\n\n" (twitter/strip-utm link))})))))
(defn -main [] (defn -main []

@ -17,6 +17,7 @@
(s/def ::append-screen-name? boolean?) (s/def ::append-screen-name? boolean?)
(s/def ::signature string?) (s/def ::signature string?)
(s/def ::sensitive? boolean?) (s/def ::sensitive? boolean?)
(s/def ::media-only? boolean?)
(s/def ::resolve-urls? boolean?) (s/def ::resolve-urls? boolean?)
(s/def ::nitter-urls? boolean?) (s/def ::nitter-urls? boolean?)
(s/def ::visibility #{"direct" "private" "unlisted" "public"}) (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-auth? (s/keys :req-un [::account-id ::access_token ::api_url]))
(def mastodon-target? (s/keys :opt-un [ (def mastodon-target? (s/keys :opt-un [
;::content-filters ::keyword-filters ;::content-filters ::keyword-filters
;::max-post-length ::max-post-length
::signature ::signature
::visibility ::visibility
::append-screen-name? ::append-screen-name?
::sensitive? ::sensitive?
::media-only?
;::resolve-urls? ;::resolve-urls?
;::nitter-urls? ::replacements ;::nitter-urls? ::replacements
])) ]))
@ -51,8 +53,8 @@
(mapv re-pattern (:keyword-filters mastodon-config))) (mapv re-pattern (:keyword-filters mastodon-config)))
(defn-spec max-post-length ::max-post-length (defn-spec max-post-length ::max-post-length
[mastodon-config mastodon-config?] [target mastodon-target?]
(:max-post-length mastodon-config)) (:max-post-length target))
(defn-spec perform-replacements string? (defn-spec perform-replacements string?
[mastodon-config mastodon-config? [mastodon-config mastodon-config?
@ -163,7 +165,7 @@
(filter #(> (:created-at %) last-post-time)))] (filter #(> (:created-at %) last-post-time)))]
(if media-links (if media-links
(post-status-with-images mastodon-auth target text 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))))) (post-status mastodon-auth target text)))))
(defn-spec get-mastodon-timeline any? (defn-spec get-mastodon-timeline any?

@ -61,7 +61,7 @@
signature_text (if (some? signature) signature_text (if (some? signature)
(str "\n" signature) (str "\n" signature)
"") "")
trim-length (- (masto/max-post-length mastodon-auth) trim-length (- (masto/max-post-length target)
(count untrimmed) (count untrimmed)
(count sname) (count sname)
(count signature_text))] (count signature_text))]

@ -15,6 +15,8 @@
:accounts ["an-twitter-account"]} :accounts ["an-twitter-account"]}
:target {:type :mastodon-target :target {:type :mastodon-target
:append-screen-name? true :append-screen-name? true
:media-only? false
:max-post-length 500
:visibility "unlisted" :visibility "unlisted"
:sensitive? true :sensitive? true
:signature "my-bot"}}]))) :signature "my-bot"}}])))