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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
/**
* Represents an embed in a message (image/video preview, rich embed, etc.)
*/
class MessageEmbed {
constructor(message, data) {
/**
* The client that instantiated this embed
* @name MessageEmbed#client
* @type {Client}
* @readonly
*/
Object.defineProperty(this, 'client', { value: message.client });
/**
* The message this embed is part of
* @type {Message}
*/
this.message = message;
this.setup(data);
}
setup(data) {
/**
* The type of this embed
* @type {string}
*/
this.type = data.type;
/**
* The title of this embed, if there is one
* @type {?string}
*/
this.title = data.title;
/**
* The description of this embed, if there is one
* @type {?string}
*/
this.description = data.description;
/**
* The URL of this embed
* @type {string}
*/
this.url = data.url;
/**
* The color of the embed
* @type {number}
*/
this.color = data.color;
/**
* The fields of this embed
* @type {MessageEmbedField[]}
*/
this.fields = [];
if (data.fields) for (const field of data.fields) this.fields.push(new MessageEmbedField(this, field));
/**
* The timestamp of this embed
* @type {number}
*/
this.createdTimestamp = data.timestamp;
/**
* The thumbnail of this embed, if there is one
* @type {MessageEmbedThumbnail}
*/
this.thumbnail = data.thumbnail ? new MessageEmbedThumbnail(this, data.thumbnail) : null;
/**
* The author of this embed, if there is one
* @type {MessageEmbedAuthor}
*/
this.author = data.author ? new MessageEmbedAuthor(this, data.author) : null;
/**
* The provider of this embed, if there is one
* @type {MessageEmbedProvider}
*/
this.provider = data.provider ? new MessageEmbedProvider(this, data.provider) : null;
/**
* The footer of this embed
* @type {MessageEmbedFooter}
*/
this.footer = data.footer ? new MessageEmbedFooter(this, data.footer) : null;
}
/**
* The date this embed was created
* @type {Date}
*/
get createdAt() {
return new Date(this.createdTimestamp);
}
/**
* The hexadecimal version of the embed color, with a leading hash.
* @type {string}
* @readonly
*/
get hexColor() {
let col = this.color.toString(16);
while (col.length < 6) col = `0${col}`;
return `#${col}`;
}
}
/**
* Represents a thumbnail for a message embed
*/
class MessageEmbedThumbnail {
constructor(embed, data) {
/**
* The embed this thumbnail is part of
* @type {MessageEmbed}
*/
this.embed = embed;
this.setup(data);
}
setup(data) {
/**
* The URL for this thumbnail
* @type {string}
*/
this.url = data.url;
/**
* The Proxy URL for this thumbnail
* @type {string}
*/
this.proxyURL = data.proxy_url;
/**
* The height of the thumbnail
* @type {number}
*/
this.height = data.height;
/**
* The width of the thumbnail
* @type {number}
*/
this.width = data.width;
}
}
/**
* Represents a provider for a message embed
*/
class MessageEmbedProvider {
constructor(embed, data) {
/**
* The embed this provider is part of
* @type {MessageEmbed}
*/
this.embed = embed;
this.setup(data);
}
setup(data) {
/**
* The name of this provider
* @type {string}
*/
this.name = data.name;
/**
* The URL of this provider
* @type {string}
*/
this.url = data.url;
}
}
/**
* Represents an author for a message embed
*/
class MessageEmbedAuthor {
constructor(embed, data) {
/**
* The embed this author is part of
* @type {MessageEmbed}
*/
this.embed = embed;
this.setup(data);
}
setup(data) {
/**
* The name of this author
* @type {string}
*/
this.name = data.name;
/**
* The URL of this author
* @type {string}
*/
this.url = data.url;
/**
* The icon URL of this author
* @type {string}
*/
this.iconURL = data.icon_url;
}
}
/**
* Represents a field for a message embed
*/
class MessageEmbedField {
constructor(embed, data) {
/**
* The embed this footer is part of
* @type {MessageEmbed}
*/
this.embed = embed;
this.setup(data);
}
setup(data) {
/**
* The name of this field
* @type {string}
*/
this.name = data.name;
/**
* The value of this field
* @type {string}
*/
this.value = data.value;
/**
* If this field is displayed inline
* @type {boolean}
*/
this.inline = data.inline;
}
}
/**
* Represents the footer of a message embed
*/
class MessageEmbedFooter {
constructor(embed, data) {
/**
* The embed this footer is part of
* @type {MessageEmbed}
*/
this.embed = embed;
this.setup(data);
}
setup(data) {
/**
* The text in this footer
* @type {string}
*/
this.text = data.text;
/**
* The icon URL of this footer
* @type {string}
*/
this.iconURL = data.icon_url;
/**
* The proxy icon URL of this footer
* @type {string}
*/
this.proxyIconUrl = data.proxy_icon_url;
}
}
MessageEmbed.Thumbnail = MessageEmbedThumbnail;
MessageEmbed.Provider = MessageEmbedProvider;
MessageEmbed.Author = MessageEmbedAuthor;
MessageEmbed.Field = MessageEmbedField;
MessageEmbed.Footer = MessageEmbedFooter;
module.exports = MessageEmbed;
|