moved signature tor transform
This commit is contained in:
parent
21c908ea85
commit
1072af0145
6 changed files with 62 additions and 51 deletions
|
@ -63,8 +63,6 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
|
|||
;; 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"
|
||||
;; optionally try to resolve URLs in posts to skip URL shorteners
|
||||
;; defaults to false
|
||||
:resolve-urls? true
|
||||
|
@ -83,7 +81,9 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
|
|||
:include-rts? false
|
||||
;; accounts you wish to mirror
|
||||
:accounts ["arstechnica" "WIRED"]}
|
||||
:target {}}]
|
||||
:target {:type :mastodon-target
|
||||
;; optional signature for posts
|
||||
:signature "#newsbot"}}]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -43,7 +43,9 @@
|
|||
:posts
|
||||
(mapv tumblr/parse-tumblr-post)
|
||||
(map #(transform/to-mastodon
|
||||
(mastodon-auth config) %))
|
||||
(mastodon-auth config)
|
||||
;todo: fix this
|
||||
(:target (first (transform config))) %))
|
||||
(masto/post-items
|
||||
(mastodon-auth config)
|
||||
last-post-time))))
|
||||
|
|
|
@ -28,12 +28,17 @@
|
|||
|
||||
(s/def ::content-filters (s/* ::content-filter))
|
||||
(s/def ::keyword-filters (s/* ::keyword-filter))
|
||||
(def mastodon-auth? (s/keys :req-un [::access_token ::api_url]))
|
||||
(def mastodon-transform? (s/keys :req-un [::account-id ::content-filters ::keyword-filters
|
||||
::max-post-length ::signature ::visibility
|
||||
::append-screen-name? ::sensitive? ::resolve-urls?
|
||||
::nitter-urls? ::replacements]))
|
||||
(def mastodon-config? (s/merge mastodon-auth? mastodon-transform?))
|
||||
(def mastodon-auth? (s/keys :req-un [::account-id ::access_token ::api_url]))
|
||||
(def mastodon-target? (s/keys :req-un [
|
||||
;::content-filters ::keyword-filters
|
||||
;::max-post-length
|
||||
::signature
|
||||
;::visibility
|
||||
;::append-screen-name? ::sensitive? ::resolve-urls?
|
||||
;::nitter-urls? ::replacements
|
||||
]))
|
||||
(def mastodon-config? (s/merge mastodon-auth? mastodon-target?))
|
||||
|
||||
|
||||
(defn-spec content-filter-regexes ::content-filters
|
||||
[mastodon-config mastodon-config?]
|
||||
|
@ -103,13 +108,6 @@
|
|||
(:nitter-urls? mastodon-config)
|
||||
(string/replace #"https://twitter.com" "https://nitter.net")))
|
||||
|
||||
(defn-spec set-signature string?
|
||||
[mastodon-config mastodon-config?
|
||||
text string?]
|
||||
(if-let [signature (:signature mastodon-config )]
|
||||
(str text "\n" signature)
|
||||
text))
|
||||
|
||||
(defn post-status
|
||||
([mastodon-config status-text]
|
||||
(post-status mastodon-config status-text nil print))
|
||||
|
@ -120,8 +118,7 @@
|
|||
(-> (.post (mastodon-client mastodon-config) "statuses"
|
||||
(clj->js (merge {:status (->> status-text
|
||||
(resolve-urls mastodon-config)
|
||||
(perform-replacements mastodon-config)
|
||||
(set-signature mastodon-config))}
|
||||
(perform-replacements mastodon-config))}
|
||||
(when media-ids {:media_ids media-ids})
|
||||
(when sensitive? {:sensitive sensitive?})
|
||||
(when visibility {:visibility visibility}))))
|
||||
|
@ -152,10 +149,10 @@
|
|||
(post-status mastodon-config status-text (not-empty ids) callback))))
|
||||
|
||||
(defn-spec get-mastodon-timeline any?
|
||||
[mastodon-config mastodon-config?
|
||||
[mastodon-auth mastodon-auth?
|
||||
callback fn?]
|
||||
(.then (.get (mastodon-client mastodon-config)
|
||||
(str "accounts/" (:account-id mastodon-config)"/statuses") #js {})
|
||||
(.then (.get (mastodon-client mastodon-auth)
|
||||
(str "accounts/" (:account-id mastodon-auth)"/statuses") #js {})
|
||||
#(let [response (-> % .-data infra/js->edn)]
|
||||
(if-let [error (::error response)]
|
||||
(infra/exit-with-error error)
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
(defmethod source-type :twitter-source [_]
|
||||
(s/merge (s/keys :req-un[::type]) twitter/twitter-source?))
|
||||
(s/def ::source (s/multi-spec source-type ::type))
|
||||
(s/def ::target any?)
|
||||
(defmulti target-type :type)
|
||||
(defmethod target-type :mastodon-target [_]
|
||||
(s/merge (s/keys :req-un [::type]) masto/mastodon-target?))
|
||||
(s/def ::target (s/multi-spec target-type ::type))
|
||||
(s/def ::transformation (s/keys :req-un [::source ::target]))
|
||||
(def transformations? (s/* ::transformation))
|
||||
|
||||
|
@ -45,45 +48,53 @@
|
|||
:else text))
|
||||
|
||||
(defn-spec to-mastodon mastodon-output?
|
||||
[mastodon-config masto/mastodon-auth?
|
||||
[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
|
||||
untrimmed (if (some? untrimmed-text)
|
||||
(str " " untrimmed-text) "")
|
||||
sname (if (masto/append-screen-name? mastodon-config)
|
||||
sname (if (masto/append-screen-name? mastodon-auth)
|
||||
(str "\n - " screen_name) "")
|
||||
trim-length (- (masto/max-post-length mastodon-config)
|
||||
signature_text (if (some? signature)
|
||||
(str "\n" signature)
|
||||
"")
|
||||
trim-length (- (masto/max-post-length mastodon-auth)
|
||||
(count untrimmed)
|
||||
(count sname))]
|
||||
(count sname)
|
||||
(count signature_text))]
|
||||
{:created-at created-at
|
||||
:text (str (trim-text text trim-length)
|
||||
untrimmed
|
||||
sname)
|
||||
sname
|
||||
signature_text)
|
||||
:media-links media-links}))
|
||||
|
||||
(defn-spec post-tweets any?
|
||||
[mastodon-config masto/mastodon-auth?
|
||||
(defn-spec post-tweets-to-mastodon any?
|
||||
[mastodon-auth masto/mastodon-auth?
|
||||
target masto/mastodon-target?
|
||||
last-post-time any?]
|
||||
(fn [error tweets response]
|
||||
(if error
|
||||
(infra/exit-with-error error)
|
||||
(->> (infra/js->edn tweets)
|
||||
(map twitter/parse-tweet)
|
||||
(map #(to-mastodon mastodon-config %))
|
||||
(masto/post-items mastodon-config last-post-time)))))
|
||||
(map #(to-mastodon mastodon-auth target %))
|
||||
(masto/post-items mastodon-auth last-post-time)))))
|
||||
|
||||
(defn-spec tweets-to-mastodon any?
|
||||
[mastodon-auth masto/mastodon-auth?
|
||||
twitter-auth twitter/twitter-auth?
|
||||
transformation ::transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [source target]} transformation
|
||||
{:keys [accounts include-rts? include-replies?]} source]
|
||||
(doseq [account accounts]
|
||||
(println account)
|
||||
(let [{:keys [source target]} transformation]
|
||||
(doseq [account (:accounts source)]
|
||||
(twitter/user-timeline
|
||||
twitter-auth
|
||||
include-rts?
|
||||
include-replies?
|
||||
source
|
||||
account
|
||||
(post-tweets mastodon-auth last-post-time)))))
|
||||
(post-tweets-to-mastodon
|
||||
mastodon-auth
|
||||
target
|
||||
last-post-time)))))
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
(s/def ::include-replies? boolean?)
|
||||
(s/def ::account string?)
|
||||
(s/def ::accounts (s/* ::account))
|
||||
(def twitter-source? (s/keys :req-un [::include-rts? ::include-replies?]))
|
||||
(def twitter-source? (s/keys :req-un [::include-rts? ::include-replies? ::accounts]))
|
||||
|
||||
(defn-spec twitter-client any?
|
||||
[twitter-auth twitter-auth?]
|
||||
|
@ -53,15 +53,15 @@
|
|||
|
||||
(defn-spec user-timeline any?
|
||||
[twitter-auth twitter-auth?
|
||||
include-rts? ::include-rts?
|
||||
include-replies? ::include-replies?
|
||||
source twitter-source?
|
||||
account ::account
|
||||
callback fn?]
|
||||
(let [{:keys [include-rts? include-replies?]} source]
|
||||
(.get (twitter-client twitter-auth)
|
||||
"statuses/user_timeline"
|
||||
#js {:screen_name account
|
||||
:tweet_mode "extended"
|
||||
:include_rts (boolean include-rts?)
|
||||
:exclude_replies (not (boolean include-replies?))}
|
||||
callback))
|
||||
callback)))
|
||||
|
|
@ -13,4 +13,5 @@
|
|||
:include-replies? false
|
||||
:include-rts? true
|
||||
:accounts ["an-twitter-account"]}
|
||||
:target {}}])))
|
||||
:target {:type :mastodon-target
|
||||
:signature "my-bot"}}])))
|
||||
|
|
Reference in a new issue