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
use serde::Serialize;
use twilight_model::{
channel::message::{
sticker::{StickerFormatType, StickerId, StickerPackId, StickerType},
Sticker,
},
id::{GuildId, UserId},
};
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct CachedSticker {
pub(crate) available: bool,
pub(crate) description: String,
pub(crate) format_type: StickerFormatType,
pub(crate) guild_id: Option<GuildId>,
pub(crate) id: StickerId,
pub(crate) kind: StickerType,
pub(crate) name: String,
pub(crate) pack_id: Option<StickerPackId>,
pub(crate) sort_value: Option<u64>,
pub(crate) tags: String,
pub(crate) user_id: Option<UserId>,
}
impl CachedSticker {
pub const fn available(&self) -> bool {
self.available
}
pub fn description(&self) -> &str {
&self.description
}
pub const fn format_type(&self) -> StickerFormatType {
self.format_type
}
pub const fn guild_id(&self) -> Option<GuildId> {
self.guild_id
}
pub const fn id(&self) -> StickerId {
self.id
}
pub const fn kind(&self) -> StickerType {
self.kind
}
pub fn name(&self) -> &str {
&self.name
}
pub const fn pack_id(&self) -> Option<StickerPackId> {
self.pack_id
}
pub const fn sort_value(&self) -> Option<u64> {
self.sort_value
}
pub fn tags(&self) -> &str {
&self.tags
}
pub const fn user_id(&self) -> Option<UserId> {
self.user_id
}
}
impl PartialEq<Sticker> for CachedSticker {
fn eq(&self, other: &Sticker) -> bool {
self.available == other.available
&& self.description.as_str() == other.description.as_ref().map_or("", String::as_str)
&& self.format_type == other.format_type
&& self.guild_id == other.guild_id
&& self.id == other.id
&& self.kind == other.kind
&& self.name == other.name
&& self.pack_id == other.pack_id
&& self.sort_value == other.sort_value
&& self.tags == other.tags
&& self.user_id == other.user.as_ref().map(|user| user.id)
}
}
#[cfg(test)]
mod tests {
use super::CachedSticker;
use static_assertions::{assert_fields, assert_impl_all};
use std::fmt::Debug;
use twilight_model::{
channel::message::{
sticker::{StickerFormatType, StickerId, StickerPackId, StickerType},
Sticker,
},
id::{GuildId, UserId},
user::{PremiumType, User, UserFlags},
};
assert_fields!(
CachedSticker: available,
description,
format_type,
guild_id,
id,
kind,
name,
pack_id,
sort_value,
tags,
user_id
);
assert_impl_all!(CachedSticker: Clone, Debug, Eq, PartialEq);
#[test]
fn test_eq_sticker() {
let sticker = Sticker {
available: true,
description: Some("sticker".into()),
format_type: StickerFormatType::Png,
guild_id: Some(GuildId::new(1).expect("non zero")),
id: StickerId::new(2).expect("non zero"),
kind: StickerType::Guild,
name: "stick".into(),
pack_id: Some(StickerPackId::new(3).expect("non zero")),
sort_value: Some(1),
tags: "foo,bar,baz".into(),
user: Some(User {
accent_color: None,
avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()),
banner: None,
bot: false,
discriminator: 1,
email: Some("address@example.com".to_owned()),
flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER),
id: UserId::new(1).expect("non zero"),
locale: Some("en-us".to_owned()),
mfa_enabled: Some(true),
name: "test".to_owned(),
premium_type: Some(PremiumType::Nitro),
public_flags: Some(
UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER,
),
system: Some(true),
verified: Some(true),
}),
};
let cached = CachedSticker {
available: true,
description: "sticker".into(),
format_type: StickerFormatType::Png,
guild_id: Some(GuildId::new(1).expect("non zero")),
id: StickerId::new(2).expect("non zero"),
kind: StickerType::Guild,
name: "stick".into(),
pack_id: Some(StickerPackId::new(3).expect("non zero")),
sort_value: Some(1),
tags: "foo,bar,baz".into(),
user_id: Some(UserId::new(1).expect("non zero")),
};
assert_eq!(cached, sticker);
}
}