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