Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Application Integration Types and Interaction Context Types #269

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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