titanium_model/
message.rs

1use crate::channel::{Channel, ChannelMention};
2use crate::component::Component;
3use crate::member::GuildMember;
4use crate::poll;
5use crate::snowflake::Snowflake;
6use crate::user::User;
7use crate::TitanString;
8use serde::{Deserialize, Serialize};
9
10/// Discord Message representation.
11#[derive(Debug, Clone, Deserialize, Serialize)]
12pub struct Message<'a> {
13    /// Message ID.
14    pub id: Snowflake,
15    /// Channel ID.
16    pub channel_id: Snowflake,
17    /// Author of the message.
18    pub author: User<'a>,
19    /// Message content.
20    pub content: TitanString<'a>,
21    /// When the message was sent (ISO8601 timestamp).
22    pub timestamp: TitanString<'a>,
23    /// When the message was edited (ISO8601 timestamp).
24    #[serde(default)]
25    pub edited_timestamp: Option<String>,
26    /// Whether this was a TTS message.
27    #[serde(default)]
28    pub tts: bool,
29    /// Whether this message mentions everyone.
30    #[serde(default)]
31    pub mention_everyone: bool,
32    /// Users mentioned in this message.
33    #[serde(default)]
34    pub mentions: smallvec::SmallVec<[User<'a>; 4]>,
35    /// Roles mentioned in this message.
36    #[serde(default)]
37    pub mention_roles: smallvec::SmallVec<[Snowflake; 4]>,
38    /// Channels mentioned in this message.
39    #[serde(default)]
40    pub mention_channels: smallvec::SmallVec<[ChannelMention; 2]>,
41    /// Attachments.
42    #[serde(default)]
43    pub attachments: smallvec::SmallVec<[Attachment<'a>; 4]>,
44    /// Embeds.
45    #[serde(default)]
46    pub embeds: smallvec::SmallVec<[Embed<'a>; 10]>,
47    /// Reactions.
48    #[serde(default)]
49    pub reactions: smallvec::SmallVec<[Reaction<'a>; 5]>,
50    /// Used for validating a message was sent.
51    #[serde(default)]
52    pub nonce: Option<crate::json::Value>,
53    /// Whether message is pinned.
54    #[serde(default)]
55    pub pinned: bool,
56    /// Webhook ID if sent by webhook.
57    #[serde(default)]
58    pub webhook_id: Option<Snowflake>,
59    /// Message type.
60    #[serde(rename = "type")]
61    pub message_type: u8,
62    /// Guild ID.
63    #[serde(default)]
64    pub guild_id: Option<Snowflake>,
65    /// Member properties for this message's author.
66    #[serde(default)]
67    pub member: Option<GuildMember<'a>>,
68    /// Message flags.
69    #[serde(default)]
70    pub flags: Option<u64>,
71    /// Reference data for replies/forwards.
72    #[serde(default)]
73    pub message_reference: Option<MessageReference>,
74    /// The message associated with the reference.
75    #[serde(default)]
76    pub referenced_message: Option<Box<Message<'a>>>,
77    /// Thread started from this message.
78    #[serde(default)]
79    pub thread: Option<Channel<'a>>,
80    /// Components (buttons, selects, etc.).
81    #[serde(default)]
82    pub components: smallvec::SmallVec<[Component<'a>; 5]>,
83    /// Sticker items.
84    #[serde(default)]
85    pub sticker_items: smallvec::SmallVec<[StickerItem; 3]>,
86    /// Poll object.
87    #[serde(default)]
88    pub poll: Option<poll::Poll<'a>>,
89}
90
91/// An attachment on a message.
92#[derive(Debug, Clone, Deserialize, Serialize)]
93pub struct Attachment<'a> {
94    /// Attachment ID.
95    pub id: Snowflake,
96    /// Filename.
97    pub filename: TitanString<'a>,
98    /// Description.
99    #[serde(default)]
100    pub description: Option<TitanString<'a>>,
101    /// Media type.
102    #[serde(default)]
103    pub content_type: Option<String>,
104    /// Size in bytes.
105    pub size: u64,
106    /// Source URL.
107    pub url: TitanString<'a>,
108    /// Proxy URL.
109    pub proxy_url: TitanString<'a>,
110    /// Height (if image).
111    #[serde(default)]
112    pub height: Option<u32>,
113    /// Width (if image).
114    #[serde(default)]
115    pub width: Option<u32>,
116    /// Whether ephemeral.
117    #[serde(default)]
118    pub ephemeral: bool,
119    /// Duration in seconds (for voice messages).
120    #[serde(default)]
121    pub duration_secs: Option<f64>,
122    /// Waveform base64 (for voice messages).
123    #[serde(default)]
124    pub waveform: Option<String>,
125    /// Attachment flags.
126    #[serde(default)]
127    pub flags: Option<u64>,
128}
129
130/// An embed in a message.
131#[derive(Debug, Clone, Default, Deserialize, Serialize)]
132pub struct Embed<'a> {
133    /// Title.
134    #[serde(default)]
135    pub title: Option<TitanString<'a>>,
136    /// Type.
137    #[serde(default, rename = "type")]
138    pub embed_type: Option<TitanString<'a>>,
139    /// Description.
140    #[serde(default)]
141    pub description: Option<TitanString<'a>>,
142    /// URL.
143    #[serde(default)]
144    pub url: Option<TitanString<'a>>,
145    /// Timestamp.
146    #[serde(default)]
147    pub timestamp: Option<TitanString<'a>>,
148    /// Color.
149    #[serde(default)]
150    pub color: Option<u32>,
151    /// Footer.
152    #[serde(default)]
153    pub footer: Option<EmbedFooter<'a>>,
154    /// Image.
155    #[serde(default)]
156    pub image: Option<EmbedMedia<'a>>,
157    /// Thumbnail.
158    #[serde(default)]
159    pub thumbnail: Option<EmbedMedia<'a>>,
160    /// Video.
161    #[serde(default)]
162    pub video: Option<EmbedMedia<'a>>,
163    /// Provider.
164    #[serde(default)]
165    pub provider: Option<EmbedProvider<'a>>,
166    /// Author.
167    #[serde(default)]
168    pub author: Option<EmbedAuthor<'a>>,
169    /// Fields.
170    #[serde(default)]
171    pub fields: Vec<EmbedField<'a>>,
172}
173
174/// Embed footer.
175#[derive(Debug, Clone, Deserialize, Serialize)]
176pub struct EmbedFooter<'a> {
177    /// Footer text.
178    pub text: TitanString<'a>,
179    /// Icon URL.
180    #[serde(default)]
181    pub icon_url: Option<TitanString<'a>>,
182    /// Proxy icon URL.
183    #[serde(default)]
184    pub proxy_icon_url: Option<TitanString<'a>>,
185}
186
187/// Embed media (image, thumbnail, video).
188#[derive(Debug, Clone, Deserialize, Serialize)]
189pub struct EmbedMedia<'a> {
190    /// URL.
191    #[serde(default)]
192    pub url: Option<TitanString<'a>>,
193    /// Proxy URL.
194    #[serde(default)]
195    pub proxy_url: Option<TitanString<'a>>,
196    /// Height.
197    #[serde(default)]
198    pub height: Option<u32>,
199    /// Width.
200    #[serde(default)]
201    pub width: Option<u32>,
202}
203
204/// Embed provider.
205#[derive(Debug, Clone, Deserialize, Serialize)]
206pub struct EmbedProvider<'a> {
207    /// Provider name.
208    #[serde(default)]
209    pub name: Option<TitanString<'a>>,
210    /// Provider URL.
211    #[serde(default)]
212    pub url: Option<TitanString<'a>>,
213}
214
215/// Embed author.
216#[derive(Debug, Clone, Deserialize, Serialize)]
217pub struct EmbedAuthor<'a> {
218    /// Author name.
219    pub name: TitanString<'a>,
220    /// Author URL.
221    #[serde(default)]
222    pub url: Option<TitanString<'a>>,
223    /// Icon URL.
224    #[serde(default)]
225    pub icon_url: Option<TitanString<'a>>,
226    /// Proxy icon URL.
227    #[serde(default)]
228    pub proxy_icon_url: Option<TitanString<'a>>,
229}
230
231/// Embed field.
232#[derive(Debug, Clone, Deserialize, Serialize)]
233pub struct EmbedField<'a> {
234    /// Field name.
235    pub name: TitanString<'a>,
236    /// Field value.
237    pub value: TitanString<'a>,
238    /// Whether inline.
239    #[serde(default)]
240    pub inline: bool,
241}
242
243/// A reaction on a message.
244#[derive(Debug, Clone, Deserialize, Serialize)]
245pub struct Reaction<'a> {
246    /// Times this emoji has been used.
247    pub count: u32,
248    /// Reaction count details.
249    #[serde(default)]
250    pub count_details: Option<ReactionCountDetails>,
251    /// Whether current user reacted.
252    pub me: bool,
253    /// Whether current user super-reacted.
254    #[serde(default)]
255    pub me_burst: bool,
256    /// Emoji information.
257    pub emoji: crate::reaction::ReactionEmoji<'a>,
258    /// Colors for super-reaction.
259    #[serde(default)]
260    pub burst_colors: Vec<String>,
261}
262
263/// Reaction count details.
264#[derive(Debug, Clone, Deserialize, Serialize)]
265pub struct ReactionCountDetails {
266    /// Count of normal reactions.
267    pub burst: u32,
268    /// Count of super reactions.
269    pub normal: u32,
270}
271
272/// Message reference for replies/forwards.
273#[derive(Debug, Clone, Deserialize, Serialize)]
274pub struct MessageReference {
275    /// ID of the originating message.
276    #[serde(default)]
277    pub message_id: Option<Snowflake>,
278    /// ID of the originating channel.
279    #[serde(default)]
280    pub channel_id: Option<Snowflake>,
281    /// ID of the originating guild.
282    #[serde(default)]
283    pub guild_id: Option<Snowflake>,
284    /// Whether to fail if referenced message doesn't exist.
285    #[serde(default)]
286    pub fail_if_not_exists: Option<bool>,
287}
288
289/// A sticker item (partial sticker).
290#[derive(Debug, Clone, Deserialize, Serialize)]
291pub struct StickerItem {
292    /// Sticker ID.
293    pub id: Snowflake,
294    /// Sticker name.
295    pub name: String,
296    /// Sticker format type.
297    pub format_type: u8,
298}
299
300/// Message update event (partial message).
301#[derive(Debug, Clone, Deserialize, Serialize)]
302pub struct MessageUpdateEvent<'a> {
303    pub id: Snowflake,
304    pub channel_id: Snowflake,
305    #[serde(default)]
306    pub guild_id: Option<Snowflake>,
307    #[serde(default)]
308    pub content: Option<String>,
309    #[serde(default)]
310    pub author: Option<User<'a>>,
311    #[serde(default)]
312    pub edited_timestamp: Option<String>,
313}
314
315/// Message delete event.
316#[derive(Debug, Clone, Deserialize, Serialize)]
317pub struct MessageDeleteEvent {
318    pub id: Snowflake,
319    pub channel_id: Snowflake,
320    #[serde(default)]
321    pub guild_id: Option<Snowflake>,
322}
323
324/// Bulk message delete event.
325#[derive(Debug, Clone, Deserialize, Serialize)]
326pub struct MessageDeleteBulkEvent {
327    pub ids: Vec<Snowflake>,
328    pub channel_id: Snowflake,
329    #[serde(default)]
330    pub guild_id: Option<Snowflake>,
331}
332
333/// Typing start event.
334#[derive(Debug, Clone, Deserialize, Serialize)]
335pub struct TypingStartEvent<'a> {
336    pub channel_id: Snowflake,
337    #[serde(default)]
338    pub guild_id: Option<Snowflake>,
339    pub user_id: Snowflake,
340    pub timestamp: u64,
341    #[serde(default)]
342    pub member: Option<GuildMember<'a>>,
343}