Class: Discordrb::Application

Inherits:
Object
  • Object
show all
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

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#cover_image_idString? (readonly)

Returns the ID of the application's default rich presence invite cover image. Can be used to generate a cover image URL.

Returns:

  • (String, nil)

    the ID of the application's default rich presence invite cover image. Can be used to generate a cover image URL.

See Also:



73
74
75
# File 'lib/discordrb/data/application.rb', line 73

def cover_image_id
  @cover_image_id
end

#custom_install_urlString? (readonly)

Returns the default custom authorization URL for the application.

Returns:

  • (String, nil)

    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

#descriptionString (readonly)

Returns the application's description, or an empty string if the application doesn't have a description.

Returns:

  • (String)

    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

#flagsInteger (readonly)

Returns the application's public flags.

Returns:

  • (Integer)

    the application's public flags.



32
33
34
# File 'lib/discordrb/data/application.rb', line 32

def flags
  @flags
end

#icon_idString? (readonly)

Returns the ID of the application's icon. Can be used to generate an icon URL.

Returns:

  • (String, nil)

    the ID of the application's icon. Can be used to generate an icon URL.

See Also:



39
40
41
# File 'lib/discordrb/data/application.rb', line 39

def icon_id
  @icon_id
end

#install_paramsInstallParams (readonly)

Returns the settings for the application's default authorization link.

Returns:

  • (InstallParams)

    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_typesHash<Integer => InstallParams> (readonly)

Returns the default scopes and permissions for each supported installation context.

Returns:

  • (Hash<Integer => InstallParams>)

    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_urlString? (readonly)

Returns the interactions endpoint URL for the application.

Returns:

  • (String, nil)

    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

#nameString (readonly)

Returns the application's name.

Returns:

  • (String)

    the application's name.



23
24
25
# File 'lib/discordrb/data/application.rb', line 23

def name
  @name
end

#ownerUser? (readonly)

Returns the user that owns the application, or nil if the application belongs to a team.

Returns:

  • (User, nil)

    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_idInteger? (readonly)

Returns the game SKU ID if this application is a game sold on Discord.

Returns:

  • (Integer, nil)

    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_urlString? (readonly)

Returns the URL to the application's privacy policy.

Returns:

  • (String, nil)

    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

#publictrue, false (readonly) Also known as: public?

Returns if users other than the bot owner can add the bot to servers.

Returns:

  • (true, false)

    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_urisArray<String> (readonly) Also known as: redirect_urls

Returns an array of redirect URIs for the application.

Returns:

  • (Array<String>)

    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_granttrue, false (readonly) Also known as: requires_code_grant?

Returns whether the bot requires the full OAuth2 code grant in order to join servers.

Returns:

  • (true, false)

    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_urlString? (readonly)

Returns the role connections URL for the application.

Returns:

  • (String, nil)

    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_originsArray<String> (readonly)

Returns the application's origins permitted to use RPC.

Returns:

  • (Array<String>)

    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_idInteger? (readonly)

Returns the ID of the server that is associated with this application.

Returns:

  • (Integer, nil)

    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_countInteger (readonly)

Returns the approximate amount of server's the application has been added to.

Returns:

  • (Integer)

    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

#slugString? (readonly)

Returns the URL slug that links to the application's game store page.

Returns:

  • (String, nil)

    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

#tagsArray<String> (readonly)

Returns an array of traits describing the content and functionality of the application.

Returns:

  • (Array<String>)

    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
  @tags
end

#teamTeam? (readonly)

Returns the team that owns this application, or nil if the application isn't owned by a team.

Returns:

  • (Team, nil)

    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_urlString? (readonly)

Returns the URL to the application's terms of service.

Returns:

  • (String, nil)

    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_countInteger (readonly)

Returns the approximate amount of users that have OAuth2 authorizations for the application.

Returns:

  • (Integer)

    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
  @user_authorization_count
end

#user_install_countInteger (readonly)

Returns the approximate amount of users that have installed the application with the application.commands oauth scope.

Returns:

  • (Integer)

    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_keyString (readonly)

Returns the hex encoded key for verification in interactions and the GameSDK.

Returns:

  • (String)

    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_typesArray<String> (readonly)

Returns the webhook event types that the application is subscribed to.

Returns:

  • (Array<String>)

    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_statusInteger (readonly)

Returns the status of the application's webhook events.

Returns:

  • (Integer)

    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_urlString? (readonly)

Returns the webhook events URL used by the application to receive webhook events.

Returns:

  • (String, nil)

    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.

