use crate::{Snowflake, User};
use crate::message::embed::Embed;
#[derive(Deserialize, Serialize, Clone, Debug, Default)]
pub struct Webhook {
pub id: Snowflake,
#[serde(default)]
pub guild_id: Option<String>,
pub channel_id: Snowflake,
#[serde(default)]
pub user: Option<User>,
pub name: Option<String>,
pub avatar: Option<String>,
pub token: String
}
#[derive(Serialize, Clone, Debug, Default)]
pub struct ModifyWebhookOptions {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
avatar: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
channel_id: Option<Snowflake>,
}
impl ModifyWebhookOptions {
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn avatar(mut self, url: &str) -> Self {
self.avatar = Some(url.to_string());
self
}
pub fn channel_id(mut self, id: Snowflake) -> Self {
self.channel_id = Some(id);
self
}
}
#[derive(Serialize, Debug, Default)]
pub struct ExecuteWebhookOptions {
#[serde(skip_serializing_if = "Option::is_none")]
content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
avatar_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tts: Option<bool>,
#[serde(skip_serializing)]
pub file: Option<(String, Vec<u8>)>,
embeds: Vec<Embed>,
}
impl ExecuteWebhookOptions {
pub fn content(mut self, text: &str) -> Self {
self.content = Some(text.to_string());
self
}
pub fn username(mut self, name: &str) -> Self {
self.username = Some(name.to_string());
self
}
pub fn avatar_url(mut self, url: &str) -> Self {
self.avatar_url = Some(url.to_string());
self
}
pub fn tts(mut self, opt: bool) -> Self {
self.tts = Some(opt);
self
}
pub fn file(mut self, name: &str, file: Vec<u8>) -> Self {
self.file = Some((name.to_string(), file));
self
}
pub fn embed(mut self, embe: Embed) -> Self {
self.embeds.push(embe);
self
}
}