Merge branch 'master' into patch-1
This commit is contained in:
commit
fdabb17fb0
2 changed files with 42 additions and 13 deletions
|
@ -31,13 +31,20 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206)
|
||||||
:consumer_secret "XXXX"
|
:consumer_secret "XXXX"
|
||||||
:access_token_key "XXXX"
|
:access_token_key "XXXX"
|
||||||
:access_token_secret "XXXX"}
|
:access_token_secret "XXXX"}
|
||||||
:accounts ["arstechnica" "WIRED"]} ;; accounts you wish to mirror
|
;; optional, defaults to false
|
||||||
|
:include-replies? false
|
||||||
|
;; optional, defaults to false
|
||||||
|
:include-rts? false
|
||||||
|
;; accounts you wish to mirror
|
||||||
|
:accounts ["arstechnica" "WIRED"]}
|
||||||
;; add Tumblr config to mirror Tumblr accounts
|
;; add Tumblr config to mirror Tumblr accounts
|
||||||
:tumblr {:access-keys
|
:tumblr {:access-keys
|
||||||
{:consumer_key "XXXX"
|
{:consumer_key "XXXX"
|
||||||
:consumer_secret "XXXX"
|
:consumer_secret "XXXX"
|
||||||
:token "XXXX"
|
:token "XXXX"
|
||||||
:token_secret "XXXX"}
|
:token_secret "XXXX"}
|
||||||
|
;; optional limit for number of posts to retrieve, default: 5
|
||||||
|
:limit 10
|
||||||
:accounts ["cyberpunky.tumblr.com" "scipunk.tumblr.com"]}
|
:accounts ["cyberpunky.tumblr.com" "scipunk.tumblr.com"]}
|
||||||
;; add RSS config to follow feeds
|
;; add RSS config to follow feeds
|
||||||
:rss {"Hacker News" "https://hnrss.org/newest"
|
:rss {"Hacker News" "https://hnrss.org/newest"
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
["tumblr" :as tumblr]
|
["tumblr" :as tumblr]
|
||||||
["twitter" :as twitter]))
|
["twitter" :as twitter]))
|
||||||
|
|
||||||
|
(defn exit-with-error [error]
|
||||||
|
(js/console.error error)
|
||||||
|
(js/process.exit 1))
|
||||||
|
|
||||||
(defn find-config []
|
(defn find-config []
|
||||||
(or (first *command-line-args*)
|
(or (first *command-line-args*)
|
||||||
(-> js/process .-env .-MASTODON_BOT_CONFIG)
|
(-> js/process .-env .-MASTODON_BOT_CONFIG)
|
||||||
|
@ -21,9 +25,7 @@
|
||||||
(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 mastodon-client (or (some-> config :mastodon clj->js mastodon.)
|
(def mastodon-client (or (some-> config :mastodon clj->js mastodon.)
|
||||||
(do
|
(exit-with-error "missing Mastodon client configuration!")))
|
||||||
(js/console.error "missing Mastodon client configuration!")
|
|
||||||
(js/process.exit 1))))
|
|
||||||
|
|
||||||
(def content-filter-regexes (mapv re-pattern (-> config :mastodon :content-filters)))
|
(def content-filter-regexes (mapv re-pattern (-> config :mastodon :content-filters)))
|
||||||
|
|
||||||
|
@ -32,7 +34,7 @@
|
||||||
(def max-post-length (-> config :mastodon :max-post-length))
|
(def max-post-length (-> config :mastodon :max-post-length))
|
||||||
|
|
||||||
(defn blocked-content? [text]
|
(defn blocked-content? [text]
|
||||||
(boolean (some #(re-matches % text) content-filter-regexes)))
|
(boolean (some #(re-find % text) content-filter-regexes)))
|
||||||
|
|
||||||
(defn js->edn [data]
|
(defn js->edn [data]
|
||||||
(js->clj data :keywordize-keys true))
|
(js->clj data :keywordize-keys true))
|
||||||
|
@ -138,20 +140,40 @@
|
||||||
{:created-at (js/Date. (or isoDate pubDate))
|
{:created-at (js/Date. (or isoDate pubDate))
|
||||||
:text (str (trim-text title) "\n\n" (strip-utm link))})))))
|
:text (str (trim-text title) "\n\n" (strip-utm link))})))))
|
||||||
|
|
||||||
|
(defn twitter-client [access-keys]
|
||||||
|
(try
|
||||||
|
(twitter. (clj->js access-keys))
|
||||||
|
(catch js/Error e
|
||||||
|
(exit-with-error
|
||||||
|
(str "failed to connect to Twitter: " (.-message e))))))
|
||||||
|
|
||||||
|
(defn tumblr-client [access-keys account]
|
||||||
|
(try
|
||||||
|
(tumblr/Blog. account (clj->js access-keys))
|
||||||
|
(catch js/Error e
|
||||||
|
(exit-with-error
|
||||||
|
(str "failed to connect to Tumblr account " account ": " (.-message e))))))
|
||||||
|
|
||||||
(get-mastodon-timeline
|
(get-mastodon-timeline
|
||||||
(fn [timeline]
|
(fn [timeline]
|
||||||
(let [last-post-time (-> timeline first :created_at (js/Date.))]
|
(let [last-post-time (-> timeline first :created_at (js/Date.))]
|
||||||
;;post from Twitter
|
;;post from Twitter
|
||||||
(when-let [twitter-client (some-> config :twitter :access-keys clj->js twitter.)]
|
(when-let [twitter-config (:twitter config)]
|
||||||
(doseq [account (-> config :twitter :accounts)]
|
(let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config
|
||||||
(.get twitter-client
|
client (twitter-client access-keys)]
|
||||||
|
(doseq [account accounts]
|
||||||
|
(.get client
|
||||||
"statuses/user_timeline"
|
"statuses/user_timeline"
|
||||||
#js {:screen_name account :include_rts false :exclude_replies true :tweet_mode "extended"}
|
#js {:screen_name account
|
||||||
(post-tweets last-post-time))))
|
:tweet_mode "extended"
|
||||||
|
:include_rts (boolean include-replies?)
|
||||||
|
:exclude_replies (boolean include-rts?)}
|
||||||
|
(post-tweets last-post-time)))))
|
||||||
;;post from Tumblr
|
;;post from Tumblr
|
||||||
(when-let [tumblr-oauth (some-> config :tumblr :access-keys clj->js)]
|
(when-let [{:keys [accounts limit tumblr-oauth]} (:tumblr config)]
|
||||||
(when-let [tumblr-client (some-> config :tumblr :accounts first (tumblr/Blog. tumblr-oauth))]
|
(doseq [account accounts]
|
||||||
(.posts tumblr-client #js {:limit 5} (post-tumblrs last-post-time))))
|
(let [client (tumblr-client access-keys account)]
|
||||||
|
(.posts client #js {:limit (or limit 5)} (post-tumblrs last-post-time)))))
|
||||||
;;post from RSS
|
;;post from RSS
|
||||||
(when-let [feeds (some-> config :rss)]
|
(when-let [feeds (some-> config :rss)]
|
||||||
(let [parser (rss.)]
|
(let [parser (rss.)]
|
||||||
|
|
Reference in a new issue