Skip to content

Commit f77cc0d

Browse files
committed
feat: add Profile#bio and Profile#bio=
1 parent fbcffca commit f77cc0d

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

lib/discordrb/api/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def update_current_application(token, custom_install_url: :undef, description: :
284284
nil,
285285
:patch,
286286
"#{Discordrb::API.api_base}/applications/@me",
287-
{ 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 { |_, value| value == :undef }.to_json,
287+
{ custom_install_url:, description:, role_connections_verification_url:, install_params:, integration_types_config:, flags:, interactions_endpoint_url:, tags:, event_webhooks_url:, event_webhooks_status:, event_webhooks_types:, icon:, cover_image: }.reject { |_, value| value == :undef }.to_json,
288288
Authorization: token,
289289
content_type: :json
290290
)

lib/discordrb/data/application.rb

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Application
2222
# @return [String] the application's name.
2323
attr_reader :name
2424

25-
# @return [String] the application's description.
25+
# @return [String] the application's description, or an empty string if the application doesn't have a description.
2626
attr_reader :description
2727

2828
# @return [Array<String>] the application's origins permitted to use RPC.
@@ -42,10 +42,6 @@ class Application
4242
attr_reader :public
4343
alias_method :public?, :public
4444

45-
# @return [Profile] the user object of the associated bot for this application.
46-
attr_reader :profile
47-
alias_method :bot, :profile
48-
4945
# @return [true, false] whether the bot requires the full OAuth2 code grant in order to join servers.
5046
attr_reader :requires_code_grant
5147
alias_method :requires_code_grant?, :requires_code_grant
@@ -170,7 +166,7 @@ def add_integration_type(type:, scopes: nil, permissions: nil)
170166
# Update the flags of this application. I recommend using this instead of {#flags=}.
171167
# @param add [Array<Integer, Symbol> Integer, Symbol] The flags to add to the application.
172168
# @param remove [Array<Integer, Symbol> Integer, Symbol] The flags to remove from the application.
173-
# @note The flags will be removed first, then added. Only limited intent flags can be updated.
169+
# @note The flags will be removed first, and then added. Only limited intent flags can be updated.
174170
def update_flags(add: 0, remove: 0)
175171
flags = lambda do |value|
176172
[*value].map { |flag_bit| FLAGS[flag_bit] || flag_bit.to_i }.reduce(&:|)
@@ -217,45 +213,45 @@ def flags=(flags)
217213
end
218214

219215
# Set the description for the application.
220-
# @param description [String] The new description for the application.
216+
# @param description [String, nil] The new description for the application.
221217
def description=(description)
222-
update_application(description: description)
223-
end
224-
225-
# Set the URL that webhook events will be sent to for the application.
226-
# @param events_url [String] The new URL that webhook events will be sent to.
227-
def webhook_events_url=(events_url)
228-
update_application(event_webhooks_url: events_url)
229-
end
230-
231-
# Set the custom installation URL for the application.
232-
# @param install_url [String] The new default custom authorization URL for the application.
233-
def custom_install_url=(install_url)
234-
update_application(custom_install_url: install_url)
218+
update_application(description: description || '')
235219
end
236220

237221
# Set the webhook events that the applicaton is subscribed to.
238-
# @param event_types [Array<String>] The new webhook event types to subscribe to for the application.
222+
# @param event_types [Array<String>] The new webhook event types to subscribe to.
239223
def webhook_event_types=(event_types)
240224
update_application(event_webhooks_types: event_types)
241225
end
242226

243227
# Set the status of webhook events for the application.
244-
# @param events_status [Integer] The new status of webhook events. `1` for disabled, `2` for enabled.
228+
# @param events_status [Integer] The new webhook events status for the application.
245229
def webhook_events_status=(events_status)
246230
update_application(event_webhooks_status: events_status)
247231
end
248232

233+
# Set the URL that webhook events will be sent to for the application.
234+
# @param events_url [String, nil] The new URL that webhook events will be sent to.
235+
def webhook_events_url=(events_url)
236+
update_application(event_webhooks_url: events_url || '')
237+
end
238+
239+
# Set the custom installation URL for the application.
240+
# @param install_url [String, nil] The new default custom authorization URL for the application.
241+
def custom_install_url=(install_url)
242+
update_application(custom_install_url: install_url || '')
243+
end
244+
249245
# Set the endpoint that will reccieve interaction over HTTP POST for the application.
250-
# @param endpoint_url [String] The new endpoint. Must pass security validation or the request will fail.
246+
# @param endpoint_url [String, nil] The new interactions endpoint. Must pass security validation.
251247
def interactions_endpoint_url=(endpoint_url)
252-
update_application(interactions_endpoint_url: endpoint_url)
248+
update_application(interactions_endpoint_url: endpoint_url || '')
253249
end
254250

255251
# Set the role connection verification URL for the application.
256-
# @param verification_url [String] The new role connections verification URL for the application.
252+
# @param verification_url [String, nil] The new role connections verification URL for the application.
257253
def role_connections_verification_url=(verification_url)
258-
update_application(role_connections_verification_url: verification_url)
254+
update_application(role_connections_verification_url: verification_url || '')
259255
end
260256

261257
# The inspect method is overwritten to give more useful output.
@@ -301,7 +297,6 @@ def update_data(new_data)
301297
@owner = new_data['owner'] ? @bot.ensure_user(new_data['owner']) : nil
302298

303299
@public = new_data['bot_public']
304-
@profile = new_data['bot'] ? Profile.new(new_data['bot'], @bot) : nil
305300
@requires_code_grant = new_data['bot_require_code_grant']
306301
@terms_of_service_url = new_data['terms_of_service_url']
307302
@privacy_policy_url = new_data['privacy_policy_url']

lib/discordrb/data/profile.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def banner=(banner)
4040
end
4141
end
4242

43+
# Get the bot's global bio.
44+
# @return [String] The bot's global bio, or an empty string if it doesn't have one set.
45+
def bio
46+
@bot.application.description
47+
end
48+
49+
# Set the bot's global bio.
50+
# @param bio [String, nil] The bot's new global bio, or `nil` to remove the current bio.
51+
def bio=(bio)
52+
@bot.application.description = bio
53+
end
54+
4355
# Updates the cached profile data with the new one.
4456
# @note For internal use only.
4557
# @!visibility private

0 commit comments

Comments
 (0)