Skip to content

Commit

Permalink
Merge pull request #78 from kiranshila/develop
Browse files Browse the repository at this point in the history
Update to the new permissions system
  • Loading branch information
kiranshila authored May 1, 2022
2 parents 14cacbb + 69ab5a1 commit e64d969
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 28 deletions.
1 change: 0 additions & 1 deletion config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
; :radarr/rootfolder ""
; :sonarrr/language-profile ""
; :sonarr/rootfolder ""
; :discord/role-id role_id
; :discord/max-results 10
; :overseerr/default-id 1
; :log-level :trace
Expand Down
19 changes: 8 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ The first step in configuration is creating the bot in Discord itself.
4. Go to OAuth2 and under "OAuth2 URL Generator", enable `applications.commands` and `bot`
5. Copy the resulting URL and use as the invite link to your server

In the server for which you will use the bot, you have the option to restrict
the commands to a certain role. For this, you need to create a new role for
your users (or use an existing one). Then, grab that role id.
### Permissions

To do this:
As of Doplarr v3.5.0, we removed the ability to role-gate the bot via our
configuration file as Discord launched the command permissions system within the client itself.

1. Enable Developer Mode (User Settings -> Advanced -> Developer Mode)
2. Under your server settings, go to Roles, find the role and "Copy ID"

!> Every user that you wish to have access to the slash commands needs to be assigned this role (even the server owner/admins).

This is optional and by default the bot will be accessible to everyone on the server.
To access this, after adding the bot to your server, navigate to `Server Settings -> Integrations -> Doplarr (or whatever you named it) -> Manage` and
from there you can configure the channels for which the bot is active and who
has access to the bot. This is a lot more powerful than the previous system and
users of the previous `ROLE_ID`-based approach must update as Discord broke the
old system.

## Sonarr/Radarr

Expand All @@ -42,7 +40,6 @@ web interface to Overseerr if you need more features.
| 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 |
Expand Down
1 change: 0 additions & 1 deletion src/doplarr/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
:overseerr/default-id
; Discord
:discord/token
:discord/role-id
:discord/max-results
:discord/requested-msg-style
; Doplarr
Expand Down
4 changes: 1 addition & 3 deletions src/doplarr/config/specs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
(spec/def :discord/token string?)

; --- 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})

Expand Down Expand Up @@ -52,8 +51,7 @@ If you have configured one, make sure to check spelling. A valid configuration c
; Complete configuration
(spec/def ::config (spec/and
(spec/keys :req [:discord/token]
:opt [:discord/role-id
:discord/max-results
:opt [:discord/max-results
:discord/requested-msg-style
:radarr/quality-profile
:sonarr/quality-profile
Expand Down
7 changes: 2 additions & 5 deletions src/doplarr/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@
(info "Connected to guild")
(let [media-types (config/available-media @state/config)
messaging (:messaging @state/discord)
bot-id (:bot-id @state/discord)
[{command-id :id}] (discord/register-commands media-types bot-id messaging id)]
(when (:discord/role-id @state/config)
(info "Setting role id. Reminder, even the server owner needs this role.")
(discord/set-permission bot-id messaging id command-id))))
bot-id (:bot-id @state/discord)]
(discord/register-commands media-types bot-id messaging id)))

(defmethod handle-event! :default
[event-type data]
Expand Down
7 changes: 0 additions & 7 deletions src/doplarr/discord.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
(defn request-command [media-types]
{:name "request"
:description "Request media"
:default_permission (boolean (not (:discord/role-id @state/config)))
:options
(into [] (for [media media-types]
{:type 1
Expand Down Expand Up @@ -157,9 +156,3 @@
messaging bot-id guild-id
[(request-command media-types)])
(else #(fatal % "Error in registering commands"))))

(defn set-permission [bot-id messaging guild-id command-id]
(->> @(m/edit-application-command-permissions!
messaging bot-id guild-id command-id
[{:id (:discord/role-id @state/config) :type 1 :permission true}])
(else #(fatal % "Error in setting command permissions"))))

0 comments on commit e64d969

Please sign in to comment.