From 0ae68af441fbf7675c832fb79316c6a3bc7c8caf Mon Sep 17 00:00:00 2001 From: jem Date: Wed, 13 May 2020 17:41:27 +0200 Subject: [PATCH] repl now works --- .gitignore | 4 +- README.md | 65 +++++++++++++------------ shadow-cljs.edn | 10 ++-- src/main/mastodon_bot/core.cljs | 9 ++-- src/main/mastodon_bot/mastodon_api.cljs | 2 +- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index e3d8124..a87dbc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -.shadow-cljs config.edn package-lock.json +/.shadow-cljs /node_modules -target/mastodon-bot.js +/target diff --git a/README.md b/README.md index c5a1d9f..b36df95 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206) with later timestamps to avoid duplicate posts. On the first run the timestamp will default to current time. ```clojure +#:mastodon-bot.core {;; add Twitter config to mirror Twitter accounts :twitter {:access-keys {:consumer_key "XXXX" @@ -51,37 +52,39 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w ;; add RSS config to follow feeds :rss {"Hacker News" "https://hnrss.org/newest" "r/Clojure" "https://www.reddit.com/r/clojure/.rss"} - :mastodon {:access_token "XXXX" - ;; account number you see when you log in and go to your profile - ;; e.g: https://mastodon.social/web/accounts/294795 - :account-id "XXXX" - :api_url "https://botsin.space/api/v1/" - ;; optional boolean to mark content as sensitive - :sensitive? true - ;; optional boolean defaults to false - ;; only sources containing media will be posted when set to true - :media-only? true - ;; optional visibility flag: direct, private, unlisted, public - ;; defaults to public - :visibility "unlisted" - ;; optional limit for the post length - :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 - :signature "#newsbot" - ;; optionally try to resolve URLs in posts to skip URL shorteners - ;; defaults to false - :resolve-urls? true - ;; optional content filter regexes - ;; any posts matching the regexes will be filtered out - :content-filters [".*bannedsite.*"] - ;; optional keyword filter regexes - ;; any posts not matching the regexes will be filtered out - :keyword-filters [".*clojure.*"] - ;; Replace Twitter links by Nitter - :nitter-urls? false}} + :mastodon + #:mastodon-bot.mastodon-api +{:access_token "XXXX" + ;; account number you see when you log in and go to your profile + ;; e.g: https://mastodon.social/web/accounts/294795 + :account-id "XXXX" + :api_url "https://botsin.space/api/v1/" + ;; optional boolean to mark content as sensitive + :sensitive? true + ;; optional boolean defaults to false + ;; only sources containing media will be posted when set to true + :media-only? true + ;; optional visibility flag: direct, private, unlisted, public + ;; defaults to public + :visibility "unlisted" + ;; optional limit for the post length + :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 + :signature "#newsbot" + ;; optionally try to resolve URLs in posts to skip URL shorteners + ;; defaults to false + :resolve-urls? true + ;; optional content filter regexes + ;; any posts matching the regexes will be filtered out + :content-filters [".*bannedsite.*"] + ;; optional keyword filter regexes + ;; any posts not matching the regexes will be filtered out + :keyword-filters [".*clojure.*"] + ;; Replace Twitter links by Nitter + :nitter-urls? false}} ``` * the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 49ba2c2..337ec72 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -1,11 +1,11 @@ {:source-paths ["src/main" "src/test"] :dependencies [[orchestra "2018.12.06-2"]] - :builds {:dev {:target :node-script - :repl-init-ns mastodon-bot.core - :output-to "target/mastodon-bot.js" - :main mastodon-bot.core/dummy - :repl-pprint true} + :builds {:dev {:target :node-library + :output-to "target/lib-mastodon-bot.js" + :exports {:infra mastodon-bot.infra/js->edn} + :repl-pprint true + } :app {:target :node-script :output-to "target/mastodon-bot.js" :main mastodon-bot.core/main diff --git a/src/main/mastodon_bot/core.cljs b/src/main/mastodon_bot/core.cljs index fedae9b..4e3638e 100755 --- a/src/main/mastodon_bot/core.cljs +++ b/src/main/mastodon_bot/core.cljs @@ -15,9 +15,12 @@ [mastodon-bot.infra :as infra] [mastodon-bot.mastodon-api :as masto])) -(defn dummy []) - (s/def ::mastodon-config masto/mastodon-config?) +(s/def ::twitter map?) +(s/def ::tumblr map?) +(s/def ::rss map?) +(def config? (s/keys :req [::mastodon-config] + :opt [::twitter ::tumblr ::rss])) ;this has to stay on top - only ns-keywords can be uses in spec (defn-spec mastodon-config ::mastodon-config @@ -135,7 +138,7 @@ (fn [timeline] (let [last-post-time (-> timeline first :created_at (js/Date.))] ;;post from Twitter - (when-let [twitter-config (:twitter config)] + (when-let [twitter-config (::twitter config)] (let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config client (twitter-client access-keys)] (doseq [account accounts] diff --git a/src/main/mastodon_bot/mastodon_api.cljs b/src/main/mastodon_bot/mastodon_api.cljs index 65dd487..16350cd 100755 --- a/src/main/mastodon_bot/mastodon_api.cljs +++ b/src/main/mastodon_bot/mastodon_api.cljs @@ -28,7 +28,7 @@ (s/def ::content-filters (s/* ::content-filter)) (s/def ::keyword-filters (s/* ::keyword-filter)) -(s/def ::mastodon-js-config (s/keys :req [::access_token ::a:pi_url])) +(s/def ::mastodon-js-config (s/keys :req [::access_token ::api_url])) (s/def ::mastodon-clj-config (s/keys :req [::account-id ::content-filters ::keyword-filters ::max-post-length ::signature ::visibility ::append-screen-name? ::sensitive? ::resolve-urls?