Changed bot to use non-nested config to make env variables easier

This commit is contained in:
Kiran Shila
2021-08-11 18:38:28 -07:00
parent 91604138e4
commit 39dd1f7380
4 changed files with 19 additions and 20 deletions

View File

@@ -1,7 +1,6 @@
{:sonarr {:url "http://localhost:8989"
:api-key "your-key"}
:radarr {:url "http://localhost:7878"
:api-key "your-key"}
:bot {:max-results 10
:cache-expiration 60000
:token "your-key"}}
{:sonarr-url "http://localhost:8989"
:sonarr-api "your-key"
:radarr-url "http://localhost:7878"
:radarr-api "your-key"
:max-results 10
:bot-token "your-token"}

View File

@@ -12,7 +12,7 @@
(:gen-class))
(defonce state (atom nil))
(defonce cache (cache/ttl-cache-factory {} :ttl (:cache-expiration (:bot env))))
(defonce cache (cache/ttl-cache-factory {} :ttl 900000)) ; 15 Minute cache expiration, coinciding with the interaction token
;; Slash command setup
(def request-command
@@ -253,8 +253,8 @@
;; Bot startup and entry point
(defn run []
(let [event-ch (a/chan 100)
connection-ch (c/connect-bot! (:token (:bot env)) event-ch :intents #{:guilds})
messaging-ch (m/start-connection! (:token (:bot env)))
connection-ch (c/connect-bot! (:bot-token env) event-ch :intents #{:guilds})
messaging-ch (m/start-connection! (:bot-token env))
init-state {:connection connection-ch
:event event-ch
:messaging messaging-ch}]

View File

@@ -3,23 +3,23 @@
[config.core :refer [env]]
[doplarr.arr-utils :refer [http-request rootfolder]]))
(def endpoint (str (:url (:radarr env)) "/api/v3"))
(def endpoint (str (:radarr-url env) "/api/v3"))
(defn search [search-term]
(:body (http-request
:get
(str endpoint "/movie/lookup")
(:api-key (:radarr env))
(:radarr-api env)
{:query-params {:term search-term}})))
(defn request [movie]
(http-request
:post
(str endpoint "/movie")
(:api-key (:radarr env))
(:radarr-api env)
{:form-params (merge movie {:qualityProfileId 1
:monitored true
:minimumAvailability "announced"
:rootFolderPath (rootfolder endpoint (:api-key (:radarr env)))
:rootFolderPath (rootfolder endpoint (:radarr-api env))
:addOptions {:searchForMovie true}})
:content-type :json}))

View File

@@ -3,20 +3,20 @@
[config.core :refer [env]]
[doplarr.arr-utils :refer [http-request rootfolder]]))
(def endpoint (str (:url (:sonarr env)) "/api"))
(def endpoint (str (:sonarr-url env) "/api"))
(defn default-options []
{:profileId 1
:monitored true
:seasonFolder true
:rootFolderPath (rootfolder endpoint (:api-key (:sonarr env)))
:rootFolderPath (rootfolder endpoint (:sonarr-api env))
:addOptions {:searchForMissingEpisodes true}})
(defn search [search-term]
(:body (http-request
:get
(str endpoint "/series/lookup")
(:api-key (:sonarr env))
(:sonarr-api env)
{:query-params {:term search-term}})))
(defn started-aquisition? [series]
@@ -41,7 +41,7 @@
(http-request
:post
(str endpoint "/series")
(:api-key (:sonarr env))
(:sonarr-api env)
{:form-params (merge series (default-options))
:content-type :json}))
@@ -58,7 +58,7 @@
(http-request
(if started? :put :post)
(str endpoint "/series")
(:api-key (:sonarr env))
(:sonarr-api env)
{:form-params series
:content-type :json})))
@@ -66,7 +66,7 @@
(http-request
:post
(str endpoint "/series")
(:api-key (:sonarr env))
(:sonarr-api env)
{:form-params (merge
(assoc-in series [:seasons 0 :monitored] true)
(default-options))