Skip to content

Commit b85c647

Browse files
committed
feat: application attributes
1 parent 35f8f4e commit b85c647

File tree

8 files changed

+484
-94
lines changed

8 files changed

+484
-94
lines changed

lib/discordrb/api.rb

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,18 @@ def server_tag_badge_url(server_id, badge_id, format = 'webp')
251251
"#{cdn_url}/guild-tag-badges/#{server_id}/#{badge_id}.#{format}"
252252
end
253253

254-
# Create an OAuth application
255-
def create_oauth_application(token, name, redirect_uris)
256-
request(
257-
:oauth2_applications,
258-
nil,
259-
:post,
260-
"#{api_base}/oauth2/applications",
261-
{ name: name, redirect_uris: redirect_uris }.to_json,
262-
Authorization: token,
263-
content_type: :json
264-
)
254+
# make a cover image URL from application and cover IDs.
255+
def app_cover_url(app_id, cover_id, format = 'webp')
256+
"#{cdn_url}/app-icons/#{app_id}/#{cover_id}.#{format}"
257+
end
258+
259+
# make a team icon URL from team and icon IDs.
260+
def team_icon_url(team_id, icon_id, format = 'webp')
261+
"#{cdn_url}/team-icons/#{team_id}/#{icon_id}.#{format}"
265262
end
266263

267264
# Change an OAuth application's properties
265+
# @deprecated Please use {Application#update_current_application} instead.
268266
def update_oauth_application(token, name, redirect_uris, description = '', icon = nil)
269267
request(
270268
:oauth2_applications,
@@ -283,21 +281,7 @@ def oauth_application(token)
283281
:oauth2_applications_me,
284282
nil,
285283
:get,
286-
"#{api_base}/oauth2/applications/@me",
287-
Authorization: token
288-
)
289-
end
290-
291-
# Acknowledge that a message has been received
292-
# The last acknowledged message will be sent in the ready packet,
293-
# so this is an easy way to catch up on messages
294-
def acknowledge_message(token, channel_id, message_id)
295-
request(
296-
:channels_cid_messages_mid_ack,
297-
nil, # This endpoint is unavailable for bot accounts and thus isn't subject to its rate limit requirements.
298-
:post,
299-
"#{api_base}/channels/#{channel_id}/messages/#{message_id}/ack",
300-
nil,
284+
"#{api_base}/applications/@me",
301285
Authorization: token
302286
)
303287
end
@@ -325,19 +309,6 @@ def gateway_bot(token)
325309
)
326310
end
327311

328-
# Validate a token (this request will fail if the token is invalid)
329-
def validate_token(token)
330-
request(
331-
:auth_login,
332-
nil,
333-
:post,
334-
"#{api_base}/auth/login",
335-
{}.to_json,
336-
Authorization: token,
337-
content_type: :json
338-
)
339-
end
340-
341312
# Get a list of available voice regions
342313
def voice_regions(token)
343314
request(

lib/discordrb/api/application.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,18 @@ def get_application_command_permissions(token, application_id, guild_id, command
211211
Authorization: token
212212
)
213213
end
214+
215+
# Edit the current application for the requesting bot user.
216+
# https://discord.com/developers/docs/resources/application#edit-current-application
217+
def update_current_application(token, custom_install_url = :undef, description = :undef, role_connections_verification_url = :undef, install_params = :undef, integration_types_config = :undef, flags = :undef, interactions_endpoint_url = :undef, tags = :undef, event_webhooks_url = :undef, event_webhooks_status = :undef, event_webhooks_types = :undef, icon = :undef, cover_image = :undef)
218+
Discordrb::API.request(
219+
:applications_me,
220+
nil,
221+
:patch,
222+
"#{Discordrb::API.api_base}/applications/@me",
223+
{ custom_install_url: custom_install_url, description: description, role_connections_verification_url: role_connections_verification_url, install_params: install_params, integration_types_config: integration_types_config, flags: flags, interactions_endpoint_url: interactions_endpoint_url, tags: tags, event_webhooks_url: event_webhooks_url, event_webhooks_status: event_webhooks_status, event_webhooks_types: event_webhooks_types, icon: icon, cover_image: cover_image }.reject { |_, v| v == :undef }.to_json,
224+
Authorization: token,
225+
content_type: :json
226+
)
227+
end
214228
end

lib/discordrb/bot.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,14 @@ def profile
232232
alias_method :bot_user, :profile
233233

234234
# The bot's OAuth application.
235-
# @return [Application, nil] The bot's application info. Returns `nil` if bot is not a bot account.
235+
# @return [Application] The bot's application info.
236236
def bot_application
237-
return unless @type == :bot
238-
239237
response = API.oauth_application(token)
240238
Application.new(JSON.parse(response), self)
241239
end
242240

243241
alias_method :bot_app, :bot_application
242+
alias_method :application, :bot_application
244243

245244
# The Discord API token received when logging in. Useful to explicitly call
246245
# {API} methods.

lib/discordrb/data.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@
4343
require 'discordrb/data/avatar_decoration'
4444
require 'discordrb/data/collectibles'
4545
require 'discordrb/data/primary_server'
46+
<<<<<<< HEAD
4647
require 'discordrb/data/server_preview'
4748
require 'discordrb/data/call'
49+
=======
50+
require 'discordrb/data/team'
51+
require 'discordrb/data/install_params'
52+
>>>>>>> f3988e354 (feat: missing application attributes)

0 commit comments

Comments
 (0)