Class: Discordrb::Application
- Inherits:
-
Object
- Object
- Discordrb::Application
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data/application.rb
Overview
Information about a bot's associated application.
Constant Summary collapse
- FLAGS =
Map of application flags.
{ automod_rule_badge: 1 << 6, approved_presence_intent: 1 << 12, limited_presence_intent: 1 << 13, approved_server_members_intent: 1 << 14, limited_server_members_intent: 1 << 15, pending_server_limit_verification: 1 << 16, embedded: 1 << 17, approved_message_content_intent: 1 << 18, limited_message_content_intent: 1 << 19, application_command_badge: 1 << 23 }.freeze
Instance Attribute Summary collapse
-
#cover_image_id ⇒ String?
readonly
The ID of the application's default rich presence invite cover image.
-
#custom_install_url ⇒ String?
readonly
The default custom authorization URL for the application.
-
#description ⇒ String
readonly
The application's description, or an empty string if the application doesn't have a description.
-
#flags ⇒ Integer
readonly
The application's public flags.
-
#icon_id ⇒ String?
readonly
The ID of the application's icon.
-
#install_params ⇒ InstallParams
readonly
The settings for the application's default authorization link.
-
#integration_types ⇒ Hash<Integer => InstallParams>
readonly
The default scopes and permissions for each supported installation context.
-
#interactions_endpoint_url ⇒ String?
readonly
The interactions endpoint URL for the application.
-
#name ⇒ String
readonly
The application's name.
-
#owner ⇒ User?
readonly
The user that owns the application, or nil if the application belongs to a team.
-
#primary_sku_id ⇒ Integer?
readonly
The game SKU ID if this application is a game sold on Discord.
-
#privacy_policy_url ⇒ String?
readonly
The URL to the application's privacy policy.
-
#public ⇒ true, false
(also: #public?)
readonly
If users other than the bot owner can add the bot to servers.
-
#redirect_uris ⇒ Array<String>
(also: #redirect_urls)
readonly
An array of redirect URIs for the application.
-
#requires_code_grant ⇒ true, false
(also: #requires_code_grant?)
readonly
Whether the bot requires the full OAuth2 code grant in order to join servers.
-
#role_connections_verification_url ⇒ String?
readonly
The role connections URL for the application.
-
#rpc_origins ⇒ Array<String>
readonly
The application's origins permitted to use RPC.
-
#server_id ⇒ Integer?
readonly
The ID of the server that is associated with this application.
-
#server_install_count ⇒ Integer
readonly
The approximate amount of server's the application has been added to.
-
#slug ⇒ String?
readonly
The URL slug that links to the application's game store page.
-
#tags ⇒ Array<String>
readonly
An array of traits describing the content and functionality of the application.
-
#team ⇒ Team?
readonly
The team that owns this application, or
nilif the application isn't owned by a team. -
#terms_of_service_url ⇒ String?
readonly
The URL to the application's terms of service.
-
#user_authorization_count ⇒ Integer
readonly
The approximate amount of users that have OAuth2 authorizations for the application.
-
#user_install_count ⇒ Integer
readonly
The approximate amount of users that have installed the application with the
application.commandsoauth scope. -
#verify_key ⇒ String
readonly
The hex encoded key for verification in interactions and the GameSDK.
-
#webhook_event_types ⇒ Array<String>
readonly
The webhook event types that the application is subscribed to.
-
#webhook_events_status ⇒ Integer
readonly
The status of the application's webhook events.
-
#webhook_events_url ⇒ String?
readonly
The webhook events URL used by the application to receive webhook events.
Attributes included from IDObject
Instance Method Summary collapse
-
#add_integration_type(type:, scopes: nil, permissions: nil) ⇒ Object
Add an integration types config for the application.
-
#application_command_badge? ⇒ true, false
Whether or not the application has registered at least one global application command.
-
#approved_message_content_intent? ⇒ true, false
Whether or not the application is in more than 100 servers and has access to the message content intent.
-
#approved_presence_intent? ⇒ true, false
Whether or not the application is in less than 100 servers and has access to the server presences intent.
-
#approved_server_members_intent? ⇒ true, false
Whether or not the application is in more than 100 servers and has access to the server members intent.
-
#automod_rule_badge? ⇒ true, false
Whether or not the application has at least 100 automod rules across all of its servers.
-
#cover_image_url(format: 'webp') ⇒ String?
Utility method to get a application's cover image URL.
-
#delete_integration_type(type) ⇒ Object
Delete an integration types config for the application.
-
#embedded? ⇒ true, false
Whether or not the application is embedded within the Discord application (currently unavailable publicly).
-
#icon_url(format: 'webp') ⇒ String?
Utility method to get a application's icon URL.
-
#limited_message_content_intent? ⇒ true, false
Whether or not the application is in less than 100 servers and has access to the message content intent.
-
#limited_presence_intent? ⇒ true, false
Whether or not the application is in more than 100 servers and has access to the server presences intent.
-
#limited_server_members_intent? ⇒ true, false
Whether or not the application is in less than 100 servers and has access to the server members intent.
-
#message_content_intent? ⇒ true, false
Check if the application has the message content intent toggled on its dashboard.
-
#modify(icon: :undef, cover_image: :undef, flags: :undef, tags: :undef, description: :undef, custom_install_url: :undef, webhook_events_url: :undef, webhook_events_status: :undef, webhook_event_types: :undef, interactions_endpoint_url: :undef, install_scopes: :undef, install_permissions: :undef, role_connections_verification_url: :undef, add_flags: :undef, remove_flags: :undef, integration_types: :undef) ⇒ nil
Modify the properties of the application.
-
#pending_server_limit_verification? ⇒ true, false
Whether or not the application has underwent unusual growth that is preventing it from being verified.
-
#presence_intent? ⇒ true, false
Check if the application has the presence intent toggled on its dashboard.
-
#server ⇒ Server?
Get the server associated with this application.
-
#server_integration_type ⇒ InstallParams?
Get the integration types config for when the application has been installed in a server.
-
#server_members_intent? ⇒ true, false
Check if the application has the server members intent toggled on its dashboard.
-
#user_integration_type ⇒ InstallParams?
Get the integration types config for when the application has been installed to a user.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#cover_image_id ⇒ String? (readonly)
Returns the ID of the application's default rich presence invite cover image. Can be used to generate a cover image URL.
73 74 75 |
# File 'lib/discordrb/data/application.rb', line 73 def cover_image_id @cover_image_id end |
#custom_install_url ⇒ String? (readonly)
Returns the default custom authorization URL for the application.
114 115 116 |
# File 'lib/discordrb/data/application.rb', line 114 def custom_install_url @custom_install_url end |
#description ⇒ String (readonly)
Returns the application's description, or an empty string if the application doesn't have a description.
26 27 28 |
# File 'lib/discordrb/data/application.rb', line 26 def description @description end |
#flags ⇒ Integer (readonly)
Returns the application's public flags.
32 33 34 |
# File 'lib/discordrb/data/application.rb', line 32 def flags @flags end |
#icon_id ⇒ String? (readonly)
Returns the ID of the application's icon. Can be used to generate an icon URL.
39 40 41 |
# File 'lib/discordrb/data/application.rb', line 39 def icon_id @icon_id end |
#install_params ⇒ InstallParams (readonly)
Returns the settings for the application's default authorization link.
108 109 110 |
# File 'lib/discordrb/data/application.rb', line 108 def install_params @install_params end |
#integration_types ⇒ Hash<Integer => InstallParams> (readonly)
Returns the default scopes and permissions for each supported installation context.
111 112 113 |
# File 'lib/discordrb/data/application.rb', line 111 def integration_types @integration_types end |
#interactions_endpoint_url ⇒ String? (readonly)
Returns the interactions endpoint URL for the application.
90 91 92 |
# File 'lib/discordrb/data/application.rb', line 90 def interactions_endpoint_url @interactions_endpoint_url end |
#name ⇒ String (readonly)
Returns the application's name.
23 24 25 |
# File 'lib/discordrb/data/application.rb', line 23 def name @name end |
#owner ⇒ User? (readonly)
Returns the user that owns the application, or nil if the application belongs to a team.
35 36 37 |
# File 'lib/discordrb/data/application.rb', line 35 def owner @owner end |
#primary_sku_id ⇒ Integer? (readonly)
Returns the game SKU ID if this application is a game sold on Discord.
68 69 70 |
# File 'lib/discordrb/data/application.rb', line 68 def primary_sku_id @primary_sku_id end |
#privacy_policy_url ⇒ String? (readonly)
Returns the URL to the application's privacy policy.
53 54 55 |
# File 'lib/discordrb/data/application.rb', line 53 def privacy_policy_url @privacy_policy_url end |
#public ⇒ true, false (readonly) Also known as: public?
Returns if users other than the bot owner can add the bot to servers.
42 43 44 |
# File 'lib/discordrb/data/application.rb', line 42 def public @public end |
#redirect_uris ⇒ Array<String> (readonly) Also known as: redirect_urls
Returns an array of redirect URIs for the application.
86 87 88 |
# File 'lib/discordrb/data/application.rb', line 86 def redirect_uris @redirect_uris end |
#requires_code_grant ⇒ true, false (readonly) Also known as: requires_code_grant?
Returns whether the bot requires the full OAuth2 code grant in order to join servers.
46 47 48 |
# File 'lib/discordrb/data/application.rb', line 46 def requires_code_grant @requires_code_grant end |
#role_connections_verification_url ⇒ String? (readonly)
Returns the role connections URL for the application.
93 94 95 |
# File 'lib/discordrb/data/application.rb', line 93 def role_connections_verification_url @role_connections_verification_url end |
#rpc_origins ⇒ Array<String> (readonly)
Returns the application's origins permitted to use RPC.
29 30 31 |
# File 'lib/discordrb/data/application.rb', line 29 def rpc_origins @rpc_origins end |
#server_id ⇒ Integer? (readonly)
Returns the ID of the server that is associated with this application.
62 63 64 |
# File 'lib/discordrb/data/application.rb', line 62 def server_id @server_id end |
#server_install_count ⇒ Integer (readonly)
Returns the approximate amount of server's the application has been added to.
76 77 78 |
# File 'lib/discordrb/data/application.rb', line 76 def server_install_count @server_install_count end |
#slug ⇒ String? (readonly)
Returns the URL slug that links to the application's game store page.
65 66 67 |
# File 'lib/discordrb/data/application.rb', line 65 def slug @slug end |
#tags ⇒ Array<String> (readonly)
Returns an array of traits describing the content and functionality of the application.
105 106 107 |
# File 'lib/discordrb/data/application.rb', line 105 def @tags end |
#team ⇒ Team? (readonly)
Returns the team that owns this application, or nil if the application isn't owned by a team.
59 60 61 |
# File 'lib/discordrb/data/application.rb', line 59 def team @team end |
#terms_of_service_url ⇒ String? (readonly)
Returns the URL to the application's terms of service.
50 51 52 |
# File 'lib/discordrb/data/application.rb', line 50 def terms_of_service_url @terms_of_service_url end |
#user_authorization_count ⇒ Integer (readonly)
Returns the approximate amount of users that have OAuth2 authorizations for the application.
83 84 85 |
# File 'lib/discordrb/data/application.rb', line 83 def @user_authorization_count end |
#user_install_count ⇒ Integer (readonly)
Returns the approximate amount of users that have installed the application with the
application.commands oauth scope.
80 81 82 |
# File 'lib/discordrb/data/application.rb', line 80 def user_install_count @user_install_count end |
#verify_key ⇒ String (readonly)
Returns the hex encoded key for verification in interactions and the GameSDK.
56 57 58 |
# File 'lib/discordrb/data/application.rb', line 56 def verify_key @verify_key end |
#webhook_event_types ⇒ Array<String> (readonly)
Returns the webhook event types that the application is subscribed to.
102 103 104 |
# File 'lib/discordrb/data/application.rb', line 102 def webhook_event_types @webhook_event_types end |
#webhook_events_status ⇒ Integer (readonly)
Returns the status of the application's webhook events.
99 100 101 |
# File 'lib/discordrb/data/application.rb', line 99 def webhook_events_status @webhook_events_status end |
#webhook_events_url ⇒ String? (readonly)
Returns the webhook events URL used by the application to receive webhook events.
96 97 98 |
# File 'lib/discordrb/data/application.rb', line 96 def webhook_events_url @webhook_events_url end |
Instance Method Details
#add_integration_type(type:, scopes: nil, permissions: nil) ⇒ Object
Add an integration types config for the application.
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/discordrb/data/application.rb', line 155 def add_integration_type(type:, scopes: nil, permissions: nil) = permisisons.bits if .respond_to?(:bits) new_data = @integration_types.dup new_data[type.to_i] = { scopes: scopes&.map(&:to_s), permissions: &.to_s } modify(integration_types: collect_integration_types(new_data.compact)) end |
#application_command_badge? ⇒ true, false
Returns whether or not the application has registered at least one global application command.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#approved_message_content_intent? ⇒ true, false
Returns whether or not the application is in more than 100 servers and has access to the message content intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#approved_presence_intent? ⇒ true, false
Returns whether or not the application is in less than 100 servers and has access to the server presences intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#approved_server_members_intent? ⇒ true, false
Returns whether or not the application is in more than 100 servers and has access to the server members intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#automod_rule_badge? ⇒ true, false
Returns whether or not the application has at least 100 automod rules across all of its servers.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#cover_image_url(format: 'webp') ⇒ String?
Utility method to get a application's cover image URL.
140 141 142 |
# File 'lib/discordrb/data/application.rb', line 140 def cover_image_url(format: 'webp') API.app_cover_url(@id, @cover_image_id, format) if @cover_image_id end |
#delete_integration_type(type) ⇒ Object
Delete an integration types config for the application.
146 147 148 149 |
# File 'lib/discordrb/data/application.rb', line 146 def delete_integration_type(type) new_data = @integration_types.dup.tap { |i| i.delete(type.to_i) } modify(integration_types: collect_integration_types(new_data)) end |
#embedded? ⇒ true, false
Returns whether or not the application is embedded within the Discord application (currently unavailable publicly).
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#icon_url(format: 'webp') ⇒ String?
Utility method to get a application's icon URL.
133 134 135 |
# File 'lib/discordrb/data/application.rb', line 133 def icon_url(format: 'webp') API.app_icon_url(@id, @icon_id, format) if @icon_id end |
#limited_message_content_intent? ⇒ true, false
Returns whether or not the application is in less than 100 servers and has access to the message content intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#limited_presence_intent? ⇒ true, false
Returns whether or not the application is in more than 100 servers and has access to the server presences intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#limited_server_members_intent? ⇒ true, false
Returns whether or not the application is in less than 100 servers and has access to the server members intent.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#message_content_intent? ⇒ true, false
Check if the application has the message content intent toggled on its dashboard.
281 282 283 |
# File 'lib/discordrb/data/application.rb', line 281 def || end |
#modify(icon: :undef, cover_image: :undef, flags: :undef, tags: :undef, description: :undef, custom_install_url: :undef, webhook_events_url: :undef, webhook_events_status: :undef, webhook_event_types: :undef, interactions_endpoint_url: :undef, install_scopes: :undef, install_permissions: :undef, role_connections_verification_url: :undef, add_flags: :undef, remove_flags: :undef, integration_types: :undef) ⇒ nil
When using the add_flags: and remove_flags: parameters, The flags are removed first, and then added.
Modify the properties of the application.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/discordrb/data/application.rb', line 198 def modify( icon: :undef, cover_image: :undef, flags: :undef, tags: :undef, description: :undef, custom_install_url: :undef, webhook_events_url: :undef, webhook_events_status: :undef, webhook_event_types: :undef, interactions_endpoint_url: :undef, install_scopes: :undef, install_permissions: :undef, role_connections_verification_url: :undef, add_flags: :undef, remove_flags: :undef, integration_types: :undef ) data = { icon: icon.respond_to?(:read) ? Discordrb.encode64(icon) : icon, cover_image: cover_image.respond_to?(:read) ? Discordrb.encode64(cover_image) : cover_image, flags: flags == :undef ? flags : [*flags].map { |bit| FLAGS[bit] || bit.to_i }.reduce(&:|), tags: , description: description, custom_install_url: custom_install_url, event_webhooks_url: webhook_events_url || '', event_webhooks_status: webhook_events_status, event_webhooks_types: webhook_event_types || [], interactions_endpoint_url: interactions_endpoint_url, role_connections_verification_url: role_connections_verification_url, integration_types_config: integration_types == :undef ? integration_types : integration_types&.to_h } ((data[:install_params] ||= @install_params.to_h)[:scopes] = install_scopes) if install_scopes != :undef if != :undef = .bits if .respond_to?(:bits) (data[:install_params] ||= @install_params.to_h)[:permissions] = .to_s end if add_flags != :undef || remove_flags != :undef raise ArgumentError, "'add_flags' and 'remove_flags' are mutually exclusive with 'flags'" if flags != :undef to_flags = lambda do |value| [*(value == :undef ? 0 : value)].map { |bit| FLAGS[bit] || bit.to_i }.reduce(&:|) end data[:flags] = ((@flags & ~to_flags.call(remove_flags)) | to_flags.call(add_flags)) end update_data(JSON.parse(API::Application.update_current_application(@bot.token, **data))) nil end |
#pending_server_limit_verification? ⇒ true, false
Returns whether or not the application has underwent unusual growth that is preventing it from being verified.
261 262 263 264 265 |
# File 'lib/discordrb/data/application.rb', line 261 FLAGS.each do |name, value| define_method("#{name}?") do @flags.anybits?(value) end end |
#presence_intent? ⇒ true, false
Check if the application has the presence intent toggled on its dashboard.
269 270 271 |
# File 'lib/discordrb/data/application.rb', line 269 def presence_intent? approved_presence_intent? || limited_presence_intent? end |
#server ⇒ Server?
Get the server associated with this application.
126 127 128 |
# File 'lib/discordrb/data/application.rb', line 126 def server @bot.server(@server_id) if @server_id end |
#server_integration_type ⇒ InstallParams?
Get the integration types config for when the application has been installed in a server.
175 176 177 |
# File 'lib/discordrb/data/application.rb', line 175 def server_integration_type @integration_types[0] end |
#server_members_intent? ⇒ true, false
Check if the application has the server members intent toggled on its dashboard.
275 276 277 |
# File 'lib/discordrb/data/application.rb', line 275 def server_members_intent? approved_server_members_intent? || limited_server_members_intent? end |
#user_integration_type ⇒ InstallParams?
Get the integration types config for when the application has been installed to a user.
169 170 171 |
# File 'lib/discordrb/data/application.rb', line 169 def user_integration_type @integration_type[1] end |