Merge pull request #52 from kiranshila/develop

Add in configuration for the request alert message
This commit is contained in:
Kiran Shila
2022-01-17 12:44:05 -08:00
committed by GitHub
5 changed files with 30 additions and 17 deletions

View File

@@ -143,16 +143,17 @@ To skip the build, just download `Doplarr.jar` and `config.edn` from the release
### Optional Settings
| Environment Variable (Docker) | Config File Keyword | Type | Default Value | Description |
| ----------------------------- | -------------------------- | ------- | ------------- | --------------------------------------------------------------------------------------------------- |
| `DISCORD__MAX_RESULTS` | `:discord/max-results` | Integer | `25` | Sets the maximum size of the search results selection |
| `DISCORD__ROLE_ID` | `:discord/role-id` | Long | N/A | The discord role id for users of the bot (omitting this lets everyone on the server use the bot) |
| `SONARR__QUALITY_PROFILE` | `:sonarr/quality-profile` | String | N/A | The name of the quality profile to use by default for Sonarr |
| `RADARR__QUALITY_PROFILE` | `:radarr/quality-profile` | String | N/A | The name of the quality profile to use by default for Radarr |
| `SONARR__LANGUAGE_PROFILE` | `:sonarr/language-profile` | String | N/A | The name of the language profile to use by default for Radarr |
| `OVERSEERR__DEFAULT_ID` | `:overseerr/default-id` | Integer | N/A | The Overseerr user id to use by default if there is no associated discord account for the requester |
| `PARTIAL_SEASONS` | `:partial-seasons` | Boolean | `true` | Sets whether users can request partial seasons. |
| `LOG_LEVEL` | `:log-level` | Keyword | `:info` | The log level for the logging backend. This can be changed for debugging purposes. |
| Environment Variable (Docker) | Config File Keyword | Type | Default Value | Description |
| ------------------------------ | ------------------------------ | ------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `DISCORD__MAX_RESULTS` | `:discord/max-results` | Integer | `25` | Sets the maximum size of the search results selection |
| `DISCORD__ROLE_ID` | `:discord/role-id` | Long | N/A | The discord role id for users of the bot (omitting this lets everyone on the server use the bot) |
| `DISCORD__REQUESTED_MSG_STYLE` | `:discord/requested-msg-style` | Keyword | `:plain` | Sets the style of the request alert message. One of `:plain :embed :none` |
| `SONARR__QUALITY_PROFILE` | `:sonarr/quality-profile` | String | N/A | The name of the quality profile to use by default for Sonarr |
| `RADARR__QUALITY_PROFILE` | `:radarr/quality-profile` | String | N/A | The name of the quality profile to use by default for Radarr |
| `SONARR__LANGUAGE_PROFILE` | `:sonarr/language-profile` | String | N/A | The name of the language profile to use by default for Radarr |
| `OVERSEERR__DEFAULT_ID` | `:overseerr/default-id` | Integer | N/A | The Overseerr user id to use by default if there is no associated discord account for the requester |
| `PARTIAL_SEASONS` | `:partial-seasons` | Boolean | `true` | Sets whether users can request partial seasons. |
| `LOG_LEVEL` | `:log-level` | Keyword | `:info` | The log level for the logging backend. This can be changed for debugging purposes. One of `trace :debug :info :warn :error :fatal :report` |
### Setting up on Windows

View File

@@ -25,6 +25,7 @@
:discord/token
:discord/role-id
:discord/max-results
:discord/requested-msg-style
; Doplarr
:partial-seasons
:log-level})

View File

@@ -19,6 +19,7 @@
; --- Optional settings
(spec/def :discord/role-id pos-int?)
(spec/def :discord/max-results (spec/int-in 1 26))
(spec/def :discord/requested-msg-style #{:none :plain :embed})
; Radarr optionals
(spec/def :radarr/quality-profile string?)
@@ -51,6 +52,7 @@ If you have configured one, make sure to check spelling. A valid configuration c
(spec/keys :req [:discord/token]
:opt [:discord/role-id
:discord/max-results
:discord/requested-msg-style
:radarr/quality-profile
:sonarr/quality-profile
:sonarr/language-profile

View File

@@ -138,6 +138,16 @@
:components [{:type 1 :components (for [format (:request-formats embed-data)]
(request-button format uuid))}]})
(defn request-performed-plain [payload media-type user-id]
{:content
(str "<@" user-id "> has requested the "
(name media-type) " `" (:title payload) " (" (:year payload) ")"
"` and it should be available soon!")})
(defn request-performed-embed [embed-data user-id]
{:content (str "<@" user-id "> has requested:")
:embeds [(request-embed embed-data)]})
;; Discljord Utilities
(defn register-commands [media-types bot-id messaging guild-id]
(->> @(m/bulk-overwrite-guild-application-commands!

View File

@@ -48,6 +48,7 @@
(let [embed (log-on-error
(a/<! ((utils/media-fn media-type "request-embed") payload media-type))
"Exception from request-embed")]
(swap! state/cache assoc-in [uuid :embed] embed)
(->> @(m/edit-original-interaction-response! messaging bot-id token (discord/request embed uuid))
(else #(fatal % "Error in sending request embed"))))
(let [[op options] (first pending-opts)]
@@ -92,7 +93,7 @@
(defmethod process-event! "request" [_ interaction uuid format]
(let [{:keys [messaging bot-id]} @state/discord
{:keys [payload media-type token]} (get @state/cache uuid)
{:keys [payload media-type token embed]} (get @state/cache uuid)
{:keys [user-id channel-id]} interaction]
(letfn [(msg-resp [msg] (->> @(m/edit-original-interaction-response! messaging bot-id token (discord/content-response msg))
(else #(fatal % "Error in message response"))))]
@@ -109,12 +110,10 @@
:available (msg-resp "This selection is already available!")
(do
(info "Performing request for " payload)
(m/create-message! messaging channel-id
:content
(str "<@" user-id "> has requested the "
(name media-type) " `" (:title payload) " (" (:year payload) ")"
"` and it should be available soon!"))
(msg-resp "Request performed!")))))
(msg-resp "Request performed!")
(case (:discord/requested-msg-style @state/config)
:plain (m/create-message! messaging channel-id (discord/request-performed-plain payload media-type user-id))
:embed (m/create-message! messaging channel-id (discord/request-performed-embed embed user-id)))))))
(else (fn [e]
(let [{:keys [status body] :as data} (ex-data e)]
(if (= status 403)