From 23b09322fe6ab1bcb1debca3a58d7f018d728bb6 Mon Sep 17 00:00:00 2001 From: Enzzo Cavallo Date: Thu, 6 Apr 2023 07:51:45 -0300 Subject: [PATCH] Add basic JAR build --- .gitignore | 4 ++- README.md | 19 ++++++++++++- deps.edn | 8 ++++-- dev/bird_bot/build.clj | 21 ++++++++++++++ src/{ => bird_bot}/main.clj | 55 +++++++++++++++++++------------------ 5 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 dev/bird_bot/build.clj rename src/{ => bird_bot}/main.clj (86%) diff --git a/.gitignore b/.gitignore index 3f81807..24d4a92 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ sys.properties .clj-kondo/* .idea/* .nrepl-port -bird_bot.iml \ No newline at end of file +*.iml +.run/ +target/ diff --git a/README.md b/README.md index f57e219..f608175 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,21 @@ or to not send messages and only update the local bck bb -x main/-main --dont-send true ``` -Everything is replable in every editor. \ No newline at end of file +Everything is repeatable in every editor. + +## Build + +Create a AoT jar with the command: + +```shell +clojure -M:dev -m bird-bot.build +``` + +Will generate `target/bird-bot.jar` + +Generate a binary from your jar file with + +```shell +## still not working +native-image target/bird-bot.jar +``` diff --git a/deps.edn b/deps.edn index e692e38..6d8fcc9 100644 --- a/deps.edn +++ b/deps.edn @@ -1,3 +1,5 @@ -{:paths ["src"] - :deps {org.clojure/clojure {:mvn/version "1.11.1"} - org.clojure/data.json {:mvn/version "2.4.0"}}} \ No newline at end of file +{:paths ["src"] + :deps {org.clojure/clojure {:mvn/version "1.11.1"} + org.clojure/data.json {:mvn/version "2.4.0"}} + :aliases {:dev {:extra-paths ["dev" "test"] + :extra-deps {io.github.clojure/tools.build {:mvn/version "0.9.4"}}}}} diff --git a/dev/bird_bot/build.clj b/dev/bird_bot/build.clj new file mode 100644 index 0000000..c34cf09 --- /dev/null +++ b/dev/bird_bot/build.clj @@ -0,0 +1,21 @@ +(ns bird-bot.build + (:require [clojure.tools.build.api :as b])) + +(def class-dir "target/classes") + +(defn -main + [& _] + (let [basis (b/create-basis {:project "deps.edn"})] + (b/delete {:path "target"}) + (b/write-pom {:class-dir class-dir + :lib 'bird-bot/bird-bot + :version "1.0.0" + :basis basis}) + #_(b/copy-dir {:src-dirs (:paths basis) + :target-dir class-dir}) + (b/compile-clj {:basis basis + :class-dir class-dir}) + (b/uber {:class-dir class-dir + :main 'bird-bot.main + :uber-file "target/bird-bot.jar" + :basis basis}))) diff --git a/src/main.clj b/src/bird_bot/main.clj similarity index 86% rename from src/main.clj rename to src/bird_bot/main.clj index 29ae210..d2ea050 100644 --- a/src/main.clj +++ b/src/bird_bot/main.clj @@ -1,4 +1,5 @@ -(ns main +(ns bird-bot.main + (:gen-class) (:require [clojure.data.json :as json] [clojure.string :as str] [clojure.java.io :as jio] @@ -38,19 +39,19 @@ (.load props reader) (into {} (for [[k v] props] [(keyword k) (read-string v)]))))) -(defonce sys - (merge - (load-props "sys.properties") - {:chat-id -1001146934165 - ;;;"message_thread_id" - :chat-rooms {:programar 29 - :musica 278 - #_#_:receitas "" - #_#_:filosofias-politica "" - #_#_:shitpost "" - #_#_:plano-real ""} - :backup-path "my-data.edn" - :telegram-log (atom #{})})) +(defonce *sys + (delay (merge + (load-props "sys.properties") + {:chat-id -1001146934165 + ;;;"message_thread_id" + :chat-rooms {:programar 29 + :musica 278 + #_#_:receitas "" + #_#_:filosofias-politica "" + #_#_:shitpost "" + #_#_:plano-real ""} + :backup-path "my-data.edn" + :telegram-log (atom #{})}))) (defn build-dict [words] (reduce (fn [dict, [current-word next-word]] @@ -112,7 +113,7 @@ (-> (str "https:" "//api.telegram.org" "/bot" - (:token sys) + (:token @*sys) "/getUpdates" (when offset-num (str "?offset=" offset-num))) @@ -131,7 +132,7 @@ [{:keys [telegram-log chat-id token]}] - (let [rand-room (-> sys + (let [rand-room (-> @*sys :chat-rooms vals (conj nil) @@ -167,9 +168,9 @@ (= 624742737))) vec))))) -#_(telegram-fetcher-data! sys) -#_(dump-local-data! sys) -#_(->> (telegram-fetcher-data! sys) +#_(telegram-fetcher-data! @*sys) +#_(dump-local-data! @*sys) +#_(->> (telegram-fetcher-data! @*sys) (sort-by :update_id)) (defn read-backup-data! [sys] @@ -181,16 +182,16 @@ (defn -main [& {:keys [dont-send]}] - (reset! (:telegram-log sys) - (read-backup-data! sys)) - (->> (telegram-fetcher-data! sys) - (swap! (:telegram-log sys) + (reset! (:telegram-log @*sys) + (read-backup-data! @*sys)) + (->> (telegram-fetcher-data! @*sys) + (swap! (:telegram-log @*sys) set/union - (read-backup-data! sys))) + (read-backup-data! @*sys))) (when-not dont-send - (telegram-sender-data! sys)) - (dump-local-data! sys) - (-> sys :telegram-log deref count (str " messages on memory") println)) + (telegram-sender-data! @*sys)) + (dump-local-data! @*sys) + (-> @*sys :telegram-log deref count (str " messages on memory") println)) #_(printf (str/join #"\n" (repeatedly 5 (fn []