1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use crate::{
error::Result,
http::HttpClient,
models::{guild::GuildMember, user::User},
};
use super::{Embed, MentionChannel, MessageReference, Attachment, Reaction, MessageApplication};
use serde::{Deserialize, Serialize};
use serde_repr::*;
#[derive(Debug, Deserialize, Serialize)]
/// Represents a message sent in a channel within Discord.
/// [Discord Documentation](https://discord.com/developers/docs/resources/channel#message-object)
pub struct Message {
/// ID of the message
pub id: String,
/// ID of the channel the message was sent in
pub channel_id: String,
/// ID of the guild the message was sent in case it was sent in one
pub guild_id: Option<String>,
/// Author of the message
pub author: User,
/// Member properties for this message's author in case it was sent in a guild
pub member: Option<GuildMember>,
/// Contents of the message
pub content: String,
/// When this message was sent, as string
pub timestamp: String,
/// When this message was edited (or `None` if never)
pub edited_timestamp: Option<String>,
/// Whether this was a TTS message
pub tts: bool,
/// Whether this message mentions everyone
pub mention_everyone: bool,
/// Users specifically mentioned in the message
pub mentions: Vec<User>,
/// Roles specifically mentioned in this message
pub mention_roles: Vec<String>,
/// Channels specifically mentioned in this message
#[serde(default)]
pub mentions_channels: Vec<MentionChannel>,
/// Any attached files
pub attachments: Vec<Attachment>,
/// Any embedded content
#[serde(default)]
pub embed: Vec<Embed>,
/// Reactions to the message
#[serde(default)]
pub reactions: Vec<Reaction>,
/// Used for validating a message was sent
pub nonce: Option<String>,
/// Whether this message is pinned
pub pinned: bool,
/// If the message is generated by a webhook, this is the webhook's id
pub webhook_id: Option<String>,
/// Type of message
#[serde(rename = "type")]
pub kind: Option<MessageKind>,
// activity: MessageActivity,
/// Sent with Rich Presence-related chat embeds
pub application: Option<MessageApplication>,
/// Reference data sent with crossposted messages
pub message_reference: Option<MessageReference>,
/// Message flags ORd together, describes extra features of the message
pub flags: Option<u64>,
}
#[derive(Debug, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum MessageKind {
Regular = 0,
RecipientAdd = 1,
RecipientRemove = 2,
Call = 3,
ChannelNameChange = 4,
ChannelIconChange = 5,
ChannelPinnedMessage = 6,
GuildMemberJoin = 7,
UserPremiumGuildSub = 8,
UserPremiumGuildSubT1 = 9,
UserPremiumGuildSubT2 = 10,
UserPremiumGuildSubT3 = 11,
ChannelFollowAdd = 12,
GuildDiscoveryDisqualified = 14,
GuildDiscoveryRequalified = 15
}
impl Message {
/// Shortcut for [`HttpClient.send_message`]
///
/// [`HttpClient.send_message`]: ../../../struct.HttpClient.html#method.send_message
pub async fn send(&self, http: &HttpClient, content: impl AsRef<str>) -> Result<Message> {
http.send_message(&self.channel_id, content).await
}
/// Shortcut for [`HttpClient.send_embed`]
///
/// [`HttpClient.send_embed`]: ../../../struct.HttpClient.html#method.send_embed
pub async fn send_embed(&self, http: &HttpClient, embed: super::Embed) -> Result<Message> {
http.send_embed(&self.channel_id, embed).await
}
/// Shortcut for [`HttpClient.add_reaction`]
///
/// [`HttpClient.add_reaction`]: ../../../struct.HttpClient.html#method.add_reaction
pub async fn add_reaction(&self, http: &HttpClient, emoji: impl AsRef<str>) -> Result<()> {
http.add_reaction(&self.channel_id, &self.id, emoji).await
}
/// Shortcut for [`HttpClient.delete_message`]
///
/// [`HttpClient.delete_message`]: ../../../struct.HttpClient.html#method.delete_message
pub async fn remove(&self, http: &HttpClient) -> Result<()> {
http.delete_message(&self.channel_id, &self.id).await
}
/// Shortcut for [`HttpClient.pin_message`]
///
/// [`HttpClient.pin_message`]: ../../../struct.HttpClient.html#method.pin_message
pub async fn pin(&self, http: &HttpClient) -> Result<()> {
http.pin_message(&self.channel_id, &self.id).await
}
/// Shortcut for [`HttpClient.unpin_message`]
///
/// [`HttpClient.unpin_message`]: ../../../struct.HttpClient.html#method.unpin_message
pub async fn unpin(&self, http: &HttpClient) -> Result<()> {
http.unpin_message(&self.channel_id, &self.id).await
}
}