Skip to content

Commit

Permalink
[cleanup] remove timbre refers, use namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlor committed Sep 6, 2023
1 parent 9eaf6b6 commit d2ceaf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
34 changes: 17 additions & 17 deletions src/moolite/bot/actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(ns moolite.bot.actions
(:require [clojure.string :as string]
[clojure.core.match :refer [match]]
[taoensso.timbre :as timbre :refer [spy info debug]]
[taoensso.timbre :as log]
[moolite.bot.send :as send]
[moolite.bot.dicer :as dicer]
[moolite.bot.db :as db]
Expand All @@ -17,13 +17,13 @@
[moolite.bot.message :as message]))

(defn register-channel [{{gid :id title :title} :chat}]
(debug {:fn "register-channel" :gid gid :title title})
(log/debug {:fn "register-channel" :gid gid :title title})
(let [chan (-> (groups/insert {:gid gid :title title})
(db/execute-one!))]
(send/text gid (printf "channel registered with id %d and title '%s'" (:gid chan) (:title chan)))))

(defn help [gid]
(debug {:fn "help" :gid gid})
(log/debug {:fn "help" :gid gid})
(let [callout (->> (callouts/all-keywords {:gid gid})
(db/execute!)
(map :callout)
Expand All @@ -33,21 +33,21 @@
(send/text gid callout)))

(defn grumpyness [gid]
(debug ["grumpyness" gid])
(log/debug ["grumpyness" gid])
(let [grumpyness (-> (stats/all {:gid gid})
(db/execute-one!))]
(send/text gid grumpyness)))

(defn link-add [gid url & text]
(debug ["link-add" gid])
(log/debug ["link-add" gid])
(-> (links/insert {:url url
:description (or (first text) "")
:gid gid})
(db/execute!))
(send/text gid "umme ..."))

(defn link-del [gid url]
(debug ["link-del" gid])
(log/debug ["link-del" gid])
(-> {:url url :gid gid}
(links/delete-one-by-url)
(db/execute-one!))
Expand All @@ -56,7 +56,7 @@
[{:url url :text "~~ ## ~~"}]))

(defn link-search [gid text]
(debug ["link-search" gid])
(log/debug ["link-search" gid])
(let [results (-> {:text text :gid gid}
(links/search)
db/execute!)]
Expand All @@ -68,7 +68,7 @@
results))))

(defn diceroll [gid text]
(debug ["diceroll" text gid])
(log/debug ["diceroll" text gid])
(let [results (->> text
(dicer/roll)
(dicer/as-emoji)
Expand All @@ -78,7 +78,7 @@

(defn yell-callout
([gid co text]
(debug ["yell-callout" gid co])
(log/debug ["yell-callout" gid co])
(when-let [c (-> (callouts/one-by-callout {:callout co :gid gid})
(db/execute-one!))]
(send/text gid (->> text
Expand All @@ -99,7 +99,7 @@

(defn create-abraxas
[gid abraxas kind]
(debug ["create-abraxas" gid])
(log/debug ["create-abraxas" gid])
(if (or (= kind "photo") (= kind "video"))
(let [results (-> (abraxoides/insert {:gid gid :abraxas abraxas :kind kind}))]
(-> {:gid gid :abraxas abraxas :kind kind}
Expand All @@ -110,21 +110,21 @@

(defn delete-abraxas
[gid abraxas]
(debug {:fn "delete-abraxas" :gid gid})
(log/debug {:fn "delete-abraxas" :gid gid})
(-> {:gid gid :abraxas abraxas}
(abraxoides/delete-by-abraxas)
(db/execute!))
(send/text gid (message/escape "Ho dimenticato qualcosa!")))

(defn conjure-abraxas
[gid abraxas]
(debug ["conjure-abraxas" gid])
(log/debug ["conjure-abraxas" gid])
(when-let [results (-> (abraxoides/search {:abraxas abraxas})
(db/execute-one!))]
(debug "abraxas?" results)
(log/debug "abraxas?" results)
(when-let [item (-> (media/get-random-by-kind {:kind (:kind results) :gid gid})
(db/execute-one!))]
(debug "item" item)
(log/debug "item" item)
(condp = (:kind item)
"photo" (send/photo gid (:data item) (message/escape (:description item)))
"video" (send/video gid (:data item) (message/escape (:description item)))
Expand All @@ -151,7 +151,7 @@
"animation" (send/animation gid (:data item) (message/escape (:description item))))))

(defn ricorda [data parsed-text]
(debug ["ricorda" parsed-text])
(log/debug ["ricorda" parsed-text])
(match [data parsed-text]
;; photos
[{:photo photo-sizes :chat {:id gid}}
Expand Down Expand Up @@ -200,7 +200,7 @@
(send/text (get-in data [:chat :id]) (message/escape "non ho capito ..."))))

(defn act [{{gid :id} :chat :as data} parsed-text]
(debug ["act" parsed-text])
(log/debug ["act" parsed-text])
(match parsed-text
[_ [:command] [:abraxas "register"] & _]
(register-channel data)
Expand Down Expand Up @@ -255,5 +255,5 @@
(string/lower-case abraxas))]
(conjure-abraxas gid abraxas))

:else (do (debug "act -> no match")
:else (do (log/debug "act -> no match")
nil)))
15 changes: 6 additions & 9 deletions src/moolite/bot/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
[next.jdbc.result-set :as result-set]
[redelay.core :refer [state]]
[config.core :refer [env]]
[taoensso.timbre :as log :refer [info debug]]
[moolite.bot.db.groups :as groups]
[moolite.bot.db.callouts :as callouts]
[moolite.bot.db.stats :as stats]))
[taoensso.timbre :as log]))

(def db
(state :start
(let [db-file (or (:database-file env)
"bot.sqlite")]
(info "using db file " db-file)
(log/info "using db file " db-file)
(-> {:connection-uri (str "jdbc:sqlite:" db-file)}
(jdbc/get-datasource)
(jdbc/with-options {:builder-fn result-set/as-unqualified-lower-maps})))
:stop))

(defn execute! [query]
(debug query)
(log/debug query)
(try
(jdbc/execute! @db query {:return-keys true})
(catch Exception e (log/error "Error performing execute!" query))))
(catch Exception e (log/error "Error performing execute!" query (.getMessage e)))))

(defn execute-one! [query]
(debug query)
(log/debug query)
(try
(jdbc/execute-one! @db query {:return-keys true})
(catch Exception e (log/error "Error performing execute-one!" query))))
(catch Exception e (log/error "Error performing execute-one!" query (.getMessage e)))))

0 comments on commit d2ceaf0

Please sign in to comment.