spectacles_model/message/
webhook.rs1use crate::{Snowflake, User};
2use crate::message::embed::Embed;
3
4#[derive(Deserialize, Serialize, Clone, Debug, Default)]
6pub struct Webhook {
7 pub id: Snowflake,
9 #[serde(default)]
11 pub guild_id: Option<String>,
12 pub channel_id: Snowflake,
14 #[serde(default)]
16 pub user: Option<User>,
17 pub name: Option<String>,
19 pub avatar: Option<String>,
21 pub token: String
23}
24
25#[derive(Serialize, Clone, Debug, Default)]
26pub struct ModifyWebhookOptions {
27 #[serde(skip_serializing_if = "Option::is_none")]
28 name: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 avatar: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 channel_id: Option<Snowflake>,
33}
34
35impl ModifyWebhookOptions {
36 pub fn name(mut self, name: &str) -> Self {
38 self.name = Some(name.to_string());
39 self
40 }
41
42 pub fn avatar(mut self, url: &str) -> Self {
45 self.avatar = Some(url.to_string());
46 self
47 }
48
49 pub fn channel_id(mut self, id: Snowflake) -> Self {
51 self.channel_id = Some(id);
52 self
53 }
54}
55
56#[derive(Serialize, Debug, Default)]
57pub struct ExecuteWebhookOptions {
58 #[serde(skip_serializing_if = "Option::is_none")]
59 content: Option<String>,
60 #[serde(skip_serializing_if = "Option::is_none")]
61 username: Option<String>,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 avatar_url: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 tts: Option<bool>,
66 #[serde(skip_serializing)]
67 pub file: Option<(String, Vec<u8>)>,
68 embeds: Vec<Embed>,
69}
70
71impl ExecuteWebhookOptions {
72 pub fn content(mut self, text: &str) -> Self {
74 self.content = Some(text.to_string());
75 self
76 }
77
78 pub fn username(mut self, name: &str) -> Self {
80 self.username = Some(name.to_string());
81 self
82 }
83
84 pub fn avatar_url(mut self, url: &str) -> Self {
86 self.avatar_url = Some(url.to_string());
87 self
88 }
89
90 pub fn tts(mut self, opt: bool) -> Self {
92 self.tts = Some(opt);
93 self
94 }
95
96 pub fn file(mut self, name: &str, file: Vec<u8>) -> Self {
98 self.file = Some((name.to_string(), file));
99 self
100 }
101
102
103 pub fn embed(mut self, embe: Embed) -> Self {
105 self.embeds.push(embe);
106 self
107 }
108}