Merge branch 'master' into refactoring

This commit is contained in:
jem 2020-05-13 18:23:17 +02:00
commit cd2441af4b
3 changed files with 14 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "mastodon-bot", "name": "mastodon-bot",
"version": "0.0.1", "version": "0.0.2",
"repository": "https://github.com/yogthos/mastodon-bot", "repository": "https://github.com/yogthos/mastodon-bot",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View file

@ -72,7 +72,7 @@
{:created-at (js/Date. created-at) {:created-at (js/Date. created-at)
:text (trim-text (str (chop-tail-media-url text media) :text (trim-text (str (chop-tail-media-url text media)
(if (masto/append-screen-name? (mastodon-config config)) (if (masto/append-screen-name? (mastodon-config config))
("\n - " screen_name) ""))) (str "\n - " screen_name) "")))
:media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)}) :media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)})
(defmulti parse-tumblr-post :type) (defmulti parse-tumblr-post :type)

View file

@ -21,6 +21,7 @@
(s/def ::resolve-urls? boolean?) (s/def ::resolve-urls? boolean?)
(s/def ::nitter-urls? boolean?) (s/def ::nitter-urls? boolean?)
(s/def ::visibility string?) (s/def ::visibility string?)
(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 600) (<= n 600)
@ -32,7 +33,7 @@
(s/def ::mastodon-clj-config (s/keys :req [::account-id ::content-filters ::keyword-filters (s/def ::mastodon-clj-config (s/keys :req [::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?])) ::nitter-urls? ::replacements]))
(def mastodon-config? (s/merge ::mastodon-js-config ::mastodon-clj-config)) (def mastodon-config? (s/merge ::mastodon-js-config ::mastodon-clj-config))
(defn-spec content-filter-regexes ::content-filters (defn-spec content-filter-regexes ::content-filters
@ -51,6 +52,11 @@
[mastodon-config mastodon-config?] [mastodon-config mastodon-config?]
(::max-post-length mastodon-config)) (::max-post-length mastodon-config))
(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-config mastodon-config?] [mastodon-config mastodon-config?]
(or (some-> mastodon-config clj->js mastodon.) (or (some-> mastodon-config clj->js mastodon.)
@ -106,8 +112,10 @@
([mastodon-config status-text media-ids] ([mastodon-config status-text media-ids]
(let [{: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 (resolve-urls mastodon-config (clj->js (merge {:status (-> status-text
(set-signature mastodon-config status-text))} (partial resolve-urls mastodon-config)
(partial perform-replacements mastodon-config)
(partial 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})))))))
@ -144,12 +152,6 @@
(infra/exit-with-error error) (infra/exit-with-error error)
(callback response))))) (callback response)))))
(defn-spec perform-replacements any?
[mastodon-config mastodon-config?
post any?]
(assoc post :text (reduce-kv string/replace (:text post) (::replacements mastodon-config)))
)
(defn-spec post-items any? (defn-spec post-items any?
[mastodon-config mastodon-config? [mastodon-config mastodon-config?
last-post-time any? last-post-time any?
@ -157,8 +159,7 @@
(doseq [{:keys [text media-links]} (doseq [{:keys [text media-links]}
(->> items (->> items
(remove #((blocked-content? mastodon-config (:text %)))) (remove #((blocked-content? mastodon-config (:text %))))
(filter #(> (:created-at %) last-post-time)) (filter #(> (:created-at %) last-post-time)))]
(map #(perform-replacements mastodon-config %)))]
(if media-links (if media-links
(post-status-with-images mastodon-config text media-links) (post-status-with-images mastodon-config text media-links)
(when-not (::media-only? mastodon-config) (when-not (::media-only? mastodon-config)