disrb 0.1.2.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65d508f2f29da21da961a646ad0eb6920d5d26fd3b7ad833b1c3dd391c5df495
4
- data.tar.gz: 7cd5482b028e9ef689fb8952cf9e8f6c4fc34ee95c7ea43fb999caf17b1d2174
3
+ metadata.gz: 755465c33626010b7a97992a3afbcee4459e9feae3249870900531ce315ae4f5
4
+ data.tar.gz: dec666a3607d7d21b3a526f6435a291122239ab66ad908d6d3a2626c1fd7ea45
5
5
  SHA512:
6
- metadata.gz: c923c3f794126970b909adbf71621b57f3cba24b29eaae333f60878b5b81089822441b7345063cb5b177283c9792a551171ad4b99a5e6c6fd449eb1d4288a55a
7
- data.tar.gz: 9337da2c386247cce3b904308474ff187d60086ec8d1988d5b438065c0a13e8ff646ae34f82ef6c939312d4f9fef214e1dd8da7f53699d69e22a71ee42337fae
6
+ metadata.gz: 1120cf0957b7e7ab2c7fdbf011b27816cb9085cb957f8c3eee37813a1a3627a4649adcb2ca001052740fca0fa7db50e6a0731b87d0ad73b46d0771f1b6fad764
7
+ data.tar.gz: d554f6fe8e41c6846d5ed186cc27988e050dc57af37a041203fa5c887414185238dce3c282c88b3c3a14c4e7f3f528eb7c6257b5fdd92e16b167fdd06b86b4df
data/CHANGELOG.md ADDED
@@ -0,0 +1,101 @@
1
+ # v0.1.4 (2026-04-05)
2
+
3
+ - Add support for file uploading
4
+ - Fix bug where HTTP handlers would continue executing even after an error
5
+ - Add missing User-Agent header in requests to the HTTP API (it can be changed from the default)
6
+ - Fix bug where functions may run `body` and `status` functions on a nil object
7
+ - Change 200 server limit notice from a warning to an info message in `get_current_user_guilds`
8
+ - Slight modifications in `README.md` and `LICENSE`
9
+
10
+ ## Breaking changes
11
+
12
+ - Any project using `DiscordApi`'s `get`, `post`, `delete`, `put` and `patch` functions will not work, as they have been made private (only functions inside the same class can call them), in order to add functionality for customizing the User-Agent header included in requests to the HTTP API.
13
+
14
+ # v0.1.3 (2025-11-15)
15
+
16
+ - Add documentation
17
+ - Lots of bugfixes and improvements
18
+ - Add replacement/deprecation warnings to parameters in create_guild_application_command and create_global_application_command
19
+ - Fix some formatting issues in the README.md with YARD
20
+ - Add .yardoc and doc folders to .gitignore
21
+ - Add a missing parameter in create_global_application_command
22
+ - Remove unnecessary double-empty check in DiscordApi#modify_current_user
23
+ - Fix bug where an Array in a String has been treated like an Array in DiscordApi#get_current_user_guilds, and also make sure that the response code is 200 before trying to parse the response
24
+ - Add missing implementation for https://discord.com/developers/docs/resources/user#get-current-user-guild-member
25
+ - Add information on how to use Faraday::Response objects and notice to read linked Discord documentation in the README.md
26
+ - Trim down and make logger.rb code more modular
27
+ - The payload_json parameter in DiscordApi#edit_message is only to be included in multipart/form-data requests, not JSON, so we remove it
28
+ - Rework the gateway connection reconnect code a bit
29
+ - Rework test.rb for the new code and also fix some bugs
30
+ - Add file and line information to Logger2 (shows where the logger was called)
31
+ - Fix a bug where all Logger2 class functions couldn't find Logger2#base
32
+ - Fix a bug, setting communication_disabled_until to false in DiscordApi#modify_guild_member would remove the timeout by sending nil to the Discord API, as specified in the documentation
33
+ - Add CHANGELOG.md to files in gemspec
34
+ - Add missing parameters in DiscordApi#modify_current_member
35
+ - Make nick in DiscordApi#modify_current_user_nick required because its the only modification
36
+ - Add support for some other opcodes in DiscordApi#connect_gateway
37
+ - Create new class function DiscordApi#bitwise_permission_flags that returns a hash with the key as the permission name (as a symbol) and the value as the bitwise permission flag, and make DiscordApi#calculate_permissions_integer and DiscordApi#reverse_permissions_integer use it to trim down some lines of code
38
+ - Move functions related to Application Commands from lib/disrb.rb to a separate file in lib/disrb/application_commands.rb
39
+
40
+ ## Breaking changes
41
+
42
+ - Rename emoji_id parameters to emoji in all functions related to the Message resource
43
+ - Description is a required parameter in create_guild_application_command and create_global_application_command
44
+ - Call the block in DiscordApi#connect_gateway on every payload, not just when an interaction is created
45
+ (stop always expecting an interaction when the block is called)
46
+ - Fixes where single splat operators didn't play nicely with keyword arguments (in DiscordApi#create_guild_application_commands, DiscordApi#create_global_application_commands)
47
+ - In mass-create application command functions, make it so that it returns the response of each request as an array, not just the last request's response
48
+ - Move DiscordApi.handle_snowflake to a separate class and slightly change usage for better documentation
49
+ - Comment out files/_files parameter in the relevant functions due to uploading files not being implemented yet
50
+ (also skip the relevant functions if only the files parameter is provided)
51
+ - Fix implementation of DiscordApi#modify_guild_role_positions, the required parameters are now different
52
+ - Apps can no longer create guilds, thus DiscordApi#create_guild has been removed
53
+
54
+ # Version 0.1.2.2 (2025-08-17)
55
+
56
+ - Fix a bug where the function wouldn't return even if the status code was the expected one for success
57
+ - (and disable Style/MultipleComparison in .rubocop.yml)
58
+
59
+ # Version 0.1.2.1 (2025-08-17)
60
+
61
+ - Fix a bug where connecting to the gateway would always fail
62
+
63
+ # Version 0.1.2 (2025-07-25)
64
+
65
+ - Change homepage in gemspec to point to the GitHub repository
66
+ - Add full support for the messages resource
67
+ - Bump Rubocop CI version to 0.0.4
68
+
69
+ # Version 0.1.1.3 (2025-07-24)
70
+
71
+ - Add rubocop to development dependencies (in gemspec)
72
+
73
+ # Version 0.1.1.2 (2025-07-24)
74
+
75
+ - Fix some problems with rubocop
76
+ - Make the CI ignore rubocop failures so that the CI can still create a release
77
+ - Add rubocop to development dependencies (in gemfile)
78
+
79
+ # Version 0.1.1.1 (2025-07-24)
80
+
81
+ - Bugfixes
82
+ - Make some functions use HandleQueryString where applicable
83
+ - Changed "if var" to "unless var.nil?" for consistency
84
+ - Functions where all options are optional, check if atleast one is provided
85
+ (keyword arguments over positional arguments if there are more than 1 optional arguments was already done)
86
+ - add Gemfile.lock to .gitignore
87
+ - since file structure changed, update require path in test.rb
88
+ - add link to changelog and license in README.md
89
+
90
+ # Version 0.1.1 (2025-07-23)
91
+
92
+ - Fully migrate from Net::HTTP to Faraday for HTTP requests
93
+ - Bugfixes
94
+ - Add roadmap to README
95
+ - Create CHANGELOG.md
96
+ - Only build and push the gem when a new tag is created
97
+ - Make the CI automatically create a new release with the gem in the attachments
98
+
99
+ # Version 0.1.0 (2025-07-23)
100
+
101
+ - Initial discord.rb release as a gem (indev release)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2025-until the sun explodes hoovad
1
+ Copyright (c) 2025-2026 hoovad
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -2,16 +2,38 @@
2
2
 
