mv replacements to transform

master
jem 4 years ago
parent cab5e24845
commit 9c525deb9d

@ -84,7 +84,9 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
:content-filters [".*bannedsite.*"]
;; optional keyword filter regexes
;; any posts not matching the regexes will be filtered out
:keyword-filters [".*clojure.*"]}]
:keyword-filters [".*clojure.*"]
;; TODO: Description & example missing here
:replacements nil}]
}
```

@ -16,7 +16,6 @@
(s/def ::sensitive? boolean?)
(s/def ::media-only? boolean?)
(s/def ::visibility #{"direct" "private" "unlisted" "public"})
(s/def ::replacements string?)
(s/def ::max-post-length (fn [n] (and
(int? n)
(<= n 500)
@ -30,7 +29,6 @@
::append-screen-name?
::sensitive?
::media-only?
;::replacements
]))
(def mastodon-config? (s/merge mastodon-auth? mastodon-target?))
@ -39,11 +37,6 @@
[target mastodon-target?]
(:max-post-length target))
(defn-spec perform-replacements string?
[mastodon-config mastodon-config?
text string?]
(reduce-kv string/replace text (:replacements mastodon-config)))
(defn-spec mastodon-client any?
[mastodon-auth mastodon-auth?]
(or (some-> mastodon-auth
@ -64,8 +57,7 @@
([mastodon-auth target status-text media-ids callback]
(let [{:keys [visibility sensitive?]} target]
(-> (.post (mastodon-client mastodon-auth) "statuses"
(clj->js (merge {:status (->> status-text
(perform-replacements mastodon-auth))}
(clj->js (merge {:status status-text}
(when media-ids {:media_ids media-ids})
(when sensitive? {:sensitive sensitive?})
(when visibility {:visibility visibility}))))

@ -26,6 +26,7 @@
(s/def ::content-filters (s/* ::content-filter))
(s/def ::keyword-filter string?)
(s/def ::keyword-filters (s/* ::keyword-filter))
(s/def ::replacements any?)
(defmulti source-type :type)
(defmethod source-type :twitter-source [_]
(s/merge (s/keys :req-un[::type]) twitter/twitter-source?))
@ -36,7 +37,7 @@
(s/def ::target (s/multi-spec target-type ::type))
(s/def ::transformation (s/keys :req-un [::source ::target]
:opt-un [::resolve-urls? ::content-filters ::keyword-filters]))
:opt-un [::resolve-urls? ::content-filters ::keyword-filters ::replacements]))
(def transformations? (s/* ::transformation))
(defn trim-text [text max-post-length]
@ -93,6 +94,11 @@
(when (not-empty (keyword-filter-regexes transformation))
(empty? (some #(re-find % text) (keyword-filter-regexes transformation)))))))
(defn-spec perform-replacements string?
[transformation ::transformation
input input?]
(update input :text #(reduce-kv string/replace % (:replacements transformation))))
; TODO: move this to mastodon-api - seems to belong strongly to mastodon
(defn-spec intermediate-to-mastodon mastodon-output?
@ -132,6 +138,7 @@
(remove #(blocked-content? transformation (:text %)))
(map #(intermediate-resolve-urls resolve-urls? %))
(map #(twitter/nitter-url source %))
(map #(perform-replacements transformation %))
(map #(intermediate-to-mastodon mastodon-auth target %))
(masto/post-items mastodon-auth target last-post-time))))))