Module: OnyxCord::Bot::ApplicationCommands
- Included in:
- OnyxCord::Bot
- Defined in:
- lib/onyxcord/core/bot/application_commands.rb
Instance Method Summary collapse
-
#application_command_permissions(server_id:) ⇒ Array<ApplicationCommand::Permission>
Get the permissions for all of the application commands in a specific server.
- #application_command_registry ⇒ Object
-
#application_emoji(emoji_id) ⇒ Emoji
Fetches a single application emoji from its ID.
-
#application_emojis ⇒ Array<Emoji>
Fetches all the application emojis that the bot can use.
- #bulk_overwrite_global_application_commands(commands) ⇒ Object
- #bulk_overwrite_guild_application_commands(server_id, commands) ⇒ Object
- #commands ⇒ OnyxCord::Interactions::Registry
-
#create_application_emoji(name:, image:) ⇒ Emoji
Creates a new custom emoji that can be used by this application.
-
#delete_application_command(command_id, server_id: nil) ⇒ Object
Remove an application command from the commands registered with discord.
-
#delete_application_emoji(emoji_id) ⇒ Object
Deletes an existing application emoji.
- #edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: nil, integration_types: nil) {|, | ... } ⇒ Object
- #edit_application_command_permissions(command_id, server_id, permissions = [], bearer_token = nil) {|builder| ... } ⇒ Object
-
#edit_application_emoji(emoji_id, name:) ⇒ Emoji
Edits an existing application emoji.
-
#get_application_command(command_id, server_id: nil) ⇒ Object
Get an application command by ID.
-
#get_application_commands(server_id: nil) ⇒ Array<ApplicationCommand>
Get all application commands.
- #message_command(name, **attributes, &block) ⇒ Object
- #register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: false, integration_types: nil) {|, | ... } ⇒ Object
- #slash(name, description: nil, **attributes, &block) ⇒ Object
- #sync_application_commands!(server_id: nil, delete_unknown: false) ⇒ Object
- #user_command(name, **attributes, &block) ⇒ Object
Instance Method Details
#application_command_permissions(server_id:) ⇒ Array<ApplicationCommand::Permission>
Get the permissions for all of the application commands in a specific server.
168 169 170 171 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 168 def (server_id:) response = REST::Application.(@token, profile.id, server_id.resolve_id) OnyxCord::Internal::JSON.parse(response).flat_map { |data| data['permissions'].map { |inner| ApplicationCommand::Permission.new(inner, data, self) } } end |
#application_command_registry ⇒ Object
38 39 40 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 38 def application_command_registry @application_command_registry ||= ::OnyxCord::ApplicationCommands::Registry.new(self) end |
#application_emoji(emoji_id) ⇒ Emoji
Fetches a single application emoji from its ID.
183 184 185 186 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 183 def application_emoji(emoji_id) response = REST::Application.get_application_emoji(@token, profile.id, emoji_id.resolve_id) Emoji.new(OnyxCord::Internal::JSON.parse(response), self) end |
#application_emojis ⇒ Array<Emoji>
Fetches all the application emojis that the bot can use.
175 176 177 178 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 175 def application_emojis response = REST::Application.list_application_emojis(@token, profile.id) OnyxCord::Internal::JSON.parse(response)['items'].map { |emoji| Emoji.new(emoji, self) } end |
#bulk_overwrite_global_application_commands(commands) ⇒ Object
58 59 60 61 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 58 def bulk_overwrite_global_application_commands(commands) response = REST::Application.bulk_overwrite_global_commands(@token, profile.id, commands) OnyxCord::Internal::JSON.parse(response).map { |data| ApplicationCommand.new(data, self) } end |
#bulk_overwrite_guild_application_commands(server_id, commands) ⇒ Object
63 64 65 66 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 63 def bulk_overwrite_guild_application_commands(server_id, commands) response = REST::Application.bulk_overwrite_guild_commands(@token, profile.id, server_id.resolve_id, commands) OnyxCord::Internal::JSON.parse(response).map { |data| ApplicationCommand.new(data, self, server_id) } end |
#commands ⇒ OnyxCord::Interactions::Registry
34 35 36 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 34 def commands @commands ||= application_command_registry end |
#create_application_emoji(name:, image:) ⇒ Emoji
Creates a new custom emoji that can be used by this application.
192 193 194 195 196 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 192 def create_application_emoji(name:, image:) image = image.respond_to?(:read) ? OnyxCord.encode64(image) : image response = REST::Application.create_application_emoji(@token, profile.id, name, image) Emoji.new(OnyxCord::Internal::JSON.parse(response), self) end |
#delete_application_command(command_id, server_id: nil) ⇒ Object
Remove an application command from the commands registered with discord.
142 143 144 145 146 147 148 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 142 def delete_application_command(command_id, server_id: nil) if server_id REST::Application.delete_guild_command(@token, profile.id, server_id, command_id) else REST::Application.delete_global_command(@token, profile.id, command_id) end end |
#delete_application_emoji(emoji_id) ⇒ Object
Deletes an existing application emoji.
209 210 211 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 209 def delete_application_emoji(emoji_id) REST::Application.delete_application_emoji(@token, profile.id, emoji_id.resolve_id) end |
#edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: nil, integration_types: nil) {|, | ... } ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 111 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, nsfw: nil, integration_types: nil) type = ApplicationCommand::TYPES[type] || type contexts = contexts&.map { |context| Interaction::CONTEXTS[context] || context } integration_types = integration_types&.map { |type| Interaction::INTEGRATION_TYPES[type] || type } = Permissions.bits() if .is_a?(Array) builder = Interactions::OptionBuilder.new = Interactions::PermissionBuilder.new yield(builder, ) if block_given? resp = if server_id REST::Application.edit_guild_command(@token, profile.id, server_id, command_id, name, description, builder.to_a, , type, &.to_s, contexts, nsfw) else REST::Application.edit_global_command(@token, profile.id, command_id, name, description, builder.to_a, , type, &.to_s, contexts, nsfw, integration_types) end cmd = ApplicationCommand.new(OnyxCord::Internal::JSON.parse(resp), self, server_id) if .to_a.any? raise ArgumentError, 'Permissions can only be set for guild commands' unless server_id (cmd.id, server_id, .to_a) end cmd end |
#edit_application_command_permissions(command_id, server_id, permissions = [], bearer_token = nil) {|builder| ... } ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 154 def (command_id, server_id, = [], bearer_token = nil) builder = Interactions::PermissionBuilder.new yield builder if block_given? raise ArgumentError, 'This method requires a valid bearer token to be provided' unless bearer_token += builder.to_a bearer_token = "Bearer #{bearer_token.delete_prefix('Bearer ')}" REST::Application.(bearer_token, profile.id, server_id, command_id, ) end |
#edit_application_emoji(emoji_id, name:) ⇒ Emoji
Edits an existing application emoji.
202 203 204 205 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 202 def edit_application_emoji(emoji_id, name:) response = REST::Application.edit_application_emoji(@token, profile.id, emoji_id.resolve_id, name) Emoji.new(OnyxCord::Internal::JSON.parse(response), self) end |
#get_application_command(command_id, server_id: nil) ⇒ Object
Get an application command by ID.
24 25 26 27 28 29 30 31 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 24 def get_application_command(command_id, server_id: nil) resp = if server_id REST::Application.get_guild_command(@token, profile.id, server_id, command_id) else REST::Application.get_global_command(@token, profile.id, command_id) end ApplicationCommand.new(OnyxCord::Internal::JSON.parse(resp), self, server_id) end |
#get_application_commands(server_id: nil) ⇒ Array<ApplicationCommand>
Get all application commands.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 9 def get_application_commands(server_id: nil) resp = if server_id REST::Application.get_guild_commands(@token, profile.id, server_id) else REST::Application.get_global_commands(@token, profile.id) end OnyxCord::Internal::JSON.parse(resp).map do |command_data| ApplicationCommand.new(command_data, self, server_id) end end |
#message_command(name, **attributes, &block) ⇒ Object
50 51 52 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 50 def (name, **attributes, &block) application_command_registry.(name, **attributes, &block) end |
#register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: false, integration_types: nil) {|, | ... } ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 82 def register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: false, integration_types: nil) type = ApplicationCommand::TYPES[type] || type contexts = contexts&.map { |context| Interaction::CONTEXTS[context] || context } integration_types = integration_types&.map { |type| Interaction::INTEGRATION_TYPES[type] || type } = Permissions.bits() if .is_a?(Array) builder = Interactions::OptionBuilder.new = Interactions::PermissionBuilder.new yield(builder, ) if block_given? resp = if server_id REST::Application.create_guild_command(@token, profile.id, server_id, name, description, builder.to_a, , type, &.to_s, contexts, nsfw) else REST::Application.create_global_command(@token, profile.id, name, description, builder.to_a, , type, &.to_s, contexts, nsfw, integration_types) end cmd = ApplicationCommand.new(OnyxCord::Internal::JSON.parse(resp), self, server_id) if .to_a.any? raise ArgumentError, 'Permissions can only be set for guild commands' unless server_id (cmd.id, server_id, .to_a) end cmd end |
#slash(name, description: nil, **attributes, &block) ⇒ Object
42 43 44 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 42 def slash(name, description: nil, **attributes, &block) application_command_registry.slash(name, description: description, **attributes, &block) end |
#sync_application_commands!(server_id: nil, delete_unknown: false) ⇒ Object
54 55 56 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 54 def sync_application_commands!(server_id: nil, delete_unknown: false) application_command_registry.sync!(server_id: server_id, delete_unknown: delete_unknown) end |
#user_command(name, **attributes, &block) ⇒ Object
46 47 48 |
# File 'lib/onyxcord/core/bot/application_commands.rb', line 46 def user_command(name, **attributes, &block) application_command_registry.user(name, **attributes, &block) end |