mv replacements to transform
This commit is contained in:
parent
cab5e24845
commit
9c525deb9d
3 changed files with 12 additions and 11 deletions
|
@ -84,7 +84,9 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
|
||||||
:content-filters [".*bannedsite.*"]
|
:content-filters [".*bannedsite.*"]
|
||||||
;; optional keyword filter regexes
|
;; optional keyword filter regexes
|
||||||
;; any posts not matching the regexes will be filtered out
|
;; 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 ::sensitive? boolean?)
|
||||||
(s/def ::media-only? boolean?)
|
(s/def ::media-only? boolean?)
|
||||||
(s/def ::visibility #{"direct" "private" "unlisted" "public"})
|
(s/def ::visibility #{"direct" "private" "unlisted" "public"})
|
||||||
(s/def ::replacements string?)
|
|
||||||
(s/def ::max-post-length (fn [n] (and
|
(s/def ::max-post-length (fn [n] (and
|
||||||
(int? n)
|
(int? n)
|
||||||
(<= n 500)
|
(<= n 500)
|
||||||
|
@ -30,7 +29,6 @@
|
||||||
::append-screen-name?
|
::append-screen-name?
|
||||||
::sensitive?
|
::sensitive?
|
||||||
::media-only?
|
::media-only?
|
||||||
;::replacements
|
|
||||||
]))
|
]))
|
||||||
(def mastodon-config? (s/merge mastodon-auth? mastodon-target?))
|
(def mastodon-config? (s/merge mastodon-auth? mastodon-target?))
|
||||||
|
|
||||||
|
@ -39,11 +37,6 @@
|
||||||
[target mastodon-target?]
|
[target mastodon-target?]
|
||||||
(:max-post-length 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?
|
(defn-spec mastodon-client any?
|
||||||
[mastodon-auth mastodon-auth?]
|
[mastodon-auth mastodon-auth?]
|
||||||
(or (some-> mastodon-auth
|
(or (some-> mastodon-auth
|
||||||
|
@ -64,8 +57,7 @@
|
||||||
([mastodon-auth target status-text media-ids callback]
|
([mastodon-auth target status-text media-ids callback]
|
||||||
(let [{:keys [visibility sensitive?]} target]
|
(let [{:keys [visibility sensitive?]} target]
|
||||||
(-> (.post (mastodon-client mastodon-auth) "statuses"
|
(-> (.post (mastodon-client mastodon-auth) "statuses"
|
||||||
(clj->js (merge {:status (->> status-text
|
(clj->js (merge {:status status-text}
|
||||||
(perform-replacements mastodon-auth))}
|
|
||||||
(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}))))
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
(s/def ::content-filters (s/* ::content-filter))
|
(s/def ::content-filters (s/* ::content-filter))
|
||||||
(s/def ::keyword-filter string?)
|
(s/def ::keyword-filter string?)
|
||||||
(s/def ::keyword-filters (s/* ::keyword-filter))
|
(s/def ::keyword-filters (s/* ::keyword-filter))
|
||||||
|
(s/def ::replacements any?)
|
||||||
(defmulti source-type :type)
|
(defmulti source-type :type)
|
||||||
(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?))
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
(s/def ::target (s/multi-spec target-type ::type))
|
(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]
|
||||||
:opt-un [::resolve-urls? ::content-filters ::keyword-filters]))
|
:opt-un [::resolve-urls? ::content-filters ::keyword-filters ::replacements]))
|
||||||
(def transformations? (s/* ::transformation))
|
(def transformations? (s/* ::transformation))
|
||||||
|
|
||||||
(defn trim-text [text max-post-length]
|
(defn trim-text [text max-post-length]
|
||||||
|
@ -93,6 +94,11 @@
|
||||||
(when (not-empty (keyword-filter-regexes transformation))
|
(when (not-empty (keyword-filter-regexes transformation))
|
||||||
(empty? (some #(re-find % text) (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
|
; TODO: move this to mastodon-api - seems to belong strongly to mastodon
|
||||||
(defn-spec intermediate-to-mastodon mastodon-output?
|
(defn-spec intermediate-to-mastodon mastodon-output?
|
||||||
|
@ -132,6 +138,7 @@
|
||||||
(remove #(blocked-content? transformation (:text %)))
|
(remove #(blocked-content? transformation (:text %)))
|
||||||
(map #(intermediate-resolve-urls resolve-urls? %))
|
(map #(intermediate-resolve-urls resolve-urls? %))
|
||||||
(map #(twitter/nitter-url source %))
|
(map #(twitter/nitter-url source %))
|
||||||
|
(map #(perform-replacements transformation %))
|
||||||
(map #(intermediate-to-mastodon mastodon-auth target %))
|
(map #(intermediate-to-mastodon mastodon-auth target %))
|
||||||
(masto/post-items mastodon-auth target last-post-time))))))
|
(masto/post-items mastodon-auth target last-post-time))))))
|
||||||
|
|
||||||
|
|
Reference in a new issue