Merge branch 'improve_console_log' into 'master'
Improve console log See merge request yogthos/mastodon-bot!12
This commit is contained in:
commit
99ce52dfba
6 changed files with 66 additions and 66 deletions
|
@ -2,7 +2,7 @@
|
||||||
"name": "mastodon-bot",
|
"name": "mastodon-bot",
|
||||||
"description": "Bot to publish twitter, tumblr or rss posts to an mastodon account.",
|
"description": "Bot to publish twitter, tumblr or rss posts to an mastodon account.",
|
||||||
"author": "Dmitri Sotnikov",
|
"author": "Dmitri Sotnikov",
|
||||||
"version": "1.11.1-SNAPSHOT",
|
"version": "1.12.0-SNAPSHOT",
|
||||||
"homepage": "https://github.com/yogthos/mastodon-bot",
|
"homepage": "https://github.com/yogthos/mastodon-bot",
|
||||||
"repository": "https://www.npmjs.com/package/mastodon-bot",
|
"repository": "https://www.npmjs.com/package/mastodon-bot",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject dda/mastodon-bot "1.11.1-SNAPSHOT"
|
(defproject dda/mastodon-bot "1.12.0-SNAPSHOT"
|
||||||
:description "Bot to publish twitter, tumblr or rss posts to an mastodon account."
|
:description "Bot to publish twitter, tumblr or rss posts to an mastodon account."
|
||||||
:url "https://github.com/yogthos/mastodon-bot"
|
:url "https://github.com/yogthos/mastodon-bot"
|
||||||
:author "Dmitri Sotnikov"
|
:author "Dmitri Sotnikov"
|
||||||
|
|
|
@ -6,11 +6,15 @@
|
||||||
["deasync" :as deasync]
|
["deasync" :as deasync]
|
||||||
["node-fetch" :as fetch]))
|
["node-fetch" :as fetch]))
|
||||||
|
|
||||||
(defn debug [item]
|
(defn log-error [item]
|
||||||
|
(js/console.error item)
|
||||||
|
item)
|
||||||
|
|
||||||
|
(defn log [item]
|
||||||
(js/console.log item)
|
(js/console.log item)
|
||||||
item)
|
item)
|
||||||
|
|
||||||
(defn debug-first [item]
|
(defn log-first [item]
|
||||||
(js/console.log (first item))
|
(js/console.log (first item))
|
||||||
item)
|
item)
|
||||||
|
|
||||||
|
@ -47,10 +51,13 @@
|
||||||
|
|
||||||
(defn resolve-promise [promise result-on-error]
|
(defn resolve-promise [promise result-on-error]
|
||||||
(let [done (atom false)
|
(let [done (atom false)
|
||||||
result (atom nil)
|
result (atom nil)]
|
||||||
promise (-> promise
|
(-> promise
|
||||||
(.then #(do (reset! result %) (reset! done true)))
|
(.then #(do (reset! result %) (reset! done true)))
|
||||||
(.catch #(do (reset! result result-on-error) (reset! done true))))]
|
(.catch #(do
|
||||||
|
(log-error %)
|
||||||
|
(reset! result result-on-error)
|
||||||
|
(reset! done true))))
|
||||||
(.loopWhile deasync (fn [] (not @done)))
|
(.loopWhile deasync (fn [] (not @done)))
|
||||||
@result))
|
@result))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(:require
|
(:require
|
||||||
[orchestra.core :refer-macros [defn-spec]]
|
[orchestra.core :refer-macros [defn-spec]]
|
||||||
[mastodon-bot.rss-domain :as rd]
|
[mastodon-bot.rss-domain :as rd]
|
||||||
|
[mastodon-bot.infra :as infra]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
["rss-parser" :as rss]))
|
["rss-parser" :as rss]))
|
||||||
|
|
||||||
|
@ -20,9 +21,5 @@
|
||||||
link)}))
|
link)}))
|
||||||
|
|
||||||
(defn-spec get-feed map?
|
(defn-spec get-feed map?
|
||||||
[url string?
|
[url string?]
|
||||||
callback fn?]
|
(infra/resolve-promise (.parseURL (rss-client) url) []))
|
||||||
(print url)
|
|
||||||
(-> (.parseURL (rss-client) url)
|
|
||||||
(.then callback)
|
|
||||||
(.catch #(js/console.log %))))
|
|
||||||
|
|
|
@ -43,38 +43,33 @@
|
||||||
(update input :text #(reduce-kv string/replace % (:replacements transformation))))
|
(update input :text #(reduce-kv string/replace % (:replacements transformation))))
|
||||||
|
|
||||||
(defn-spec post-tweets-to-mastodon any?
|
(defn-spec post-tweets-to-mastodon any?
|
||||||
[mastodon-auth md/mastodon-auth?
|
[tweets any?
|
||||||
|
mastodon-auth md/mastodon-auth?
|
||||||
transformation ::trd/transformation
|
transformation ::trd/transformation
|
||||||
last-post-time any?]
|
last-post-time any?]
|
||||||
(let [{:keys [source target resolve-urls?]} transformation]
|
(let [{:keys [source target resolve-urls?]} transformation]
|
||||||
(fn [error tweets response]
|
(->> (infra/js->edn tweets)
|
||||||
(if error
|
(map twa/parse-tweet)
|
||||||
(infra/exit-with-error error)
|
(filter #(> (:created-at %) last-post-time))
|
||||||
(->> (infra/js->edn tweets)
|
(remove #(blocked-content? transformation (:text %)))
|
||||||
(map twa/parse-tweet)
|
(map #(intermediate-resolve-urls resolve-urls? %))
|
||||||
(filter #(> (:created-at %) last-post-time))
|
(map #(twa/nitter-url source %))
|
||||||
(remove #(blocked-content? transformation (:text %)))
|
(map #(perform-replacements transformation %))
|
||||||
(map #(intermediate-resolve-urls resolve-urls? %))
|
(map #(ma/intermediate-to-mastodon target %))
|
||||||
(map #(twa/nitter-url source %))
|
(ma/post-items mastodon-auth target))))
|
||||||
(map #(perform-replacements transformation %))
|
|
||||||
(map #(ma/intermediate-to-mastodon target %))
|
|
||||||
(ma/post-items mastodon-auth target))))))
|
|
||||||
|
|
||||||
(defn-spec tweets-to-mastodon any?
|
(defn-spec tweets-to-mastodon any?
|
||||||
[mastodon-auth md/mastodon-auth?
|
[mastodon-auth md/mastodon-auth?
|
||||||
twitter-auth twd/twitter-auth?
|
twitter-auth twd/twitter-auth?
|
||||||
transformation ::trd/transformation
|
transformation ::trd/transformation
|
||||||
last-post-time any?]
|
last-post-time any?]
|
||||||
(let [{:keys [source target resolve-urls?]} transformation]
|
(let [{:keys [source target resolve-urls?]} transformation
|
||||||
(doseq [account (:accounts source)]
|
accounts (:accounts source)]
|
||||||
(twa/user-timeline
|
(infra/log (str "processing tweets for " accounts))
|
||||||
twitter-auth
|
(doseq [account accounts]
|
||||||
source
|
(-> (twa/user-timeline twitter-auth source account)
|
||||||
account
|
(post-tweets-to-mastodon mastodon-auth transformation last-post-time)))
|
||||||
(post-tweets-to-mastodon
|
(infra/log "done.")))
|
||||||
mastodon-auth
|
|
||||||
transformation
|
|
||||||
last-post-time)))))
|
|
||||||
|
|
||||||
(defn-spec post-tumblr-to-mastodon any?
|
(defn-spec post-tumblr-to-mastodon any?
|
||||||
[mastodon-auth md/mastodon-auth?
|
[mastodon-auth md/mastodon-auth?
|
||||||
|
@ -98,7 +93,9 @@
|
||||||
tumblr-auth td/tumblr-auth?
|
tumblr-auth td/tumblr-auth?
|
||||||
transformation ::trd/transformation
|
transformation ::trd/transformation
|
||||||
last-post-time any?]
|
last-post-time any?]
|
||||||
(let [{:keys [accounts limit]} transformation]
|
(let [{:keys [source target]} transformation
|
||||||
|
{:keys [accounts limit]} source]
|
||||||
|
(infra/log (str "processing tumblr for " accounts))
|
||||||
(doseq [account accounts]
|
(doseq [account accounts]
|
||||||
(let [client (ta/tumblr-client tumblr-auth account)]
|
(let [client (ta/tumblr-client tumblr-auth account)]
|
||||||
(.posts client
|
(.posts client
|
||||||
|
@ -110,31 +107,30 @@
|
||||||
)))))
|
)))))
|
||||||
|
|
||||||
(defn-spec post-rss-to-mastodon any?
|
(defn-spec post-rss-to-mastodon any?
|
||||||
[mastodon-auth md/mastodon-auth?
|
[payload any?
|
||||||
|
mastodon-auth md/mastodon-auth?
|
||||||
transformation ::trd/transformation
|
transformation ::trd/transformation
|
||||||
last-post-time any?]
|
last-post-time any?]
|
||||||
(let [{:keys [source target resolve-urls?]} transformation]
|
(let [{:keys [source target resolve-urls?]} transformation]
|
||||||
(fn [payload]
|
(->> (infra/js->edn payload)
|
||||||
(->> (infra/js->edn payload)
|
(:items)
|
||||||
(:items)
|
(map ra/parse-feed)
|
||||||
(map ra/parse-feed)
|
(filter #(> (:created-at %) last-post-time))
|
||||||
(filter #(> (:created-at %) last-post-time))
|
(remove #(blocked-content? transformation (:text %)))
|
||||||
(remove #(blocked-content? transformation (:text %)))
|
(map #(intermediate-resolve-urls resolve-urls? %))
|
||||||
(map #(intermediate-resolve-urls resolve-urls? %))
|
(map #(perform-replacements transformation %))
|
||||||
(map #(perform-replacements transformation %))
|
(map #(ma/intermediate-to-mastodon target %))
|
||||||
(map #(ma/intermediate-to-mastodon target %))
|
(ma/post-items mastodon-auth target))))
|
||||||
(ma/post-items mastodon-auth target)))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec rss-to-mastodon any?
|
(defn-spec rss-to-mastodon any?
|
||||||
[mastodon-auth md/mastodon-auth?
|
[mastodon-auth md/mastodon-auth?
|
||||||
transformation ::trd/transformation
|
transformation ::trd/transformation
|
||||||
last-post-time any?]
|
last-post-time any?]
|
||||||
(let [{:keys [source target]} transformation]
|
(let [{:keys [source target]} transformation
|
||||||
(doseq [[name url] (:feeds source)]
|
{:keys [feeds]} source]
|
||||||
(ra/get-feed
|
(infra/log (str "processing rss for " feeds))
|
||||||
url
|
(doseq [[name url] feeds]
|
||||||
(post-rss-to-mastodon
|
(-> (ra/get-feed url)
|
||||||
mastodon-auth
|
(post-rss-to-mastodon mastodon-auth transformation last-post-time)))
|
||||||
transformation
|
(infra/log "done.")))
|
||||||
last-post-time)))))
|
|
|
@ -46,14 +46,14 @@
|
||||||
(defn-spec user-timeline any?
|
(defn-spec user-timeline any?
|
||||||
[twitter-auth td/twitter-auth?
|
[twitter-auth td/twitter-auth?
|
||||||
source td/twitter-source?
|
source td/twitter-source?
|
||||||
account ::td/account
|
account ::td/account]
|
||||||
callback fn?]
|
|
||||||
(let [{:keys [include-rts? include-replies?]} source]
|
(let [{:keys [include-rts? include-replies?]} source]
|
||||||
(.get (twitter-client twitter-auth)
|
(infra/resolve-promise
|
||||||
"statuses/user_timeline"
|
(.get (twitter-client twitter-auth)
|
||||||
#js {:screen_name account
|
"statuses/user_timeline"
|
||||||
:tweet_mode "extended"
|
#js {:screen_name account
|
||||||
:include_rts (boolean include-rts?)
|
:tweet_mode "extended"
|
||||||
:exclude_replies (not (boolean include-replies?))}
|
:include_rts (boolean include-rts?)
|
||||||
callback)))
|
:exclude_replies (not (boolean include-replies?))})
|
||||||
|
[])))
|
||||||
|
|
Reference in a new issue