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
|
'use strict';
const { embedLength } = require('@discordjs/builders');
const isEqual = require('fast-deep-equal');
/**
* Represents an embed.
*/
class Embed {
constructor(data) {
/**
* The API embed data.
* @type {APIEmbed}
* @readonly
*/
this.data = { ...data };
}
/**
* An array of fields of this embed.
* @type {Array<APIEmbedField>}
* @readonly
*/
get fields() {
return this.data.fields ?? [];
}
/**
* The title of this embed.
* @type {?string}
* @readonly
*/
get title() {
return this.data.title ?? null;
}
/**
* The description of this embed.
* @type {?string}
* @readonly
*/
get description() {
return this.data.description ?? null;
}
/**
* The URL of this embed.
* @type {?string}
* @readonly
*/
get url() {
return this.data.url ?? null;
}
/**
* The color of this embed.
* @type {?number}
* @readonly
*/
get color() {
return this.data.color ?? null;
}
/**
* The timestamp of this embed. This is in an ISO 8601 format.
* @type {?string}
* @readonly
*/
get timestamp() {
return this.data.timestamp ?? null;
}
/**
* @typedef {Object} EmbedAssetData
* @property {?string} url The URL of the image
* @property {?string} proxyURL The proxy URL of the image
* @property {?number} height The height of the image
* @property {?number} width The width of the image
*/
/**
* The thumbnail of this embed.
* @type {?EmbedAssetData}
* @readonly
*/
get thumbnail() {
if (!this.data.thumbnail) return null;
return {
url: this.data.thumbnail.url,
proxyURL: this.data.thumbnail.proxy_url,
height: this.data.thumbnail.height,
width: this.data.thumbnail.width,
};
}
/**
* The image of this embed.
* @type {?EmbedAssetData}
* @readonly
*/
get image() {
if (!this.data.image) return null;
return {
url: this.data.image.url,
proxyURL: this.data.image.proxy_url,
height: this.data.image.height,
width: this.data.image.width,
};
}
/**
* The video of this embed.
* @type {?EmbedAssetData}
* @readonly
*/
get video() {
if (!this.data.video) return null;
return {
url: this.data.video.url,
proxyURL: this.data.video.proxy_url,
height: this.data.video.height,
width: this.data.video.width,
};
}
/**
* @typedef {Object} EmbedAuthorData
* @property {string} name The name of the author
* @property {?string} url The URL of the author
* @property {?string} iconURL The icon URL of the author
* @property {?string} proxyIconURL The proxy icon URL of the author
*/
/**
* The author of this embed.
* @type {?EmbedAuthorData}
* @readonly
*/
get author() {
if (!this.data.author) return null;
return {
name: this.data.author.name,
url: this.data.author.url,
iconURL: this.data.author.icon_url,
proxyIconURL: this.data.author.proxy_icon_url,
};
}
/**
* The provider of this embed.
* @type {?APIEmbedProvider}
* @readonly
*/
get provider() {
return this.data.provider ?? null;
}
/**
* @typedef {Object} EmbedFooterData
* @property {string} text The text of the footer
* @property {?string} iconURL The URL of the icon
* @property {?string} proxyIconURL The proxy URL of the icon
*/
/**
* The footer of this embed.
* @type {?EmbedFooterData}
* @readonly
*/
get footer() {
if (!this.data.footer) return null;
return {
text: this.data.footer.text,
iconURL: this.data.footer.icon_url,
proxyIconURL: this.data.footer.proxy_icon_url,
};
}
/**
* The accumulated length for the embed title, description, fields, footer text, and author name.
* @type {number}
* @readonly
*/
get length() {
return embedLength(this.data);
}
/**
* The hex color of this embed.
* @type {?string}
* @readonly
*/
get hexColor() {
return typeof this.data.color === 'number'
? `#${this.data.color.toString(16).padStart(6, '0')}`
: this.data.color ?? null;
}
/**
* Returns the API-compatible JSON for this embed.
* @returns {APIEmbed}
*/
toJSON() {
return { ...this.data };
}
/**
* Whether the given embeds are equal.
* @param {Embed|APIEmbed} other The embed to compare against
* @returns {boolean}
*/
equals(other) {
if (other instanceof Embed) {
return isEqual(other.data, this.data);
}
return isEqual(other, this.data);
}
}
module.exports = Embed;
|