titanium_model/
integration.rs1use crate::Snowflake;
6use crate::TitanString;
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct Integration<'a> {
12 pub id: Snowflake,
14
15 pub name: String,
17
18 #[serde(rename = "type")]
20 pub integration_type: String,
21
22 #[serde(default)]
24 pub enabled: bool,
25
26 #[serde(default)]
28 pub syncing: Option<bool>,
29
30 #[serde(default)]
32 pub role_id: Option<Snowflake>,
33
34 #[serde(default)]
36 pub enable_emoticons: Option<bool>,
37
38 #[serde(default)]
40 pub expire_behavior: Option<u8>,
41
42 #[serde(default)]
44 pub expire_grace_period: Option<u32>,
45
46 #[serde(default)]
48 pub user: Option<super::User<'a>>,
49
50 #[serde(default)]
52 pub account: Option<IntegrationAccount>,
53
54 #[serde(default)]
56 pub synced_at: Option<String>,
57
58 #[serde(default)]
60 pub subscriber_count: Option<u32>,
61
62 #[serde(default)]
64 pub revoked: Option<bool>,
65
66 #[serde(default)]
68 pub application: Option<IntegrationApplication<'a>>,
69
70 #[serde(default)]
72 pub scopes: Vec<String>,
73}
74
75#[derive(Debug, Clone, Deserialize, Serialize)]
77pub struct IntegrationAccount {
78 pub id: String,
80
81 pub name: String,
83}
84
85#[derive(Debug, Clone, Deserialize, Serialize)]
87pub struct IntegrationApplication<'a> {
88 pub id: Snowflake,
90
91 pub name: String,
93
94 #[serde(default)]
96 pub icon: Option<String>,
97
98 pub description: String,
100
101 #[serde(default)]
103 pub bot: Option<super::User<'a>>,
104}
105
106#[derive(Debug, Clone, Deserialize, Serialize)]
108pub struct IntegrationDeleteEvent {
109 pub id: Snowflake,
111
112 pub guild_id: Snowflake,
114
115 #[serde(default)]
117 pub application_id: Option<Snowflake>,
118}
119
120#[derive(Debug, Clone, Deserialize, Serialize)]
122pub struct GuildIntegrationsUpdateEvent {
123 pub guild_id: Snowflake,
125}
126
127#[derive(Debug, Clone, Deserialize, Serialize)]
129pub struct Webhook<'a> {
130 pub id: Snowflake,
132
133 #[serde(rename = "type")]
135 pub webhook_type: u8,
136
137 #[serde(default)]
139 pub guild_id: Option<Snowflake>,
140
141 #[serde(default)]
143 pub channel_id: Option<Snowflake>,
144
145 #[serde(default)]
147 pub user: Option<super::User<'a>>,
148
149 #[serde(default)]
151 pub name: Option<TitanString<'a>>,
152
153 #[serde(default)]
155 pub avatar: Option<TitanString<'a>>,
156
157 #[serde(default)]
159 pub token: Option<TitanString<'a>>,
160
161 #[serde(default)]
163 pub application_id: Option<Snowflake>,
164
165 #[serde(default)]
167 pub source_guild: Option<WebhookSourceGuild>,
168
169 #[serde(default)]
171 pub source_channel: Option<WebhookSourceChannel>,
172
173 #[serde(default)]
175 pub url: Option<TitanString<'a>>,
176}
177
178#[derive(Debug, Clone, Deserialize, Serialize)]
180pub struct WebhookSourceGuild {
181 pub id: Snowflake,
183
184 pub name: String,
186
187 #[serde(default)]
189 pub icon: Option<String>,
190}
191
192#[derive(Debug, Clone, Deserialize, Serialize)]
194pub struct WebhookSourceChannel {
195 pub id: Snowflake,
197
198 pub name: String,
200}
201
202#[derive(Debug, Clone, Deserialize, Serialize)]
204pub struct WebhooksUpdateEvent {
205 pub guild_id: Snowflake,
207
208 pub channel_id: Snowflake,
210}
211
212#[cfg(test)]
213mod tests {
214 use super::*;
215
216 #[test]
217 fn test_integration() {
218 let json = r#"{
219 "id": "123",
220 "name": "Test Bot",
221 "type": "discord",
222 "enabled": true
223 }"#;
224
225 let integration: Integration = crate::json::from_str(json).unwrap();
226 assert_eq!(integration.name, "Test Bot");
227 assert_eq!(integration.integration_type, "discord");
228 }
229
230 #[test]
231 fn test_webhook() {
232 let json = r#"{
233 "id": "123",
234 "type": 1,
235 "guild_id": "456",
236 "channel_id": "789",
237 "name": "Test Webhook"
238 }"#;
239
240 let _webhook: Webhook = crate::json::from_str(json).unwrap();
241 let webhook: Webhook = crate::json::from_str(json).unwrap();
242 assert_eq!(webhook.name, Some(TitanString::Borrowed("Test Webhook")));
243 }
244}