-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add builder for edit_current_application_info endpoint
- Loading branch information
1 parent
71ab298
commit 8fd6b7e
Showing
2 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
use std::borrow::Cow; | ||
use std::collections::HashMap; | ||
|
||
#[cfg(feature = "http")] | ||
use crate::http::Http; | ||
use crate::model::prelude::*; | ||
|
||
/// A builder for editing [`CurrentApplicationInfo`] i.e the current Application's information. | ||
/// | ||
/// The fields are optional, and only the ones explicitly set will be updated. | ||
#[derive(Clone, Debug, Default, Serialize)] | ||
#[must_use] | ||
pub struct EditCurrentApplicationInfo<'a> { | ||
/// Default custom authorization URL for the app, if enabled. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
custom_install_url: Option<Cow<'a, str>>, | ||
|
||
/// Description of the app. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
description: Option<Cow<'a, str>>, | ||
|
||
/// Role connection verification URL for the app. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
role_connections_verification_url: Option<Cow<'a, str>>, | ||
|
||
/// Settings for the app's default in-app authorization link, if enabled. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
install_params: Option<InstallParams>, | ||
|
||
/// Default scopes and permissions for each supported installation context. | ||
/// Value for each key is an integration type configuration object. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
integration_types_config: Option<HashMap<InstallationContext, InstallationContextConfig>>, | ||
|
||
/// App's public flags. | ||
/// | ||
/// Only limited intent flags (GATEWAY_PRESENCE_LIMITED, GATEWAY_GUILD_MEMBERS_LIMITED, | ||
/// and GATEWAY_MESSAGE_CONTENT_LIMITED) can be updated via the API. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
flags: Option<ApplicationFlags>, | ||
|
||
/// Icon for the app | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
icon: Option<ImageHash>, | ||
|
||
/// Default rich presence invite cover image for the app. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
cover_image: Option<ImageHash>, | ||
|
||
/// Interactions endpoint URL for the app. | ||
/// | ||
/// To update an Interactions endpoint URL via the API, the URL must be valid according | ||
/// to the [Receiving an Interaction] | ||
/// (https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction) documentation. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
interactions_endpoint_url: Option<Cow<'a, str>>, | ||
|
||
/// List of tags describing the content and functionality of the app (max of 20 characters per | ||
/// tag). Max of 5 tags. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
tags: Option<Vec<String>>, | ||
|
||
/// Event webhooks URL for the app to receive webhook events. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
event_webhooks_url: Option<Cow<'a, str>>, | ||
|
||
/// If webhook events are enabled for the app. 1 to disable, and 2 to enable. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
event_webhook_status: Option<EventWebhookStatus>, | ||
|
||
/// List of Webhook event types to subscribe to. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
event_webhook_types: Option<Vec<EventWebhookType>>, | ||
} | ||
|
||
impl<'a> EditCurrentApplicationInfo<'a> { | ||
/// Creates a new builder instance with all values set to None. | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
/// Sets the custom installation URL. | ||
pub fn install_url(mut self, url: impl Into<Cow<'a, str>>) -> Self { | ||
self.custom_install_url = Some(url.into()); | ||
self | ||
} | ||
|
||
/// Sets the description of the application. | ||
pub fn description(mut self, description: impl Into<Cow<'a, str>>) -> Self { | ||
self.description = Some(description.into()); | ||
self | ||
} | ||
|
||
/// Sets the role connections verification URL. | ||
pub fn verification_url(mut self, url: impl Into<Cow<'a, str>>) -> Self { | ||
self.role_connections_verification_url = Some(url.into()); | ||
self | ||
} | ||
|
||
/// Sets the installation parameters for the application. | ||
pub fn install_params(mut self, params: InstallParams) -> Self { | ||
self.install_params = Some(params); | ||
self | ||
} | ||
|
||
/// Sets the integration types configuration. | ||
pub fn integration_types_config( | ||
mut self, | ||
config: HashMap<InstallationContext, InstallationContextConfig>, | ||
) -> Self { | ||
self.integration_types_config = Some(config); | ||
self | ||
} | ||
|
||
/// Sets the application flags. | ||
pub fn flags(mut self, flags: ApplicationFlags) -> Self { | ||
self.flags = Some(flags); | ||
self | ||
} | ||
|
||
/// Sets the application icon hash. | ||
pub fn icon(mut self, hash: &str) -> Self { | ||
if let Ok(image_hash) = hash.parse() { | ||
self.icon = Some(image_hash); | ||
} else { | ||
println!("Error parsing image hash while constructing EditCurrentApplicationInfo"); | ||
} | ||
self | ||
} | ||
|
||
/// Sets the cover image hash. | ||
pub fn cover_image(mut self, hash: &str) -> Self { | ||
if let Ok(image_hash) = hash.parse() { | ||
self.cover_image = Some(image_hash); | ||
} else { | ||
println!("Error parsing image hash while constructing EditCurrentApplicationInfo"); | ||
} | ||
self | ||
} | ||
|
||
/// Sets the interactions endpoint URL. | ||
pub fn endpoint_url(mut self, url: impl Into<Cow<'a, str>>) -> Self { | ||
self.interactions_endpoint_url = Some(url.into()); | ||
self | ||
} | ||
|
||
/// Sets the application tags. | ||
pub fn tags(mut self, tags: Vec<String>) -> Self { | ||
self.tags = Some(tags); | ||
self | ||
} | ||
|
||
/// Sets the event webhooks URL. | ||
pub fn webhooks_url(mut self, url: impl Into<Cow<'a, str>>) -> Self { | ||
self.event_webhooks_url = Some(url.into()); | ||
self | ||
} | ||
|
||
/// Sets the event webhook status. | ||
pub fn webhook_status(mut self, status: EventWebhookStatus) -> Self { | ||
self.event_webhook_status = Some(status); | ||
self | ||
} | ||
|
||
/// Sets the event webhook types. | ||
pub fn webhook_types(mut self, types: Vec<EventWebhookType>) -> Self { | ||
self.event_webhook_types = Some(types); | ||
self | ||
} | ||
|
||
/// Executes the builder, sending the configured application data to Discord. | ||
/// Returns updated [`CurrentApplicationInfo`] on success. | ||
/// | ||
/// # Errors | ||
/// | ||
/// Returns an error if the HTTP request fails or if the Discord API | ||
/// rejects the updated information. | ||
#[cfg(feature = "http")] | ||
pub async fn execute(self, http: &Http) -> Result<CurrentApplicationInfo> { | ||
http.edit_current_application_info(&self).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters