-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRichEmbed.js
46 lines (44 loc) · 1.44 KB
/
RichEmbed.js
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
class RichEmbed {
constructor() {
this.embed = {};
}
setAuthor(text, icon) {
this.embed.author = {};
this.embed.author.name = text;
this.embed.author.icon_url = icon;
return this;
}
setFooter(text, icon) {
this.embed.footer = {};
this.embed.footer.text = text;
this.embed.footer.icon_url = icon;
return this;
}
setColor(color) {
this.embed.color = color;
}
setTimestamp() {
this.embed.timestamp = new Date();
}
setTitle(str) {
if (str.length >= 256) throw new RangeError('Embed titles may not exceed 256 characters.');
this.embed.title = str;
return this;
}
setDescription(str) {
if (str.length >= 2048) throw new RangeError('Embed descriptions may not exceed 2048 characters.');
this.embed.description = str;
return this;
}
addField(name, value, inline) {
//if (typeof name !== 'string') throw new TypeError('Embed field \'name\' must be a string.');
//if (typeof value !== 'string') throw new TypeError('Embed field \'value\' must be a string.');
//if (typeof inline !== 'boolean') throw new TypeError('Embed field \'inline\' must be a boolean.');
this.embed.fields = this.embed.fields || [];
if (this.embed.fields.size >= 25) throw new RangeError('You may only have 25 embed fields.');
if (typeof value === 'undefined') value = 'undefined';
this.embed.fields.push( {name, value, inline});
return this;
}
}
module.exports = RichEmbed;