Skip to content

Commit

Permalink
added support for application integration types
Browse files Browse the repository at this point in the history
  • Loading branch information
EinTim23 committed Oct 17, 2024
1 parent 840c533 commit a56f09c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/discordrb/api/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ def get_global_command(token, application_id, command_id)

# Create a global application command.
# https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command
def create_global_command(token, application_id, name, description, options = [], default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil)
def create_global_command(token, application_id, name, description, options = [], default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, integration_types = nil)
Discordrb::API.request(
:applications_aid_commands,
nil,
:post,
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts }.to_json,
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, integration_types: integration_types }.to_json,
Authorization: token,
content_type: :json
)
end

# Edit a global application command.
# https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command
def edit_global_command(token, application_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil)
def edit_global_command(token, application_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, integration_types = nil)
Discordrb::API.request(
:applications_aid_commands_cid,
nil,
:patch,
"#{Discordrb::API.api_base}/applications/#{application_id}/commands/#{command_id}",
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts }.compact.to_json,
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, integration_types: integration_types }.compact.to_json,
Authorization: token,
content_type: :json
)
Expand Down
8 changes: 4 additions & 4 deletions lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def get_application_command(command_id, server_id: nil)
# end
# end
# end
def register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil)
def register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, integration_types: nil)
type = ApplicationCommand::TYPES[type] || type

builder = Interactions::OptionBuilder.new
Expand All @@ -841,7 +841,7 @@ def register_application_command(name, description, server_id: nil, default_perm
resp = if server_id
API::Application.create_guild_command(@token, profile.id, server_id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts)
else
API::Application.create_global_command(@token, profile.id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts)
API::Application.create_global_command(@token, profile.id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts, integration_types)
end
cmd = ApplicationCommand.new(JSON.parse(resp), self, server_id)

Expand All @@ -856,7 +856,7 @@ def register_application_command(name, description, server_id: nil, default_perm

# @yieldparam [OptionBuilder]
# @yieldparam [PermissionBuilder]
def edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil)
def edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, integration_types: nil)
type = ApplicationCommand::TYPES[type] || type

builder = Interactions::OptionBuilder.new
Expand All @@ -867,7 +867,7 @@ def edit_application_command(command_id, server_id: nil, name: nil, description:
resp = if server_id
API::Application.edit_guild_command(@token, profile.id, server_id, command_id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts)
else
API::Application.edit_global_command(@token, profile.id, command_id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts)
API::Application.edit_global_command(@token, profile.id, command_id, name, description, builder.to_a, default_permission, type, default_member_permissions, contexts, integration_types)
end
cmd = ApplicationCommand.new(JSON.parse(resp), self, server_id)

Expand Down
15 changes: 15 additions & 0 deletions lib/discordrb/data/interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class Interaction
modal: 9
}.freeze

# Interaction context types.
# @see https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types
COMMAND_CONTEXTS = {
guild: 0,
bot_dm: 1,
private_channel: 2
}.freeze

# Application integration types.
# @see https://discord.com/developers/docs/resources/application#application-object-application-integration-types
COMMAND_INTEGRATION_TYPES = {
guild_install: 0,
user_install: 1
}.freeze

# @return [User, Member] The user that initiated the interaction.
attr_reader :user

Expand Down

0 comments on commit a56f09c

Please sign in to comment.