3
3
  [![Licensed under the MIT license](https://img.shields.io/github/license/hoovad/discord.rb)](LICENSE)
4
4
  [![Gem Version](https://img.shields.io/gem/v/disrb?logo=ruby&color=green)](https://rubygems.org/gems/disrb)
5
- ![project status: active](https://img.shields.io/badge/project_status-active-active)
5
+ ![project status: active](https://img.shields.io/badge/project_status-active-green)
6
6
  [![main](https://github.com/hoovad/discord.rb/actions/workflows/main.yml/badge.svg)](https://github.com/hoovad/discord.rb/actions/workflows/main.yml)
7
7
 
8
- [Changelog](CHANGELOG.md) | [Documentation](https://www.rubydoc.info/gems/disrb/) (currently in development)
8
+ [Changelog](CHANGELOG.md) | [Documentation](https://www.rubydoc.info/gems/disrb/) | [Contributing](CONTRIBUTING.md)
9
+
10
+ > [!IMPORTANT]
11
+ > This is project is still in early development. Expect changes that might break your code at any time. If your code suddenly doesn't work but it did on a previous version, check the [Changelog](CHANGELOG.md) for any breaking changes.
9
12
 
10
13
  W.I.P. Discord API wrapper written in Ruby for fun.
11
14
 
12
- The test.rb file creates two commands "test" and "test2", that return "Hi" and "Hello World!" respectively, sets the bot's current activity to 'Watching if i work', and sets the presence to online since the program was started provided you provide the required data in `env.rb.template` and rename it to `env.rb`.
15
+ > [!NOTE]
16
+ > This is not a full-featured Discord API handler. This gem lets you interact with the Discord API directly without all the baggage. If you want to make a bot extremely easily, this is not what you are looking for.
17
+
18
+ If you wanted to use this project, but found that something is missing, doesn't work, don't be afraid to open an issue! Read the [Contributing](CONTRIBUTING.md) page.
19
+
20
+ ## Demonstration
21
+
22
+ The test.rb file creates two commands "test" and "test2", that return "Hi" and "Hello World!" respectively, sets the bot's current activity to 'Watching if i work', and sets the presence to online since the program was started.
23
+
24
+ > [!NOTE]
25
+ > You will need to fill out the required data in `env.rb.template` and rename it to `env.rb` before running `test.rb`.
26
+
27
+ ## How to use this project
28
+
29
+ The documentation will contain information about the functions implemented in this project. Check it out [here](https://www.rubydoc.info/gems/disrb/).
30
+
31
+ Most functions in this library return a `Faraday::Response` object. Check the [Faraday documentation](https://www.rubydoc.info/github/lostisland/faraday) for info on how to use that object.
32
+
33
+ If you want to get the contents of the response, use the `body` instance method (example: `[Faraday::Response object here].body`). The contents will most likely be JSON. To convert it to a Ruby object, use `JSON.parse([Faraday::Response object here].body)` (with `require 'json'` of course).
13
34
 
14
- !DISCLAIMER! This is project is in development. Expect changes that might break your code at any time.
35
+ > [!TIP]
36
+ > When reading the documentation, there most likely will be a link to the relevant Discord Developer Documentation page. Please read that page as well, it will contain information that may help you.
15
37
 
16
38
  ## Roadmap
17
39
  - [x] Indev release (v0.1.0)
@@ -23,12 +45,12 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
23
45
  - [x] Basic gateway support
24
46
  - [x] RubyGem building and publishing
25
47
  - [ ] Alpha release (v0.2.0)
26
- - [ ] Add support for all Discord API endpoints
27
- - [ ] Add support for all Discord Gateway events and properly handle the connection
28
- - [ ] Documentation (v0.1.3)
48
+ - [ ] Add support for all Discord API endpoints (v0.2.0)
49
+ - [ ] Add support for all Discord Gateway events and properly handle the connection (v0.1.5)
50
+ - [ ] Add support for uploading files (v0.1.4)
51
+ - [x] Documentation (v0.1.3)
52
+ - [x] Full message resource support (v0.1.2)
29
53
  - [x] Transition to Faraday for HTTP requests (v0.1.1)
30
- - [x] Functions where all options are optional, check if atleast one is provided (v0.1.1.1)
31
- - [x] Prefer to use keyword arguments over positional arguments if there are more than 1 optional arguments (v0.1.1.1)
32
54
  - [ ] Beta release (v0.3.0)
33
55
  - [ ] Component support and builder
34
56
  - [ ] Sharding support
@@ -36,4 +58,5 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
36
58
  - [ ] Voice support
37
59
  - [ ] Add parameter validation
38
60
  - [ ] Stable release (v1.0.0)
61
+ - [ ] Return classes instead of `Faraday::Response` objects
39
62
  - [ ] Bugfixes, consistency and improvements
@@ -0,0 +1,409 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class that contains functions that allow interacting with the Discord API.
4
+ class DiscordApi
5
+ # Creates an application command specifically for one guild.
6
+ # See https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
7
+ # @param guild_id [Integer] The ID of the guild where the command will be created.
8
+ # @param name [String] The name of the command.
9
+ # @param name_localizations [Hash, nil] Localized names for the command.
10
+ # @param description [String, nil] The description of the command.
11
+ # @param description_localizations [Hash, nil] Localized descriptions for the command.
12
+ # @param options [Array, nil] Options for the command.
13
+ # @param default_member_permissions [String, nil] Sets the default permission(s) that members need to run the command.
14
+ # (must be set to a bitwise permission flag as a string)
15
+ # @param default_permission [TrueClass, FalseClass, nil] (replaced by default_member_permissions) Whether the command
16
+ # is enabled by default when the app is added to a guild.
17
+ # @param type [Integer, nil] The type of the command.
18
+ # @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
19
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
20
+ def create_guild_application_command(guild_id, name, description, name_localizations: nil,
21
+ description_localizations: nil, options: nil, default_member_permissions: nil,
22
+ default_permission: nil, type: nil, nsfw: nil)
23
+ output = {}
24
+ output[:name] = name
25
+ output[:description] = description
26
+ output[:name_localizations] = name_localizations unless name_localizations.nil?
27
+ output[:description_localizations] = description_localizations unless description_localizations.nil?
28
+ output[:options] = options unless options.nil?
29
+ unless default_permission.nil?
30
+ @logger.warn('The "default_permission" parameter has been replaced by "default_member_permissions" ' \
31
+ 'and will be deprecated in the future.')
32
+ output[:default_permission] = default_permission
33
+ end
34
+ output[:type] = type unless type.nil?
35
+ output[:nsfw] = nsfw unless nsfw.nil?
36
+ output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
37
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands"
38
+ data = JSON.generate(output)
39
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
40
+ response = post(url, data, headers)
41
+ return response if response.is_a?(Faraday::Response) && (response.status == 201 || response.status == 200)
42
+
43
+ @logger.error("Failed to create guild application command in guild with ID #{guild_id}." \
44
+ " Response: #{response_error_body(response)}")
45
+ response
46
+ end
47
+
48
+ # Mass-creates application commands for guild(s).
49
+ # @param application_commands_array [Array] An array of arrays, where the first three elements (of the inner array)
50
+ # are the values for for the first three parameters (which are required) in the create_guild_application_command
51
+ # method in order. The fourth element is a Hash that contains the rest of the parameters for the command, the key
52
+ # must be the name of the parameter as a symbol (e.g. :description, :options, etc.) and the value must be the value
53
+ # for that parameter.
54
+ # @return [Array] An array of Faraday::Response objects, one for each command creation request.
55
+ def create_guild_application_commands(application_commands_array)
56
+ response = []
57
+ if application_commands_array.is_a?(Array)
58
+ application_commands_array.each do |parameter_array|
59
+ if parameter_array.is_a?(Array)
60
+ response << create_guild_application_command(*parameter_array[0..2], **parameter_array[3] || {})
61
+ else
62
+ @logger.error("Invalid parameter array: #{parameter_array}. Expected an array of parameters.")
63
+ end
64
+ end
65
+ else
66
+ @logger.error("Invalid application commands array: #{application_commands_array}. Expected an array of arrays.")
67
+ end
68
+ response
69
+ end
70
+
71
+ # Creates an application command globally.
72
+ # See https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
73
+ # @param name [String] The name of the command.
74
+ # @param description [String] The description of the command.
75
+ # @param name_localizations [Hash, nil] Localized names for the command.
76
+ # @param description_localizations [Hash, nil] Localized descriptions for the command.
77
+ # @param options [Array, nil] Options for the command.
78
+ # @param default_member_permissions [String, nil] Sets the default permission(s) that members need to run the command.
79
+ # (must be set to a bitwise permission flag as a string)
80
+ # @param dm_permission [TrueClass, FalseClass, nil] (deprecated, use contexts instead) Whether the command is
81
+ # available in DMs.
82
+ # @param default_permission [TrueClass, FalseClass, nil] (replaced by default_member_permissions) Whether the command
83
+ # is enabled by default when the app is added to a guild.
84
+ # @param integration_types [Array, nil] Installation context(s) where the command is available.
85
+ # @param contexts [Array, nil] Interaction context(s) where the command can be used
86
+ # @param type [Integer, nil] The type of the command.
87
+ # @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
88
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
89
+ def create_global_application_command(name, description, name_localizations: nil,
90
+ description_localizations: nil, options: nil,
91
+ default_member_permissions: nil, dm_permission: nil, default_permission: nil,
92
+ integration_types: nil, contexts: nil, type: nil, nsfw: nil)
93
+ output = {}
94
+ output[:name] = name
95
+ output[:description] = description
96
+ output[:name_localizations] = name_localizations unless name_localizations.nil?
97
+ output[:description_localizations] = description_localizations unless description_localizations.nil?
98
+ output[:options] = options unless options.nil?
99
+ output[:type] = type unless type.nil?
100
+ output[:nsfw] = nsfw unless nsfw.nil?
101
+ output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
102
+ unless dm_permission.nil?
103
+ @logger.warn('The "dm_permission" parameter has been deprecated and "contexts" should be used instead!')
104
+ output[:dm_permission] = dm_permission
105
+ end
106
+ unless default_permission.nil?
107
+ @logger.warn('The "default_permission" parameter has been replaced by "default_member_permissions" ' \
108
+ 'and will be deprecated in the future.')
109
+ output[:default_permission] = default_permission
110
+ end
111
+ output[:integration_types] = integration_types unless integration_types.nil?
112
+ output[:contexts] = contexts unless contexts.nil?
113
+ url = "#{@base_url}/applications/#{@application_id}/commands"
114
+ data = JSON.generate(output)
115
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
116
+ response = post(url, data, headers)
117
+ return response if response.is_a?(Faraday::Response) && (response.status == 201 || response.status == 200)
118
+
119
+ @logger.error("Failed to create global application command. Response: #{response_error_body(response)}")
120
+ response
121
+ end
122
+
123
+ # Mass-creates application commands globally.
124
+ # @param application_commands_array [Array] An array of arrays, where the first two elements (of the inner array)
125
+ # are the values for for the first two parameters (which are required) in the create_global_application_command
126
+ # method in order. The third element is a Hash that contains the rest of the parameters for the command, the key
127
+ # must be the name of the parameter as a symbol (e.g. :description, :options, etc.) and the value must be the value
128
+ # for that parameter.
129
+ # @return [Array] An array of Faraday::Response objects, one for each command creation request.
130
+ def create_global_application_commands(application_commands_array)
131
+ response = []
132
+ if application_commands_array.is_a?(Array)
133
+ application_commands_array.each do |parameter_array|
134
+ if parameter_array.is_a?(Array)
135
+ response << create_global_application_command(*parameter_array[0..1], **parameter_array[2] || {})
136
+ else
137
+ @logger.error("Invalid parameter array: #{parameter_array}. Expected an array of parameters.")
138
+ end
139
+ end
140
+ else
141
+ @logger.error("Invalid application commands array: #{application_commands_array}. Expected an array of arrays.")
142
+ end
143
+ response
144
+ end
145
+
146
+ # Edits a global application command. Returns 200 OK with the updated command object on success.
147
+ # If none of the optional parameters are specified (modifications), the function logs a warning and returns nil.
148
+ # See https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command
149
+ # @param command_id [String] The ID of the global command to edit.
150
+ # @param name [String, nil] New name of the command.
151
+ # @param name_localizations [Hash, nil] Localized names for the command.
152
+ # @param description [String, nil] New description of the command.
153
+ # @param description_localizations [Hash, nil] Localized descriptions for the command.
154
+ # @param options [Array, nil] New options for the command.
155
+ # @param default_member_permissions [String, nil] New default permissions bitwise string for the command.
156
+ # @param default_permission [TrueClass, FalseClass, nil] (deprecated) Whether the command is enabled by default.
157
+ # @param integration_types [Array, nil] Installation context(s) where the command is available.
158
+ # @param contexts [Array, nil] Interaction context(s) where the command can be used.
159
+ # @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
160
+ # @return [Faraday::Response, nil] The response from the Discord API, or nil if no modifications were provided.
161
+ def edit_global_application_command(command_id, name: nil, name_localizations: nil, description: nil,
162
+ description_localizations: nil, options: nil, default_member_permissions: nil,
163
+ default_permission: nil, integration_types: nil, contexts: nil, nsfw: nil)
164
+ if args[1..].all?(&:nil?)
165
+ @logger.warn("No modifications provided for global application command with ID #{command_id}. Skipping.")
166
+ return nil
167
+ end
168
+ output = {}
169
+ output[:name] = name
170
+ output[:name_localizations] = name_localizations unless name_localizations.nil?
171
+ output[:description] = description unless description.nil?
172
+ output[:description_localizations] = description_localizations unless description_localizations.nil?
173
+ output[:options] = options unless options.nil?
174
+ output[:default_permission] = default_permission unless default_permission.nil?
175
+ output[:nsfw] = nsfw unless nsfw.nil?
176
+ output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
177
+ output[:integration_types] = integration_types unless integration_types.nil?
178
+ output[:contexts] = contexts unless contexts.nil?
179
+ url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
180
+ data = JSON.generate(output)
181
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
182
+ response = patch(url, data, headers)
183
+ return response if response.is_a?(Faraday::Response) && response.status == 200
184
+
185
+ @logger.error("Failed to edit global application command with ID #{command_id}." \
186
+ " Response: #{response_error_body(response)}")
187
+ response
188
+ end
189
+
190
+ # Edits a guild application command. Returns 200 OK with the updated command object on success.
191
+ # If none of the optional parameters are specified (modifications), the function logs a warning and returns nil.
192
+ # See https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
193
+ # @param guild_id [String] The ID of the guild containing the command.
194
+ # @param command_id [String] The ID of the guild command to edit.
195
+ # @param name [String, nil] New name of the command.
196
+ # @param name_localizations [Hash, nil] Localized names for the command.
197
+ # @param description [String, nil] New description of the command.
198
+ # @param description_localizations [Hash, nil] Localized descriptions for the command.
199
+ # @param options [Array, nil] New options for the command.
200
+ # @param default_member_permissions [String, nil] New default permissions bitwise string for the command.
201
+ # @param default_permission [TrueClass, FalseClass, nil] (deprecated) Whether the command is enabled by default.
202
+ # @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
203
+ # @return [Faraday::Response, nil] The response from the Discord API, or nil if no modifications were provided.
204
+ def edit_guild_application_command(guild_id, command_id, name: nil, name_localizations: nil, description: nil,
205
+ description_localizations: nil, options: nil, default_member_permissions: nil,
206
+ default_permission: nil, nsfw: nil)
207
+ if args[2..].all?(&:nil?)
208
+ @logger.warn("No modifications provided for guild application command with command ID #{command_id}. Skipping.")
209
+ return nil
210
+ end
211
+ output = {}
212
+ output[:name] = name
213
+ output[:name_localizations] = name_localizations unless name_localizations.nil?
214
+ output[:description] = description unless description.nil?
215
+ output[:description_localizations] = description_localizations unless description_localizations.nil?
216
+ output[:options] = options unless options.nil?
217
+ output[:default_permission] = default_permission unless default_permission.nil?
218
+ output[:nsfw] = nsfw unless nsfw.nil?
219
+ output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
220
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
221
+ data = JSON.generate(output)
222
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
223
+ response = patch(url, data, headers)
224
+ return response if response.is_a?(Faraday::Response) && response.status == 200
225
+
226
+ @logger.error("Failed to edit guild application command with ID #{command_id}." \
227
+ " Response: #{response_error_body(response)}")
228
+ response
229
+ end
230
+
231
+ # Deletes a global application command. Returns 204 No Content on success.
232
+ # See https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command
233
+ # @param command_id [String] The ID of the global command to delete.
234
+ # @return [Faraday::Response] The response from the Discord API.
235
+ def delete_global_application_command(command_id)
236
+ url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
237
+ headers = { 'Authorization': @authorization_header }
238
+ response = delete(url, headers)
239
+ return response if response.is_a?(Faraday::Response) && response.status == 204
240
+
241
+ @logger.error("Failed to delete global application command with ID #{command_id}." \
242
+ "Response: #{response_error_body(response)}")
243
+ response
244
+ end
245
+
246
+ # Deletes a guild application command. Returns 204 No Content on success.
247
+ # See https://discord.com/developers/docs/interactions/application-commands#delete-guild-application-command
248
+ # @param guild_id [String] The ID of the guild containing the command.
249
+ # @param command_id [String] The ID of the guild command to delete.
250
+ # @return [Faraday::Response] The response from the Discord API.
251
+ def delete_guild_application_command(guild_id, command_id)
252
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
253
+ headers = { 'Authorization': @authorization_header }
254
+ response = delete(url, headers)
255
+ return response if response.is_a?(Faraday::Response) && response.status == 204
256
+
257
+ @logger.error("Failed to delete guild application command with ID #{command_id} in guild with ID #{guild_id}. " \
258
+ "Response: #{response_error_body(response)}")
259
+ response
260
+ end
261
+
262
+ # Returns a list of application commands for a guild. Returns 200 OK with an array of command objects.
263
+ # See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
264
+ # @param guild_id [String] The ID of the guild to list commands for.
265
+ # @param with_localizations [TrueClass, FalseClass, nil] Whether to include full localization dictionaries.
266
+ # @return [Faraday::Response] The response from the Discord API.
267
+ def get_guild_application_commands(guild_id, with_localizations: nil)
268
+ query_string_hash = {}
269
+ query_string_hash[:with_localizations] = with_localizations unless with_localizations.nil?
270
+ query_string = DiscordApi.handle_query_strings(query_string_hash)
271
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands#{query_string}"
272
+ headers = { 'Authorization': @authorization_header }
273
+ response = get(url, headers)
274
+ return response if response.is_a?(Faraday::Response) && response.status == 200
275
+
276
+ @logger.error("Failed to get guild application commands for guild with ID #{guild_id}." \
277
+ " Response: #{response_error_body(response)}")
278
+ response
279
+ end
280
+
281
+ # Returns a list of global application commands for the current application. Returns 200 OK on success.
282
+ # See https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands
283
+ # @param with_localizations [TrueClass, FalseClass, nil] Whether to include full localization dictionaries.
284
+ # @return [Faraday::Response] The response from the Discord API.
285
+ def get_global_application_commands(with_localizations: false)
286
+ query_string_hash = {}
287
+ query_string_hash[:with_localizations] = with_localizations unless with_localizations.nil?
288
+ query_string = DiscordApi.handle_query_strings(query_string_hash)
289
+ url = "#{@base_url}/applications/#{@application_id}/commands#{query_string}"
290
+ headers = { 'Authorization': @authorization_header }
291
+ response = get(url, headers)
292
+ return response if response.is_a?(Faraday::Response) && response.status == 200
293
+
294
+ @logger.error("Failed to get global application commands. Response: #{response_error_body(response)}")
295
+ response
296
+ end
297
+
298
+ # Returns a single global application command by ID. Returns 200 OK with the command object.
299
+ # See https://discord.com/developers/docs/interactions/application-commands#get-global-application-command
300
+ # @param command_id [String] The ID of the global command to retrieve.
301
+ # @return [Faraday::Response] The response from the Discord API.
302
+ def get_global_application_command(command_id)
303
+ url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
304
+ headers = { 'Authorization': @authorization_header }
305
+ response = get(url, headers)
306
+ return response if response.is_a?(Faraday::Response) && response.status == 200
307
+
308
+ @logger.error("Failed to get global application command with ID #{command_id}." \
309
+ " Response: #{response_error_body(response)}")
310
+ response
311
+ end
312
+
313
+ # Returns a single guild application command by ID. Returns 200 OK with the command object.
314
+ # See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command
315
+ # @param guild_id [String] The ID of the guild containing the command.
316
+ # @param command_id [String] The ID of the guild command to retrieve.
317
+ # @return [Faraday::Response] The response from the Discord API.
318
+ def get_guild_application_command(guild_id, command_id)
319
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
320
+ headers = { 'Authorization': @authorization_header }
321
+ response = get(url, headers)
322
+ return response if response.is_a?(Faraday::Response) && response.status == 200
323
+
324
+ @logger.error("Failed to get guild application command with ID #{command_id}." \
325
+ " Response: #{response_error_body(response)}")
326
+ response
327
+ end
328
+
329
+ # Overwrites all global application commands. Returns 200 OK with an array of the new command objects.
330
+ # See https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
331
+ # @param commands [Array] Array of command objects (hashes) to set globally.
332
+ # @return [Faraday::Response] The response from the Discord API.
333
+ def bulk_overwrite_global_application_commands(commands)
334
+ url = "#{@base_url}/applications/#{@application_id}/commands"
335
+ data = JSON.generate(commands)
336
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
337
+ response = put(url, data, headers)
338
+ return response if response.is_a?(Faraday::Response) && response.status == 200
339
+
340
+ @logger.error("Failed to bulk overwrite global application commands. Response: #{response_error_body(response)}")
341
+ response
342
+ end
343
+
344
+ # Overwrites all guild application commands in a guild. Returns 200 OK with an array of the new command objects.
345
+ # See https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands
346
+ # @param guild_id [String] The ID of the guild to overwrite commands for.
347
+ # @param commands [Array] Array of command objects (hashes) to set for the guild.
348
+ # @return [Faraday::Response] The response from the Discord API.
349
+ def bulk_overwrite_guild_application_commands(guild_id, commands)
350
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands"
351
+ data = JSON.generate(commands)
352
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
353
+ response = put(url, data, headers)
354
+ return response if response.is_a?(Faraday::Response) && response.status == 200
355
+
356
+ @logger.error("Failed to bulk overwrite guild application commands in guild with ID #{guild_id}. " \
357
+ "Response: #{response_error_body(response)}")
358
+ response
359
+ end
360
+
361
+ # Returns all application command permissions for a guild. Returns 200 OK with an array of permissions.
362
+ # See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command-permissions
363
+ # @param guild_id [String] The ID of the guild to get command permissions for.
364
+ # @return [Faraday::Response] The response from the Discord API.
365
+ def get_guild_application_command_permissions(guild_id)
366
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/permissions"
367
+ headers = { 'Authorization': @authorization_header }
368
+ response = get(url, headers)
369
+ return response if response.is_a?(Faraday::Response) && response.status == 200
370
+
371
+ @logger.error("Failed to get guild application command permissions for guild with ID #{guild_id}. " \
372
+ "Response: #{response_error_body(response)}")
373
+ response
374
+ end
375
+
376
+ # Returns command permissions for a specific guild command. Returns 200 OK with the permission object.
377
+ # See https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions
378
+ # @param guild_id [String] The ID of the guild containing the command.
379
+ # @param command_id [String] The ID of the command to get permissions for.
380
+ # @return [Faraday::Response] The response from the Discord API.
381
+ def get_application_command_permissions(guild_id, command_id)
382
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
383
+ headers = { 'Authorization': @authorization_header }
384
+ response = get(url, headers)
385
+ return response if response.is_a?(Faraday::Response) && response.status == 200
386
+
387
+ @logger.error("Failed to get appliaction command permissions for command with ID #{command_id} in guild with ID " \
388
+ "#{guild_id}. Response: #{response_error_body(response)}")
389
+ response
390
+ end
391
+
392
+ # Edits command permissions for a specific guild command. Returns 200 OK with the updated permissions.
393
+ # See https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions
394
+ # @param guild_id [String] The ID of the guild containing the command.
395
+ # @param command_id [String] The ID of the command to edit permissions for.
396
+ # @param permissions [Hash] The permissions payload to set.
397
+ # @return [Faraday::Response] The response from the Discord API.
398
+ def edit_application_command_permissions(guild_id, command_id, permissions)
399
+ url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
400
+ data = JSON.generate(permissions)
401
+ headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
402
+ response = put(url, data, headers)
403
+ return response if response.is_a?(Faraday::Response) && response.status == 200
404
+
405
+ @logger.error("Failed to edit application command permissions for command with ID #{command_id} in guild with ID " \
406
+ "#{guild_id}. Response: #{response_error_body(response)}")
407
+ response
408
+ end
409
+ end