Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ sys.properties
.clj-kondo/*
.idea/*
.nrepl-port
bird_bot.iml
*.iml
.run/
target/
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
```
8 changes: 5 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/data.json {:mvn/version "2.4.0"}}}
{: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"}}}}}
21 changes: 21 additions & 0 deletions dev/bird_bot/build.clj
Original file line number Diff line number Diff line change
@@ -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})))
55 changes: 28 additions & 27 deletions src/main.clj → src/bird_bot/main.clj
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -112,7 +113,7 @@
(-> (str "https:"
"//api.telegram.org"
"/bot"
(:token sys)
(:token @*sys)
"/getUpdates"
(when offset-num
(str "?offset=" offset-num)))
Expand All @@ -131,7 +132,7 @@
[{:keys [telegram-log
chat-id
token]}]
(let [rand-room (-> sys
(let [rand-room (-> @*sys
:chat-rooms
vals
(conj nil)
Expand Down Expand Up @@ -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]
Expand All @@ -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 []
Expand Down