disrb 0.1.2.1 → 0.1.3
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 +4 -4
- data/CHANGELOG.md +88 -0
- data/README.md +16 -5
- data/lib/disrb/application_commands.rb +401 -0
- data/lib/disrb/guild.rb +481 -101
- data/lib/disrb/logger.rb +69 -32
- data/lib/disrb/message.rb +173 -43
- data/lib/disrb/user.rb +84 -17
- data/lib/disrb.rb +218 -397
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6deda52f746ca6b5a0288842930d00b6a88ae807968faf1247e9d13ca5f6156
|
|
4
|
+
data.tar.gz: 95ca41d74b765546a14dc658671c0da64ef7bf25be9bdc9a434812836d2b1355
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35fa13cc8b978785309b19566b7daa932237afcc9125835bd75863fe456a26c7adc30b1a2d3507bcd6c4c459e17d22d1313cde56dc4a8c92e065773a8bb5e227
|
|
7
|
+
data.tar.gz: 71511d399e5ad53222a6253f63da1562abdee97a9dc1e0b6339650bc4a94e094d1dc00fa27155c039c9b8d675014c5c8077ee6aa8a4a13cf47fa9d067245ad88
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# v0.1.3 (2025-11-15)
|
|
2
|
+
|
|
3
|
+
- Add documentation
|
|
4
|
+
- Lots of bugfixes and improvements
|
|
5
|
+
- Add replacement/deprecation warnings to parameters in create_guild_application_command and create_global_application_command
|
|
6
|
+
- Fix some formatting issues in the README.md with YARD
|
|
7
|
+
- Add .yardoc and doc folders to .gitignore
|
|
8
|
+
- Add a missing parameter in create_global_application_command
|
|
9
|
+
- Remove unnecessary double-empty check in DiscordApi#modify_current_user
|
|
10
|
+
- 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
|
|
11
|
+
- Add missing implementation for https://discord.com/developers/docs/resources/user#get-current-user-guild-member
|
|
12
|
+
- Add information on how to use Faraday::Response objects and notice to read linked Discord documentation in the README.md
|
|
13
|
+
- Trim down and make logger.rb code more modular
|
|
14
|
+
- The payload_json parameter in DiscordApi#edit_message is only to be included in multipart/form-data requests, not JSON, so we remove it
|
|
15
|
+
- Rework the gateway connection reconnect code a bit
|
|
16
|
+
- Rework test.rb for the new code and also fix some bugs
|
|
17
|
+
- Add file and line information to Logger2 (shows where the logger was called)
|
|
18
|
+
- Fix a bug where all Logger2 class functions couldn't find Logger2#base
|
|
19
|
+
- 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
|
|
20
|
+
- Add CHANGELOG.md to files in gemspec
|
|
21
|
+
- Add missing parameters in DiscordApi#modify_current_member
|
|
22
|
+
- Make nick in DiscordApi#modify_current_user_nick required because its the only modification
|
|
23
|
+
- Add support for some other opcodes in DiscordApi#connect_gateway
|
|
24
|
+
- 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
|
|
25
|
+
- Move functions related to Application Commands from lib/disrb.rb to a separate file in lib/disrb/application_commands.rb
|
|
26
|
+
|
|
27
|
+
## Breaking changes
|
|
28
|
+
|
|
29
|
+
- Rename emoji_id parameters to emoji in all functions related to the Message resource
|
|
30
|
+
- Description is a required parameter in create_guild_application_command and create_global_application_command
|
|
31
|
+
- Call the block in DiscordApi#connect_gateway on every payload, not just when an interaction is created
|
|
32
|
+
(stop always expecting an interaction when the block is called)
|
|
33
|
+
- Fixes where single splat operators didn't play nicely with keyword arguments (in DiscordApi#create_guild_application_commands, DiscordApi#create_global_application_commands)
|
|
34
|
+
- 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
|
|
35
|
+
- Move DiscordApi.handle_snowflake to a separate class and slightly change usage for better documentation
|
|
36
|
+
- Comment out files/_files parameter in the relevant functions due to uploading files not being implemented yet
|
|
37
|
+
(also skip the relevant functions if only the files parameter is provided)
|
|
38
|
+
- Fix implementation of DiscordApi#modify_guild_role_positions, the required parameters are now different
|
|
39
|
+
- Apps can no longer create guilds, thus DiscordApi#create_guild has been removed
|
|
40
|
+
|
|
41
|
+
# Version 0.1.2.2 (2025-08-17)
|
|
42
|
+
|
|
43
|
+
- Fix a bug where the function wouldn't return even if the status code was the expected one for success
|
|
44
|
+
- (and disable Style/MultipleComparison in .rubocop.yml)
|
|
45
|
+
|
|
46
|
+
# Version 0.1.2.1 (2025-08-17)
|
|
47
|
+
|
|
48
|
+
- Fix a bug where connecting to the gateway would always fail
|
|
49
|
+
|
|
50
|
+
# Version 0.1.2 (2025-07-25)
|
|
51
|
+
|
|
52
|
+
- Change homepage in gemspec to point to the GitHub repository
|
|
53
|
+
- Add full support for the messages resource
|
|
54
|
+
- Bump Rubocop CI version to 0.0.4
|
|
55
|
+
|
|
56
|
+
# Version 0.1.1.3 (2025-07-24)
|
|
57
|
+
|
|
58
|
+
- Add rubocop to development dependencies (in gemspec)
|
|
59
|
+
|
|
60
|
+
# Version 0.1.1.2 (2025-07-24)
|
|
61
|
+
|
|
62
|
+
- Fix some problems with rubocop
|
|
63
|
+
- Make the CI ignore rubocop failures so that the CI can still create a release
|
|
64
|
+
- Add rubocop to development dependencies (in gemfile)
|
|
65
|
+
|
|
66
|
+
# Version 0.1.1.1 (2025-07-24)
|
|
67
|
+
|
|
68
|
+
- Bugfixes
|
|
69
|
+
- Make some functions use HandleQueryString where applicable
|
|
70
|
+
- Changed "if var" to "unless var.nil?" for consistency
|
|
71
|
+
- Functions where all options are optional, check if atleast one is provided
|
|
72
|
+
(keyword arguments over positional arguments if there are more than 1 optional arguments was already done)
|
|
73
|
+
- add Gemfile.lock to .gitignore
|
|
74
|
+
- since file structure changed, update require path in test.rb
|
|
75
|
+
- add link to changelog and license in README.md
|
|
76
|
+
|
|
77
|
+
# Version 0.1.1 (2025-07-23)
|
|
78
|
+
|
|
79
|
+
- Fully migrate from Net::HTTP to Faraday for HTTP requests
|
|
80
|
+
- Bugfixes
|
|
81
|
+
- Add roadmap to README
|
|
82
|
+
- Create CHANGELOG.md
|
|
83
|
+
- Only build and push the gem when a new tag is created
|
|
84
|
+
- Make the CI automatically create a new release with the gem in the attachments
|
|
85
|
+
|
|
86
|
+
# Version 0.1.0 (2025-07-23)
|
|
87
|
+
|
|
88
|
+
- Initial discord.rb release as a gem (indev release)
|
data/README.md
CHANGED
|
@@ -13,6 +13,16 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
|
|
|
13
13
|
|
|
14
14
|
!DISCLAIMER! This is project is in development. Expect changes that might break your code at any time.
|
|
15
15
|
|
|
16
|
+
## How to use this project
|
|
17
|
+
|
|
18
|
+
The documentation will contain information about the functions implemented in this project. Check it out [here](https://www.rubydoc.info/gems/disrb/).
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
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)`.
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
16
26
|
## Roadmap
|
|
17
27
|
- [x] Indev release (v0.1.0)
|
|
18
28
|
- [x] Basic Discord API wrapper
|
|
@@ -23,12 +33,12 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
|
|
|
23
33
|
- [x] Basic gateway support
|
|
24
34
|
- [x] RubyGem building and publishing
|
|
25
35
|
- [ ] 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
|
-
- [ ]
|
|
36
|
+
- [ ] Add support for all Discord API endpoints (v0.2.0)
|
|
37
|
+
- [ ] Add support for all Discord Gateway events and properly handle the connection (v0.1.5)
|
|
38
|
+
- [ ] Add support for uploading files (v0.1.4)
|
|
39
|
+
- [x] Documentation (v0.1.3)
|
|
40
|
+
- [x] Full message resource support (v0.1.2)
|
|
29
41
|
- [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
42
|
- [ ] Beta release (v0.3.0)
|
|
33
43
|
- [ ] Component support and builder
|
|
34
44
|
- [ ] Sharding support
|
|
@@ -36,4 +46,5 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
|
|
|
36
46
|
- [ ] Voice support
|
|
37
47
|
- [ ] Add parameter validation
|
|
38
48
|
- [ ] Stable release (v1.0.0)
|
|
49
|
+
- [ ] Class-ification update (instead of returning the raw HTTP response, make them into classes to make responses easier to use)
|
|
39
50
|
- [ ] Bugfixes, consistency and improvements
|
|
@@ -0,0 +1,401 @@
|
|
|
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 = DiscordApi.post(url, data, headers)
|
|
41
|
+
return response if response.status == 201 || response.status == 200
|
|
42
|
+
|
|
43
|
+
@logger.error("Failed to create guild application command in guild with ID #{guild_id}. Response: #{response.body}")
|
|
44
|
+
response
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Mass-creates application commands for guild(s).
|
|
48
|
+
# @param application_commands_array [Array] An array of arrays, where the first three elements (of the inner array)
|
|
49
|
+
# are the values for for the first three parameters (which are required) in the create_guild_application_command
|
|
50
|
+
# method in order. The fourth element is a Hash that contains the rest of the parameters for the command, the key
|
|
51
|
+
# must be the name of the parameter as a symbol (e.g. :description, :options, etc.) and the value must be the value
|
|
52
|
+
# for that parameter.
|
|
53
|
+
# @return [Array] An array of Faraday::Response objects, one for each command creation request.
|
|
54
|
+
def create_guild_application_commands(application_commands_array)
|
|
55
|
+
response = []
|
|
56
|
+
if application_commands_array.is_a?(Array)
|
|
57
|
+
application_commands_array.each do |parameter_array|
|
|
58
|
+
if parameter_array.is_a?(Array)
|
|
59
|
+
response << create_guild_application_command(*parameter_array[0..2], **parameter_array[3] || {})
|
|
60
|
+
else
|
|
61
|
+
@logger.error("Invalid parameter array: #{parameter_array}. Expected an array of parameters.")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
@logger.error("Invalid application commands array: #{application_commands_array}. Expected an array of arrays.")
|
|
66
|
+
end
|
|
67
|
+
response
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Creates an application command globally.
|
|
71
|
+
# See https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
|
|
72
|
+
# @param name [String] The name of the command.
|
|
73
|
+
# @param description [String] The description of the command.
|
|
74
|
+
# @param name_localizations [Hash, nil] Localized names for the command.
|
|
75
|
+
# @param description_localizations [Hash, nil] Localized descriptions for the command.
|
|
76
|
+
# @param options [Array, nil] Options for the command.
|
|
77
|
+
# @param default_member_permissions [String, nil] Sets the default permission(s) that members need to run the command.
|
|
78
|
+
# (must be set to a bitwise permission flag as a string)
|
|
79
|
+
# @param dm_permission [TrueClass, FalseClass, nil] (deprecated, use contexts instead) Whether the command is
|
|
80
|
+
# available in DMs.
|
|
81
|
+
# @param default_permission [TrueClass, FalseClass, nil] (replaced by default_member_permissions) Whether the command
|
|
82
|
+
# is enabled by default when the app is added to a guild.
|
|
83
|
+
# @param integration_types [Array, nil] Installation context(s) where the command is available.
|
|
84
|
+
# @param contexts [Array, nil] Interaction context(s) where the command can be used
|
|
85
|
+
# @param type [Integer, nil] The type of the command.
|
|
86
|
+
# @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
|
|
87
|
+
# @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
|
|
88
|
+
def create_global_application_command(name, description, name_localizations: nil,
|
|
89
|
+
description_localizations: nil, options: nil,
|
|
90
|
+
default_member_permissions: nil, dm_permission: nil, default_permission: nil,
|
|
91
|
+
integration_types: nil, contexts: nil, type: nil, nsfw: nil)
|
|
92
|
+
output = {}
|
|
93
|
+
output[:name] = name
|
|
94
|
+
output[:description] = description
|
|
95
|
+
output[:name_localizations] = name_localizations unless name_localizations.nil?
|
|
96
|
+
output[:description_localizations] = description_localizations unless description_localizations.nil?
|
|
97
|
+
output[:options] = options unless options.nil?
|
|
98
|
+
output[:type] = type unless type.nil?
|
|
99
|
+
output[:nsfw] = nsfw unless nsfw.nil?
|
|
100
|
+
output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
|
|
101
|
+
unless dm_permission.nil?
|
|
102
|
+
@logger.warn('The "dm_permission" parameter has been deprecated and "contexts" should be used instead!')
|
|
103
|
+
output[:dm_permission] = dm_permission
|
|
104
|
+
end
|
|
105
|
+
unless default_permission.nil?
|
|
106
|
+
@logger.warn('The "default_permission" parameter has been replaced by "default_member_permissions" ' \
|
|
107
|
+
'and will be deprecated in the future.')
|
|
108
|
+
output[:default_permission] = default_permission
|
|
109
|
+
end
|
|
110
|
+
output[:integration_types] = integration_types unless integration_types.nil?
|
|
111
|
+
output[:contexts] = contexts unless contexts.nil?
|
|
112
|
+
url = "#{@base_url}/applications/#{@application_id}/commands"
|
|
113
|
+
data = JSON.generate(output)
|
|
114
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
115
|
+
response = DiscordApi.post(url, data, headers)
|
|
116
|
+
return response if response.status == 201 || response.status == 200
|
|
117
|
+
|
|
118
|
+
@logger.error("Failed to create global application command. Response: #{response.body}")
|
|
119
|
+
response
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Mass-creates application commands globally.
|
|
123
|
+
# @param application_commands_array [Array] An array of arrays, where the first two elements (of the inner array)
|
|
124
|
+
# are the values for for the first two parameters (which are required) in the create_global_application_command
|
|
125
|
+
# method in order. The third element is a Hash that contains the rest of the parameters for the command, the key
|
|
126
|
+
# must be the name of the parameter as a symbol (e.g. :description, :options, etc.) and the value must be the value
|
|
127
|
+
# for that parameter.
|
|
128
|
+
# @return [Array] An array of Faraday::Response objects, one for each command creation request.
|
|
129
|
+
def create_global_application_commands(application_commands_array)
|
|
130
|
+
response = []
|
|
131
|
+
if application_commands_array.is_a?(Array)
|
|
132
|
+
application_commands_array.each do |parameter_array|
|
|
133
|
+
if parameter_array.is_a?(Array)
|
|
134
|
+
response << create_global_application_command(*parameter_array[0..1], **parameter_array[2] || {})
|
|
135
|
+
else
|
|
136
|
+
@logger.error("Invalid parameter array: #{parameter_array}. Expected an array of parameters.")
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
else
|
|
140
|
+
@logger.error("Invalid application commands array: #{application_commands_array}. Expected an array of arrays.")
|
|
141
|
+
end
|
|
142
|
+
response
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Edits a global application command. Returns 200 OK with the updated command object on success.
|
|
146
|
+
# If none of the optional parameters are specified (modifications), the function logs a warning and returns nil.
|
|
147
|
+
# See https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command
|
|
148
|
+
# @param command_id [String] The ID of the global command to edit.
|
|
149
|
+
# @param name [String, nil] New name of the command.
|
|
150
|
+
# @param name_localizations [Hash, nil] Localized names for the command.
|
|
151
|
+
# @param description [String, nil] New description of the command.
|
|
152
|
+
# @param description_localizations [Hash, nil] Localized descriptions for the command.
|
|
153
|
+
# @param options [Array, nil] New options for the command.
|
|
154
|
+
# @param default_member_permissions [String, nil] New default permissions bitwise string for the command.
|
|
155
|
+
# @param default_permission [TrueClass, FalseClass, nil] (deprecated) Whether the command is enabled by default.
|
|
156
|
+
# @param integration_types [Array, nil] Installation context(s) where the command is available.
|
|
157
|
+
# @param contexts [Array, nil] Interaction context(s) where the command can be used.
|
|
158
|
+
# @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
|
|
159
|
+
# @return [Faraday::Response, nil] The response from the Discord API, or nil if no modifications were provided.
|
|
160
|
+
def edit_global_application_command(command_id, name: nil, name_localizations: nil, description: nil,
|
|
161
|
+
description_localizations: nil, options: nil, default_member_permissions: nil,
|
|
162
|
+
default_permission: nil, integration_types: nil, contexts: nil, nsfw: nil)
|
|
163
|
+
if args[1..].all?(&:nil?)
|
|
164
|
+
@logger.warn("No modifications provided for global application command with ID #{command_id}. Skipping.")
|
|
165
|
+
return nil
|
|
166
|
+
end
|
|
167
|
+
output = {}
|
|
168
|
+
output[:name] = name
|
|
169
|
+
output[:name_localizations] = name_localizations unless name_localizations.nil?
|
|
170
|
+
output[:description] = description unless description.nil?
|
|
171
|
+
output[:description_localizations] = description_localizations unless description_localizations.nil?
|
|
172
|
+
output[:options] = options unless options.nil?
|
|
173
|
+
output[:default_permission] = default_permission unless default_permission.nil?
|
|
174
|
+
output[:nsfw] = nsfw unless nsfw.nil?
|
|
175
|
+
output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
|
|
176
|
+
output[:integration_types] = integration_types unless integration_types.nil?
|
|
177
|
+
output[:contexts] = contexts unless contexts.nil?
|
|
178
|
+
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
179
|
+
data = JSON.generate(output)
|
|
180
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
181
|
+
response = DiscordApi.patch(url, data, headers)
|
|
182
|
+
return response if response.status == 200
|
|
183
|
+
|
|
184
|
+
@logger.error("Failed to edit global application command with ID #{command_id}. Response: #{response.body}")
|
|
185
|
+
response
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Edits a guild application command. Returns 200 OK with the updated command object on success.
|
|
189
|
+
# If none of the optional parameters are specified (modifications), the function logs a warning and returns nil.
|
|
190
|
+
# See https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
|
|
191
|
+
# @param guild_id [String] The ID of the guild containing the command.
|
|
192
|
+
# @param command_id [String] The ID of the guild command to edit.
|
|
193
|
+
# @param name [String, nil] New name of the command.
|
|
194
|
+
# @param name_localizations [Hash, nil] Localized names for the command.
|
|
195
|
+
# @param description [String, nil] New description of the command.
|
|
196
|
+
# @param description_localizations [Hash, nil] Localized descriptions for the command.
|
|
197
|
+
# @param options [Array, nil] New options for the command.
|
|
198
|
+
# @param default_member_permissions [String, nil] New default permissions bitwise string for the command.
|
|
199
|
+
# @param default_permission [TrueClass, FalseClass, nil] (deprecated) Whether the command is enabled by default.
|
|
200
|
+
# @param nsfw [TrueClass, FalseClass, nil] Whether the command is NSFW.
|
|
201
|
+
# @return [Faraday::Response, nil] The response from the Discord API, or nil if no modifications were provided.
|
|
202
|
+
def edit_guild_application_command(guild_id, command_id, name: nil, name_localizations: nil, description: nil,
|
|
203
|
+
description_localizations: nil, options: nil, default_member_permissions: nil,
|
|
204
|
+
default_permission: nil, nsfw: nil)
|
|
205
|
+
if args[2..].all?(&:nil?)
|
|
206
|
+
@logger.warn("No modifications provided for guild application command with command ID #{command_id}. Skipping.")
|
|
207
|
+
return nil
|
|
208
|
+
end
|
|
209
|
+
output = {}
|
|
210
|
+
output[:name] = name
|
|
211
|
+
output[:name_localizations] = name_localizations unless name_localizations.nil?
|
|
212
|
+
output[:description] = description unless description.nil?
|
|
213
|
+
output[:description_localizations] = description_localizations unless description_localizations.nil?
|
|
214
|
+
output[:options] = options unless options.nil?
|
|
215
|
+
output[:default_permission] = default_permission unless default_permission.nil?
|
|
216
|
+
output[:nsfw] = nsfw unless nsfw.nil?
|
|
217
|
+
output[:default_member_permissions] = default_member_permissions unless default_member_permissions.nil?
|
|
218
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
219
|
+
data = JSON.generate(output)
|
|
220
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
221
|
+
response = DiscordApi.patch(url, data, headers)
|
|
222
|
+
return response if response.status == 200
|
|
223
|
+
|
|
224
|
+
@logger.error("Failed to edit guild application command with ID #{command_id}. Response: #{response.body}")
|
|
225
|
+
response
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Deletes a global application command. Returns 204 No Content on success.
|
|
229
|
+
# See https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command
|
|
230
|
+
# @param command_id [String] The ID of the global command to delete.
|
|
231
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
232
|
+
def delete_global_application_command(command_id)
|
|
233
|
+
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
234
|
+
headers = { 'Authorization': @authorization_header }
|
|
235
|
+
response = DiscordApi.delete(url, headers)
|
|
236
|
+
return response if response.status == 204
|
|
237
|
+
|
|
238
|
+
@logger.error("Failed to delete global application command with ID #{command_id}. Response: #{response.body}")
|
|
239
|
+
response
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Deletes a guild application command. Returns 204 No Content on success.
|
|
243
|
+
# See https://discord.com/developers/docs/interactions/application-commands#delete-guild-application-command
|
|
244
|
+
# @param guild_id [String] The ID of the guild containing the command.
|
|
245
|
+
# @param command_id [String] The ID of the guild command to delete.
|
|
246
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
247
|
+
def delete_guild_application_command(guild_id, command_id)
|
|
248
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
249
|
+
headers = { 'Authorization': @authorization_header }
|
|
250
|
+
response = DiscordApi.delete(url, headers)
|
|
251
|
+
return response if response.status == 204
|
|
252
|
+
|
|
253
|
+
@logger.error("Failed to delete guild application command with ID #{command_id} in guild with ID #{guild_id}. " \
|
|
254
|
+
"Response: #{response.body}")
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Returns a list of application commands for a guild. Returns 200 OK with an array of command objects.
|
|
258
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
|
|
259
|
+
# @param guild_id [String] The ID of the guild to list commands for.
|
|
260
|
+
# @param with_localizations [TrueClass, FalseClass, nil] Whether to include full localization dictionaries.
|
|
261
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
262
|
+
def get_guild_application_commands(guild_id, with_localizations: nil)
|
|
263
|
+
query_string_hash = {}
|
|
264
|
+
query_string_hash[:with_localizations] = with_localizations unless with_localizations.nil?
|
|
265
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
266
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands#{query_string}"
|
|
267
|
+
headers = { 'Authorization': @authorization_header }
|
|
268
|
+
response = DiscordApi.get(url, headers)
|
|
269
|
+
return response if response.status == 200
|
|
270
|
+
|
|
271
|
+
@logger.error("Failed to get guild application commands for guild with ID #{guild_id}. Response: #{response.body}")
|
|
272
|
+
response
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Returns a list of global application commands for the current application. Returns 200 OK on success.
|
|
276
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands
|
|
277
|
+
# @param with_localizations [TrueClass, FalseClass, nil] Whether to include full localization dictionaries.
|
|
278
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
279
|
+
def get_global_application_commands(with_localizations: false)
|
|
280
|
+
query_string_hash = {}
|
|
281
|
+
query_string_hash[:with_localizations] = with_localizations unless with_localizations.nil?
|
|
282
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
283
|
+
url = "#{@base_url}/applications/#{@application_id}/commands#{query_string}"
|
|
284
|
+
headers = { 'Authorization': @authorization_header }
|
|
285
|
+
response = DiscordApi.get(url, headers)
|
|
286
|
+
return response if response.status == 200
|
|
287
|
+
|
|
288
|
+
@logger.error("Failed to get global application commands. Response: #{response.body}")
|
|
289
|
+
response
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# Returns a single global application command by ID. Returns 200 OK with the command object.
|
|
293
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-global-application-command
|
|
294
|
+
# @param command_id [String] The ID of the global command to retrieve.
|
|
295
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
296
|
+
def get_global_application_command(command_id)
|
|
297
|
+
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
298
|
+
headers = { 'Authorization': @authorization_header }
|
|
299
|
+
response = DiscordApi.get(url, headers)
|
|
300
|
+
return response if response.status == 200
|
|
301
|
+
|
|
302
|
+
@logger.error("Failed to get global application command with ID #{command_id}. Response: #{response.body}")
|
|
303
|
+
response
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# Returns a single guild application command by ID. Returns 200 OK with the command object.
|
|
307
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command
|
|
308
|
+
# @param guild_id [String] The ID of the guild containing the command.
|
|
309
|
+
# @param command_id [String] The ID of the guild command to retrieve.
|
|
310
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
311
|
+
def get_guild_application_command(guild_id, command_id)
|
|
312
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
313
|
+
headers = { 'Authorization': @authorization_header }
|
|
314
|
+
response = DiscordApi.get(url, headers)
|
|
315
|
+
return response if response.status == 200
|
|
316
|
+
|
|
317
|
+
@logger.error("Failed to get guild application command with ID #{command_id}. Response: #{response.body}")
|
|
318
|
+
response
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Overwrites all global application commands. Returns 200 OK with an array of the new command objects.
|
|
322
|
+
# See https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
|
|
323
|
+
# @param commands [Array] Array of command objects (hashes) to set globally.
|
|
324
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
325
|
+
def bulk_overwrite_global_application_commands(commands)
|
|
326
|
+
url = "#{@base_url}/applications/#{@application_id}/commands"
|
|
327
|
+
data = JSON.generate(commands)
|
|
328
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
329
|
+
response = DiscordApi.put(url, data, headers)
|
|
330
|
+
return response if response.status == 200
|
|
331
|
+
|
|
332
|
+
@logger.error("Failed to bulk overwrite global application commands. Response: #{response.body}")
|
|
333
|
+
response
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# Overwrites all guild application commands in a guild. Returns 200 OK with an array of the new command objects.
|
|
337
|
+
# See https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands
|
|
338
|
+
# @param guild_id [String] The ID of the guild to overwrite commands for.
|
|
339
|
+
# @param commands [Array] Array of command objects (hashes) to set for the guild.
|
|
340
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
341
|
+
def bulk_overwrite_guild_application_commands(guild_id, commands)
|
|
342
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands"
|
|
343
|
+
data = JSON.generate(commands)
|
|
344
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
345
|
+
response = DiscordApi.put(url, data, headers)
|
|
346
|
+
return response if response.status == 200
|
|
347
|
+
|
|
348
|
+
@logger.error("Failed to bulk overwrite guild application commands in guild with ID #{guild_id}. " \
|
|
349
|
+
"Response: #{response.body}")
|
|
350
|
+
response
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Returns all application command permissions for a guild. Returns 200 OK with an array of permissions.
|
|
354
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command-permissions
|
|
355
|
+
# @param guild_id [String] The ID of the guild to get command permissions for.
|
|
356
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
357
|
+
def get_guild_application_command_permissions(guild_id)
|
|
358
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/permissions"
|
|
359
|
+
headers = { 'Authorization': @authorization_header }
|
|
360
|
+
response = DiscordApi.get(url, headers)
|
|
361
|
+
return response if response.status == 200
|
|
362
|
+
|
|
363
|
+
@logger.error("Failed to get guild application command permissions for guild with ID #{guild_id}. " \
|
|
364
|
+
"Response: #{response.body}")
|
|
365
|
+
response
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Returns command permissions for a specific guild command. Returns 200 OK with the permission object.
|
|
369
|
+
# See https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions
|
|
370
|
+
# @param guild_id [String] The ID of the guild containing the command.
|
|
371
|
+
# @param command_id [String] The ID of the command to get permissions for.
|
|
372
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
373
|
+
def get_application_command_permissions(guild_id, command_id)
|
|
374
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
|
|
375
|
+
headers = { 'Authorization': @authorization_header }
|
|
376
|
+
response = DiscordApi.get(url, headers)
|
|
377
|
+
return response if response.status == 200
|
|
378
|
+
|
|
379
|
+
@logger.error("Failed to get appliaction command permissions for command with ID #{command_id} in guild with ID " \
|
|
380
|
+
"#{guild_id}. Response: #{response.body}")
|
|
381
|
+
response
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
# Edits command permissions for a specific guild command. Returns 200 OK with the updated permissions.
|
|
385
|
+
# See https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions
|
|
386
|
+
# @param guild_id [String] The ID of the guild containing the command.
|
|
387
|
+
# @param command_id [String] The ID of the command to edit permissions for.
|
|
388
|
+
# @param permissions [Hash] The permissions payload to set.
|
|
389
|
+
# @return [Faraday::Response] The response from the Discord API.
|
|
390
|
+
def edit_application_command_permissions(guild_id, command_id, permissions)
|
|
391
|
+
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
|
|
392
|
+
data = JSON.generate(permissions)
|
|
393
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
394
|
+
response = DiscordApi.put(url, data, headers)
|
|
395
|
+
return response if response.status == 200
|
|
396
|
+
|
|
397
|
+
@logger.error("Failed to edit application command permissions for command with ID #{command_id} in guild with ID " \
|
|
398
|
+
"#{guild_id}. Response: #{response.body}")
|
|
399
|
+
response
|
|
400
|
+
end
|
|
401
|
+
end
|