|
|
@ -29,8 +29,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
(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))
|
|
|
|
(s/def ::mastodon-js-config (s/keys :req [::access_token ::api_url]))
|
|
|
|
(s/def ::mastodon-js-config (s/keys :req-un [::access_token ::api_url]))
|
|
|
|
(s/def ::mastodon-clj-config (s/keys :req [::account-id ::content-filters ::keyword-filters
|
|
|
|
(s/def ::mastodon-clj-config (s/keys :req-un [::account-id ::content-filters ::keyword-filters
|
|
|
|
::max-post-length ::signature ::visibility
|
|
|
|
::max-post-length ::signature ::visibility
|
|
|
|
::append-screen-name? ::sensitive? ::resolve-urls?
|
|
|
|
::append-screen-name? ::sensitive? ::resolve-urls?
|
|
|
|
::nitter-urls? ::replacements]))
|
|
|
|
::nitter-urls? ::replacements]))
|
|
|
@ -38,24 +38,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec content-filter-regexes ::content-filters
|
|
|
|
(defn-spec content-filter-regexes ::content-filters
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
(mapv re-pattern (::content-filters mastodon-config)))
|
|
|
|
(mapv re-pattern (:content-filters mastodon-config)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec keyword-filter-regexes ::keyword-filters
|
|
|
|
(defn-spec keyword-filter-regexes ::keyword-filters
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
(mapv re-pattern (::keyword-filters mastodon-config)))
|
|
|
|
(mapv re-pattern (:keyword-filters mastodon-config)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec append-screen-name? ::append-screen-name?
|
|
|
|
(defn-spec append-screen-name? ::append-screen-name?
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
(boolean (::append-screen-name? mastodon-config)))
|
|
|
|
(boolean (:append-screen-name? mastodon-config)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec max-post-length ::max-post-length
|
|
|
|
(defn-spec max-post-length ::max-post-length
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
(::max-post-length mastodon-config))
|
|
|
|
(:max-post-length mastodon-config))
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec perform-replacements string?
|
|
|
|
(defn-spec perform-replacements string?
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
text string?]
|
|
|
|
text string?]
|
|
|
|
(reduce-kv string/replace text (::replacements mastodon-config)))
|
|
|
|
(reduce-kv string/replace text (:replacements mastodon-config)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn-spec mastodon-client any?
|
|
|
|
(defn-spec mastodon-client any?
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
|
[mastodon-config mastodon-config?]
|
|
|
@ -94,15 +94,15 @@
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
text string?]
|
|
|
|
text string?]
|
|
|
|
(cond-> text
|
|
|
|
(cond-> text
|
|
|
|
(::resolve-urls? mastodon-config)
|
|
|
|
(:resolve-urls? mastodon-config)
|
|
|
|
(string/replace shortened-url-pattern resolve-url)
|
|
|
|
(string/replace shortened-url-pattern resolve-url)
|
|
|
|
(::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?
|
|
|
|
(defn-spec set-signature string?
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
[mastodon-config mastodon-config?
|
|
|
|
text string?]
|
|
|
|
text string?]
|
|
|
|
(if-let [signature (::signature mastodon-config )]
|
|
|
|
(if-let [signature (:signature mastodon-config )]
|
|
|
|
(str text "\n" signature)
|
|
|
|
(str text "\n" signature)
|
|
|
|
text))
|
|
|
|
text))
|
|
|
|
|
|
|
|
|
|
|
@ -112,7 +112,7 @@
|
|
|
|
([mastodon-config status-text media-ids]
|
|
|
|
([mastodon-config status-text media-ids]
|
|
|
|
(post-status mastodon-config status-text media-ids print))
|
|
|
|
(post-status mastodon-config status-text media-ids print))
|
|
|
|
([mastodon-config status-text media-ids callback]
|
|
|
|
([mastodon-config status-text media-ids callback]
|
|
|
|
(let [{:mastodon-bot.mastodon-api/keys [sensitive? signature visibility]} mastodon-config]
|
|
|
|
(let [{:keys [sensitive? signature visibility]} mastodon-config]
|
|
|
|
(-> (.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)
|
|
|
@ -134,22 +134,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
(defn post-status-with-images
|
|
|
|
(defn post-status-with-images
|
|
|
|
([mastodon-config status-text urls]
|
|
|
|
([mastodon-config status-text urls]
|
|
|
|
(post-status-with-images mastodon-config status-text urls []))
|
|
|
|
(post-status-with-images mastodon-config status-text urls [] print))
|
|
|
|
([mastodon-config status-text [url & urls] ids]
|
|
|
|
([mastodon-config status-text urls ids]
|
|
|
|
|
|
|
|
(post-status-with-images mastodon-config status-text urls ids print))
|
|
|
|
|
|
|
|
([mastodon-config status-text [url & urls] ids callback]
|
|
|
|
(if url
|
|
|
|
(if url
|
|
|
|
(-> request
|
|
|
|
(-> request
|
|
|
|
(.get url)
|
|
|
|
(.get url)
|
|
|
|
(.on "response"
|
|
|
|
(.on "response"
|
|
|
|
(fn [image-stream]
|
|
|
|
(fn [image-stream]
|
|
|
|
(post-image mastodon-config image-stream status-text
|
|
|
|
(post-image mastodon-config image-stream status-text
|
|
|
|
#(post-status-with-images status-text urls (conj ids %))))))
|
|
|
|
#(post-status-with-images status-text urls (conj ids %) callback)))))
|
|
|
|
(post-status mastodon-config status-text (not-empty ids)))))
|
|
|
|
(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-config mastodon-config?
|
|
|
|
callback fn?]
|
|
|
|
callback fn?]
|
|
|
|
(.then (.get (mastodon-client mastodon-config)
|
|
|
|
(.then (.get (mastodon-client mastodon-config)
|
|
|
|
(str "accounts/" (::account-id mastodon-config)"/statuses") #js {})
|
|
|
|
(str "accounts/" (:account-id mastodon-config)"/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)
|
|
|
|