made screenname optional, removed default post limit

This commit is contained in:
Dmitri Sotnikov 2018-08-17 20:02:35 -04:00
parent c39b71d025
commit 350b265000
2 changed files with 23 additions and 12 deletions

View file

@ -44,7 +44,11 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206)
"r/Clojure" "https://www.reddit.com/r/clojure/.rss"} "r/Clojure" "https://www.reddit.com/r/clojure/.rss"}
:mastodon {:access_token "XXXX" :mastodon {:access_token "XXXX"
:api_url "https://botsin.space/api/v1/" :api_url "https://botsin.space/api/v1/"
;; optional limit for the post length
:max-post-length 300 :max-post-length 300
;; optional flag specifying wether the name of the account
;; will be appended in the post, defaults to false
:append-screen-name? false
;; optional signature for posts ;; optional signature for posts
:signature "#newsbot" :signature "#newsbot"
;; optional content filter regexes ;; optional content filter regexes

View file

@ -20,23 +20,30 @@
(def config (-> (find-config) (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string)) (def config (-> (find-config) (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string))
(def content-filter-regexes (mapv re-pattern (-> config :mastodon :content-filters)))
(defn blocked-content? [text]
(boolean (some #(re-matches % text) content-filter-regexes)))
(def max-post-length (or (-> config :mastodon :max-post-length) 300))
(def mastodon-client (or (some-> config :mastodon clj->js mastodon.) (def mastodon-client (or (some-> config :mastodon clj->js mastodon.)
(do (do
(js/console.error "missing Mastodon client configuration!") (js/console.error "missing Mastodon client configuration!")
(js/process.exit 1)))) (js/process.exit 1))))
(def content-filter-regexes (mapv re-pattern (-> config :mastodon :content-filters)))
(def append-screen-name? (boolean (-> config :mastodon :append-screen-name?)))
(def max-post-length (-> config :mastodon :max-post-length))
(defn blocked-content? [text]
(boolean (some #(re-matches % text) content-filter-regexes)))
(defn js->edn [data] (defn js->edn [data]
(js->clj data :keywordize-keys true)) (js->clj data :keywordize-keys true))
(defn trim-text [text] (defn trim-text [text]
(if (> (count text) max-post-length) (cond
(nil? max-post-length)
text
(> (count text) max-post-length)
(reduce (reduce
(fn [text word] (fn [text word]
(if (> (+ (count text) (count word)) (- max-post-length 3)) (if (> (+ (count text) (count word)) (- max-post-length 3))
@ -44,7 +51,8 @@
(str text " " word))) (str text " " word)))
"" ""
(clojure.string/split text #" ")) (clojure.string/split text #" "))
text))
:else text))
(defn delete-status [status] (defn delete-status [status]
(.delete mastodon-client (str "statuses/" status) #js {})) (.delete mastodon-client (str "statuses/" status) #js {}))
@ -89,7 +97,7 @@
{:keys [media]} :extended_entities {:keys [media]} :extended_entities
{:keys [screen_name]} :user :as tweet}] {:keys [screen_name]} :user :as tweet}]
{:created-at (js/Date. created-at) {:created-at (js/Date. created-at)
:text (str text "\n - " screen_name) :text (trim-text (if append-screen-name? (str text "\n - " screen_name) text))
: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)
@ -120,8 +128,7 @@
(post-items last-post-time)))) (post-items last-post-time))))
(defn strip-utm [news-link] (defn strip-utm [news-link]
(first (first (string/split news-link #"\?utm")))
(string/split news-link #"\?utm")))
(defn parse-feed [last-post-time parser [title url]] (defn parse-feed [last-post-time parser [title url]]
(-> (.parseURL parser url) (-> (.parseURL parser url)