diff --git a/src/doplarr/arr_utils.clj b/src/doplarr/arr_utils.clj index 0ecf2c3..a5e03fa 100644 --- a/src/doplarr/arr_utils.clj +++ b/src/doplarr/arr_utils.clj @@ -7,7 +7,7 @@ (defn fatal-error [ex] (log/fatal ex) - (System/exit -1)) + #_(System/exit -1)) (defn deep-merge [a & maps] (if (map? a) diff --git a/src/doplarr/core.clj b/src/doplarr/core.clj index 6b4f1e2..f6a957e 100644 --- a/src/doplarr/core.clj +++ b/src/doplarr/core.clj @@ -1,9 +1,8 @@ (ns doplarr.core (:require - [doplarr.discord :as discord] [doplarr.config :as config] - [doplarr.direct :as direct] - [doplarr.proxied :as proxied] + [doplarr.interaction-state-machine :as ism] + [doplarr.discord :as discord] [discljord.messaging :as m] [discljord.connections :as c] [discljord.events :as e] @@ -11,11 +10,6 @@ [clojure.core.async :as a]) (:gen-class)) -(def backend (delay (config/backend))) - -(def backend-request {:direct #'doplarr.direct/make-request - :proxied #'doplarr.proxied/make-request}) - ;;;;;;;;;;;;;;;;;;;;;;;; Gateway event handlers (defmulti handle-event (fn [event-type _] @@ -25,8 +19,8 @@ [_ data] (let [interaction (discord/interaction-data data)] (case (:type interaction) - :application-command ((backend-request @backend) interaction) ; These will all be requests as that is the only top level command - :message-component (discord/continue-request interaction)))) + :application-command (ism/start-interaction interaction) + :message-component (ism/continue-interaction interaction)))) (defmethod handle-event :ready [_ {{id :id} :user}] diff --git a/src/doplarr/direct.clj b/src/doplarr/direct.clj deleted file mode 100644 index 95b1c2b..0000000 --- a/src/doplarr/direct.clj +++ /dev/null @@ -1,68 +0,0 @@ -(ns doplarr.direct - (:require - [doplarr.discord :as discord] - [doplarr.sonarr :as sonarr] - [doplarr.radarr :as radarr] - [com.rpl.specter :as s] - [clojure.core.async :as a])) - -(def search-fn {:series sonarr/search - :movie radarr/search}) - -(def profiles-fn {:series sonarr/quality-profiles - :movie radarr/quality-profiles}) - -(def request-fn {:series sonarr/request - :movie radarr/request}) - -(defn select-profile [profiles uuid] - (discord/dropdown "Which quality profile?" - (str "select_profile:" uuid) - (map #(hash-map :label (:name %) :value (:id %)) profiles))) - -(defn make-request [interaction] - (let [uuid (str (java.util.UUID/randomUUID)) - id (:id interaction) - token (:token interaction) - search (:options (:payload interaction)) - request-type (first (keys search)) - request-term (s/select-one [request-type :term] search) - chan (a/chan)] - ; Send the in-progress response - (discord/interaction-response id token 5 :ephemeral? true) - ; Create this command's channel - (swap! discord/cache assoc uuid chan) - (a/go - (let [results (->> ((search-fn request-type) request-term) - a/> ((profiles-fn request-type)) - a/> (a/> (a/> (a/ (- now last-modified) discord/channel-timeout) + ; Update interaction with timeout message + (discord/update-interaction-response token (discord/content-response "Request times out, please try again.")) + ; Move through the state machine to update cache side effecting new components + (do + (swap! discord/cache assoc-in [uuid :last-modified] now) + (process-event event interaction uuid)))))) diff --git a/src/doplarr/overseerr.clj b/src/doplarr/overseerr.clj index ce8e1c6..9549501 100644 --- a/src/doplarr/overseerr.clj +++ b/src/doplarr/overseerr.clj @@ -11,6 +11,8 @@ (def poster-path "https://image.tmdb.org/t/p/w500") +(def status [:unknown :pending :processing :partially-available :available]) + (defn GET [endpoint & [params]] (utils/http-request :get @@ -83,31 +85,27 @@ (defn search-series [term] (search term "tv")) -(defn details [id media-type] - (a/go - (->> (a/> (a/ {:mediaType (:mediaType selection) @@ -123,9 +121,15 @@ (assoc s :description (:overview s)) (assoc s :remotePoster (str poster-path (:posterPath s))))) -(defn request [body user-id] +(defn post-process-selection [selection] + (a/go + (let [details (a/> (a/> ((search-fn request-type) request-term) - a/> (a/> (a/> (a/> (a/