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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use serde::Serialize;
use twilight_model::{
channel::{
embed::Embed,
message::{
sticker::MessageSticker, Message, MessageActivity, MessageApplication, MessageFlags,
MessageReaction, MessageReference, MessageType,
},
Attachment, ChannelMention,
},
datetime::Timestamp,
guild::PartialMember,
id::{ChannelId, GuildId, MessageId, RoleId, UserId, WebhookId},
};
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct CachedMessage {
activity: Option<MessageActivity>,
application: Option<MessageApplication>,
pub(crate) attachments: Vec<Attachment>,
author: UserId,
channel_id: ChannelId,
pub(crate) content: String,
pub(crate) edited_timestamp: Option<Timestamp>,
pub(crate) embeds: Vec<Embed>,
flags: Option<MessageFlags>,
guild_id: Option<GuildId>,
id: MessageId,
kind: MessageType,
member: Option<PartialMember>,
mention_channels: Vec<ChannelMention>,
pub(crate) mention_everyone: bool,
pub(crate) mention_roles: Vec<RoleId>,
pub(crate) mentions: Vec<UserId>,
pub(crate) pinned: bool,
pub(crate) reactions: Vec<MessageReaction>,
reference: Option<MessageReference>,
sticker_items: Vec<MessageSticker>,
pub(crate) timestamp: Timestamp,
pub(crate) tts: bool,
webhook_id: Option<WebhookId>,
}
impl CachedMessage {
pub const fn activity(&self) -> Option<&MessageActivity> {
self.activity.as_ref()
}
pub const fn application(&self) -> Option<&MessageApplication> {
self.application.as_ref()
}
pub fn attachments(&self) -> &[Attachment] {
&self.attachments
}
pub const fn author(&self) -> UserId {
self.author
}
pub const fn channel_id(&self) -> ChannelId {
self.channel_id
}
pub fn content(&self) -> &str {
&self.content
}
pub const fn edited_timestamp(&self) -> Option<Timestamp> {
self.edited_timestamp
}
pub fn embeds(&self) -> &[Embed] {
&self.embeds
}
pub const fn flags(&self) -> Option<MessageFlags> {
self.flags
}
pub const fn guild_id(&self) -> Option<GuildId> {
self.guild_id
}
pub const fn id(&self) -> MessageId {
self.id
}
pub const fn kind(&self) -> MessageType {
self.kind
}
pub const fn member(&self) -> Option<&PartialMember> {
self.member.as_ref()
}
pub fn mention_channels(&self) -> &[ChannelMention] {
&self.mention_channels
}
pub const fn mention_everyone(&self) -> bool {
self.mention_everyone
}
pub fn mention_roles(&self) -> &[RoleId] {
&self.mention_roles
}
pub fn mentions(&self) -> &[UserId] {
&self.mentions
}
pub const fn pinned(&self) -> bool {
self.pinned
}
pub fn reactions(&self) -> &[MessageReaction] {
&self.reactions
}
pub const fn reference(&self) -> Option<&MessageReference> {
self.reference.as_ref()
}
pub fn sticker_items(&self) -> &[MessageSticker] {
&self.sticker_items
}
pub const fn timestamp(&self) -> Timestamp {
self.timestamp
}
pub const fn tts(&self) -> bool {
self.tts
}
pub const fn webhook_id(&self) -> Option<WebhookId> {
self.webhook_id
}
}
impl From<Message> for CachedMessage {
fn from(msg: Message) -> Self {
Self {
id: msg.id,
activity: msg.activity,
application: msg.application,
attachments: msg.attachments,
author: msg.author.id,
channel_id: msg.channel_id,
content: msg.content,
edited_timestamp: msg.edited_timestamp,
embeds: msg.embeds,
flags: msg.flags,
guild_id: msg.guild_id,
kind: msg.kind,
member: msg.member,
mention_channels: msg.mention_channels,
mention_everyone: msg.mention_everyone,
mention_roles: msg.mention_roles,
mentions: msg.mentions.iter().map(|mention| mention.id).collect(),
pinned: msg.pinned,
reactions: msg.reactions,
reference: msg.reference,
sticker_items: msg.sticker_items,
timestamp: msg.timestamp,
tts: msg.tts,
webhook_id: msg.webhook_id,
}
}
}