Skip to content

Commit

Permalink
Add additional avatar/icon/image methods for better feature coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Jun 27, 2022
1 parent e15f845 commit be3f947
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/builder/create_scheduled_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl CreateScheduledEvent {
///
/// # Errors
///
/// May error if the icon is a URL and the HTTP request fails, or if the image is a file
/// on a path that doesn't exist.
/// May error if a URL is given and the HTTP request fails, or if a path is given to a file
/// that does not exist.
#[cfg(feature = "http")]
pub async fn image<'a>(
mut self,
Expand All @@ -133,6 +133,14 @@ impl CreateScheduledEvent {
Ok(self)
}

/// Sets the cover image for the scheduled event. Requires the input be a base64-encoded image
/// that is in either JPG, GIF, or PNG format.
#[cfg(not(feature = "http"))]
pub fn image(mut self, image: String) -> Self {
self.image = Some(image);
self
}

/// Creates a new scheduled event in the guild with the data set, if any.
///
/// **Note**: Requres the [Manage Events] permission.
Expand Down
20 changes: 20 additions & 0 deletions src/builder/create_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::http::{CacheHttp, Http};
use crate::internal::prelude::*;
#[cfg(feature = "http")]
use crate::model::prelude::*;
#[cfg(feature = "http")]
use crate::utils::encode_image;

#[derive(Clone, Debug, Serialize)]
pub struct CreateWebhook {
Expand Down Expand Up @@ -34,8 +36,26 @@ impl CreateWebhook {
self
}

/// Set the webhook's default avatar.
///
/// # Errors
///
/// May error if a URL is given and the HTTP request fails, or if a path is given to a file
/// that does not exist.
#[cfg(feature = "http")]
pub async fn avatar<'a>(
mut self,
http: impl AsRef<Http>,
avatar: impl Into<AttachmentType<'a>>,
) -> Result<Self> {
let avatar_data = avatar.into().data(&http.as_ref().client).await?;
self.avatar = Some(encode_image(&avatar_data));
Ok(self)
}

/// Set the webhook's default avatar. Requires the input be a base64-encoded image that is in
/// either JPG, GIF, or PNG format.
#[cfg(not(feature = "http"))]
pub fn avatar(mut self, avatar: String) -> Self {
self.avatar = Some(avatar);
self
Expand Down
13 changes: 11 additions & 2 deletions src/builder/edit_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ impl EditRole {
///
/// # Errors
///
/// May error if the icon is a URL and the HTTP request fails, or if the icon is a file
/// on a path that doesn't exist.
/// May error if a URL is given and the HTTP request fails, or if a path is given to a file
/// that does not exist.
#[cfg(feature = "model")]
pub async fn icon<'a>(
&mut self,
Expand All @@ -159,4 +159,13 @@ impl EditRole {

Ok(self)
}

/// The image to set as the role icon. Requires the input be a base64-encoded image that is in
/// either JPG, GIF, or PNG format.
#[cfg(not(feature = "model"))]
pub fn icon(&mut self, icon: String) -> &mut Self {
self.icon = Some(icon);
self.unicode_emoji = None;
self
}
}
12 changes: 10 additions & 2 deletions src/builder/edit_scheduled_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl EditScheduledEvent {
///
/// # Errors
///
/// May error if the icon is a URL and the HTTP request fails, or if the image is a file
/// on a path that doesn't exist.
/// May error if a URL is given and the HTTP request fails, or if a path is given to a file
/// that does not exist.
#[cfg(feature = "model")]
pub async fn image<'a>(
&mut self,
Expand All @@ -153,4 +153,12 @@ impl EditScheduledEvent {
self.image = Some(encode_image(&image_data));
Ok(self)
}

/// Sets the cover image for the scheduled event. Requires the input be a base64-encoded image
/// that is in either JPG, GIF, or PNG format.
#[cfg(not(feature = "model"))]
pub fn image(&mut self, image: String) -> &mut Self {
self.image = Some(image);
self
}
}
18 changes: 18 additions & 0 deletions src/builder/edit_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,26 @@ impl<'a> EditWebhook<'a> {
self
}

/// Set the webhook's default avatar.
///
/// # Errors
///
/// May error if a URL is given and the HTTP request fails, or if a path is given to a file
/// that does not exist.
#[cfg(featuer = "http")]
pub async fn avatar(
mut self,
http: impl AsRef<Http>,
avatar: impl Into<AttachmentType<'a>>,
) -> Result<Self> {
let avatar_data = avatar.into().data(&http.as_ref().client).await?;
self.avatar = Some(Some(encode_image(&avatar_data)));
Ok(self)
}

/// Set the webhook's default avatar. Requires the input be a base64-encoded image that is in
/// either JPG, GIF, or PNG format.
#[cfg(not(feature = "http"))]
pub fn avatar(mut self, avatar: String) -> Self {
self.avatar = Some(Some(avatar));
self
Expand Down

0 comments on commit be3f947

Please sign in to comment.