Parameters:

  • type (Integer, String)

    The type of the integration type.

  • scopes (Array<String, Symbol>, nil) (defaults to: nil)

    The default Oauth scopes for the config.

  • permissions (Permissions, String, Integer, nil) (defaults to: nil)

    The default permissions for the config.



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)
  permissions = permisisons.bits if permissions.respond_to?(:bits)
  new_data = @integration_types.dup

  new_data[type.to_i] = {
    scopes: scopes&.map(&:to_s),
    permissions: 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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Parameters:

  • format (String) (defaults to: 'webp')

    The URL will default to webp. You can otherwise specify one of webp, jpg or png to override this.

Returns:

  • (String, nil)

    The URL of the cover image (nil if no cover is set).



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.

Parameters:

  • type (Integer, String)

    The type of the integration type to remove.



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).

Returns:

  • (true, false)

    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.

Parameters:

  • format (String) (defaults to: 'webp')

    The URL will default to webp. You can otherwise specify one of webp, jpg or png to override this.

Returns:

  • (String, nil)

    The URL of the icon image (nil if no image is set).



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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    Whether or not the application has access to the message content intent.



281
282
283
# File 'lib/discordrb/data/application.rb', line 281

def message_content_intent?
  approved_message_content_intent? || limited_message_content_intent?
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

Note:

When using the add_flags: and remove_flags: parameters, The flags are removed first, and then added.

Modify the properties of the application.

Parameters:

  • icon (#read, nil) (defaults to: :undef)

    The new icon for the application. Must be a file-like object that response to #read.

  • cover_image (#read, nil) (defaults to: :undef)

    The new rich presence cover image for the application. Must be a file-like object that response to #read.

  • flags (Integer, Symbol, Array<Symbol, Integer>) (defaults to: :undef)

    The new flags to set for the application. Only limited intent flags can be updated.

  • tags (Array<String, Symbol>, nil) (defaults to: :undef)

    The new tags representing the application's traits.

  • description (String, nil) (defaults to: :undef)

    The new description of the application.

  • custom_install_url (String, nil) (defaults to: :undef)

    The new default custom authorization URL for the application.

  • webhook_events_url (String, nil) (defaults to: :undef)

    The new URL the application will use to receive webhook events via HTTP.

  • webhook_events_status (Integer) (defaults to: :undef)

    The new status of the application's webhook events.

  • webhook_event_types (Array<String, Symbol>, nil) (defaults to: :undef)

    The new types of webhook events that the application wishes to receive.

  • interactions_endpoint_url (String, nil) (defaults to: :undef)

    The new URL the application will use to receive INTERACTION_CREATE events via HTTP.

  • install_scopes (Array<String, Symbol>) (defaults to: :undef)

    The new default scopes to add the application to a server with.

  • install_permissions (Permissions, Integer, String) (defaults to: :undef)

    The new default permissions to add the application to a server with.

  • role_connections_verification_url (String, nil) (defaults to: :undef)

    The new role connections verification URL for the application.

  • add_flags (Integer, Symbol, Array<Symbol, Integer>) (defaults to: :undef)

    The limited intent flags to add to the application.

  • remove_flags (Integer, Symbol, Array<Symbol, Integer>) (defaults to: :undef)

    The limited intent flags to remove from the application.

  • integration_types (#to_h) (defaults to: :undef)

    The new integration types configuration for the application.

Returns:

  • (nil)


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: 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 install_permissions != :undef
    install_permissions = install_permissions.bits if install_permissions.respond_to?(:bits)
    (data[:install_params] ||= @install_params.to_h)[:permissions] = install_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.

Returns:

  • (true, false)

    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.

Returns:

  • (true, false)

    Whether or not the application has access to the presence intent.



269
270
271
# File 'lib/discordrb/data/application.rb', line 269

def presence_intent?
  approved_presence_intent? || limited_presence_intent?
end

#serverServer?

Get the server associated with this application.

Returns:

  • (Server, nil)

    This will be nil if the bot does not have an associated server set.

Raises:



126
127
128
# File 'lib/discordrb/data/application.rb', line 126

def server
  @bot.server(@server_id) if @server_id
end

#server_integration_typeInstallParams?

Get the integration types config for when the application has been installed in a server.

Returns:

  • (InstallParams, nil)

    The defaults install params for when the application's is 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.

Returns:

  • (true, false)

    Whether or not the application has access to the server members intent.



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_typeInstallParams?

Get the integration types config for when the application has been installed to a user.

Returns:

  • (InstallParams, nil)

    The default install params for when the application's is installed to a user.



169
170
171
# File 'lib/discordrb/data/application.rb', line 169

def user_integration_type
  @integration_type[1]
end