#[cfg(feature = "http")]
use super::Builder;
use super::CreateAttachment;
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;
#[derive(Debug, Default, Clone, Serialize)]
#[must_use]
pub struct EditWebhook<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
avatar: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
channel_id: Option<ChannelId>,
#[serde(skip)]
audit_log_reason: Option<&'a str>,
}
impl<'a> EditWebhook<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn channel_id(mut self, channel_id: impl Into<ChannelId>) -> Self {
self.channel_id = Some(channel_id.into());
self
}
pub fn avatar(mut self, avatar: &CreateAttachment) -> Self {
self.avatar = Some(Some(avatar.to_base64()));
self
}
pub fn delete_avatar(mut self) -> Self {
self.avatar = Some(None);
self
}
pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
self.audit_log_reason = Some(reason);
self
}
}
#[cfg(feature = "http")]
#[async_trait::async_trait]
impl Builder for EditWebhook<'_> {
type Context<'ctx> = (WebhookId, Option<&'ctx str>);
type Built = Webhook;
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
match ctx.1 {
Some(token) => {
cache_http
.http()
.edit_webhook_with_token(ctx.0, token, &self, self.audit_log_reason)
.await
},
None => cache_http.http().edit_webhook(ctx.0, &self, self.audit_log_reason).await,
}
}
}