revolt_models/v0/
channel_webhooks.rs

1#[cfg(feature = "validator")]
2use validator::Validate;
3
4use super::File;
5
6auto_derived_partial!(
7    /// Webhook
8    pub struct Webhook {
9        /// Webhook Id
10        pub id: String,
11
12        /// The name of the webhook
13        pub name: String,
14
15        /// The avatar of the webhook
16        #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
17        pub avatar: Option<File>,
18
19        /// User that created this webhook
20        pub creator_id: String,
21
22        /// The channel this webhook belongs to
23        pub channel_id: String,
24
25        /// The permissions for the webhook
26        pub permissions: u64,
27
28        /// The private token for the webhook
29        pub token: Option<String>,
30    },
31    "PartialWebhook"
32);
33
34auto_derived!(
35    /// Information about the webhook bundled with Message
36    pub struct MessageWebhook {
37        // The name of the webhook - 1 to 32 chars
38        pub name: String,
39
40        // The id of the avatar of the webhook, if it has one
41        pub avatar: Option<String>,
42    }
43
44    /// New webhook information
45    #[cfg_attr(feature = "validator", derive(validator::Validate))]
46    pub struct DataEditWebhook {
47        /// Webhook name
48        #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
49        pub name: Option<String>,
50
51        /// Avatar ID
52        #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
53        pub avatar: Option<String>,
54
55        /// Webhook permissions
56        pub permissions: Option<u64>,
57
58        /// Fields to remove from webhook
59        #[cfg_attr(feature = "serde", serde(default))]
60        pub remove: Vec<FieldsWebhook>,
61    }
62
63    /// Webhook information
64    pub struct ResponseWebhook {
65        /// Webhook Id
66        pub id: String,
67
68        /// Webhook name
69        pub name: String,
70
71        /// Avatar ID
72        pub avatar: Option<String>,
73
74        /// The channel this webhook belongs to
75        pub channel_id: String,
76
77        /// The permissions for the webhook
78        pub permissions: u64,
79    }
80
81    /// Optional fields on webhook object
82    pub enum FieldsWebhook {
83        Avatar,
84    }
85
86    /// Information for the webhook
87    #[cfg_attr(feature = "validator", derive(Validate))]
88    pub struct CreateWebhookBody {
89        #[validate(length(min = 1, max = 32))]
90        pub name: String,
91
92        #[validate(length(min = 1, max = 128))]
93        pub avatar: Option<String>,
94    }
95);
96
97impl From<Webhook> for MessageWebhook {
98    fn from(value: Webhook) -> Self {
99        MessageWebhook {
100            name: value.name,
101            avatar: value.avatar.map(|file| file.id),
102        }
103    }
104}
105
106impl From<Webhook> for ResponseWebhook {
107    fn from(value: Webhook) -> Self {
108        ResponseWebhook {
109            id: value.id,
110            name: value.name,
111            avatar: value.avatar.map(|file| file.id),
112            channel_id: value.channel_id,
113            permissions: value.permissions,
114        }
115    }
116}