-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes_structures_messageEmbed.js.html
353 lines (312 loc) · 17.7 KB
/
classes_structures_messageEmbed.js.html
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>classes/structures/messageEmbed.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Tutorials</li><li class="nav-item"><a href="tutorial-example-bot.html">Example Bot</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Client.html">Client</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Client.html#login">login</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="ClientWebSocket.html">ClientWebSocket</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="ClientWebSocket.html#connect">connect</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Member.html">Member</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="MemberBan.html">MemberBan</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="MemberRemove.html">MemberRemove</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="MemberUpdated.html">MemberUpdated</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Message.html">Message</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#delete">delete</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#edit">edit</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#getMember">getMember</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#getUser">getUser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#react">react</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Message.html#reply">reply</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="MessageEmbed.html">MessageEmbed</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#addField">addField</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setAuthor">setAuthor</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setColor">setColor</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setDescription">setDescription</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setFields">setFields</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setFooter">setFooter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setImage">setImage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setThumbnail">setThumbnail</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setTimestamp">setTimestamp</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setTitle">setTitle</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="MessageEmbed.html#setURL">setURL</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Reaction.html">Reaction</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="User.html">User</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="User.html#getAvatarURL">getAvatarURL</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="User.html#getBannerURL">getBannerURL</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="UserSummary.html">UserSummary</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Webhook.html">Webhook</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:closed">closed</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:debug">debug</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:destroy">destroy</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:error">error</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberBan">memberBan</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberJoin">memberJoin</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberLeave">memberLeave</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberRoleUpdate">memberRoleUpdate</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberUnban">memberUnban</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:memberUpdate">memberUpdate</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:message">message</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:messageDelete">messageDelete</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:messageUpdate">messageUpdate</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:reactionAdd">reactionAdd</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:reactionRemove">reactionRemove</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:ready">ready</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:webhookCreate">webhookCreate</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Client.html#event:webhookUpdate">webhookUpdate</a></span></li>
</nav>
<div id="main">
<h1 class="page-title">classes/structures/messageEmbed.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* This class is used to create embeds for guilded messages
*/
class MessageEmbed {
/**
* Set the title of the embed
* @param {string} title - The title of the embed
* @returns {MessageEmbed} - The embed
* @example
* embed.setTitle('This is a title');
*/
setTitle(title) {
if (typeof title !== "string") return this;
if (title.length > 256) return this;
this.title = title;
return this;
}
/**
* Set the description of the embed
* @param {string} description - The description of the embed
* @returns {MessageEmbed} - The embed
* @example
* embed.setDescription('This is a description');
*/
setDescription(description) {
if (typeof description !== "string") return this;
if (description.length > 2048) return this;
this.description = description;
return this;
}
/**
* Set a URL for the embed
* @param {String} url - The URL
* @returns {MessageEmbed} - The embed
* @example
* embed.setURL('https://guilded.gg');
*/
setURL(url) {
if (typeof url !== "string") return this;
//Create a regex to check if the url is valid, valid url: https://www.google.com, http://www.google.com, https://google.com?test=1, http://google.com?test=1&test2=2
let regex = /(https?:\/\/[^\s]+)/gi;
if (!regex.test(url)) return this;
this.url = url;
return this;
}
/**
* Set the color of the embed
* @param {string | number} color - The color of the embed
* @returns {MessageEmbed} - The embed
* @example
* embed.setColor('#0099ff');
* embed.setColor(0x0099ff);
* embed.setColor('grey');
* embed.setColor('RANDOM');
* embed.setColor('RED');
*/
setColor(color = null) {
const colors = {
red: 16711680,
green: 65280,
blue: 255,
yellow: 16776960,
purple: 8388736,
orange: 16753920,
grey: 10066329,
lightgrey: 13421772,
darkgrey: 3355443,
lightred: 16729344,
lightgreen: 16776960,
lightblue: 16775416,
lightyellow: 16774638,
lightpurple: 16740352,
lightorange: 16756736,
pink: 16761035,
lightpink: 16737792,
lightteal: 16773077,
lightcyan: 16744448,
lightmagenta: 16738885,
teal: 8421376,
cyan: 65535,
magenta: 255,
gold: 16766720,
lightgold: 16759920,
darkgold: 13369344,
darkorange: 13382297,
darkpink: 13382451,
darkteal: 13395559,
darkcyan: 13395457,
darkmagenta: 13382297,
darkgrey: 10066329,
darkred: 16711680,
darkgreen: 65280,
darkblue: 255,
darkyellow: 16776960,
darkpurple: 8388736,
chucknorris: 15787699,
};
switch (typeof color) {
case "string":
if (color.startsWith("#")) color = parseInt(color.replace("#", ""), 16);
else if (color.startsWith("0x"))
color = parseInt(color.replace("0x", ""), 16);
else if (colors[color]) color = colors[color];
else if (color.toLowerCase() === "random")
color = Math.floor(Math.random() * 16777215);
else return this;
break;
case "number":
if (color < 0 || color > 16777215) return this;
break;
}
return this;
}
/**
* Set the footer for the embed
* @param {Object} footer - The footer object
* @param {string} footer.text - The text of the footer
* @param {string | undefined} footer.icon - The icon of the footer
* @returns {MessageEmbed} - The embed
* @example
* embed.setFooter({text: 'This is a footer', icon: 'https://i.imgur.com/sINzKh7.png'});
*/
setFooter(footer = {}) {
if (typeof footer.text !== "string") return this;
if (footer.text.length > 2048) return this;
this.footer = {
text: footer.text,
icon_url: footer.iconURL,
};
return this;
}
/**
* Set the time for the embed
* @param {Date | undefined} date - The date for the embed
* @returns {MessageEmbed} - The embed
* @example
* embed.setTime(new Date());
* embed.setTime(Date.now());
*/
setTimestamp(timestamp = new Date().toISOString()) {
if (timestamp instanceof Date) return this;
this.timestamp = timestamp.toISOString();
return this;
}
/**
* Set the thumbnail for the embed
* @param {string} url - The url of the thumbnail
* @returns {MessageEmbed} - The embed
* @example
* embed.setThumbnail('https://i.imgur.com/sINzKh7.png');
*/
setThumbnail(thumbnail) {
if (typeof thumbnail !== "string") return this;
let regex = /(https?:\/\/.*\.(?:png|jpg|gif|jpeg|webp))/gi;
if (!regex.test(thumbnail)) return this;
if (thumbnail.length > 1024) return this;
this.thumbnail = {
url: thumbnail,
};
return this;
}
/**
* Set the image for the embed
* @param {string} url - The url of the image
* @returns {MessageEmbed} - The embed
* @example
* embed.setImage('https://i.imgur.com/sINzKh7.png');
*/
setImage(image) {
if (typeof image !== "string") return this;
// Create a regex to test for a valid url, example: https://i.imgur.com/sINzKh7.png, https://img.guildedcdn.com/UserAvatar/63d207d85e1a5225ec16377f72b8867e-Large.webp?w=450&h=450, https://google.com, http://google.com, etc. Supports ?size=1024, etc.
let regex = /(https?:\/\/.*\.(?:png|jpg|gif|jpeg|webp))/gi;
if (!regex.test(image)) return this;
if (image.length > 1024) return this;
this.image = {
url: image,
};
return this;
}
/**
* Set the author for the embed
* @param {Object} author - The author object
* @param {string} author.name - The name of the author
* @param {string | undefined} author.icon - The icon of the author
* @param {string | undefined} author.url - The url of the author
* @returns {MessageEmbed} - The embed
* @example
* embed.setAuthor({name: 'Guilded', icon: 'https://i.imgur.com/sINzKh7.png', url: 'https://guilded.gg'});
*/
setAuthor(author = {}) {
if (!author.name) return this;
if (typeof author.name !== "string") return this;
if (author.name.length > 256) return this;
this.author = {
name: author.name,
icon_url: author.iconURL,
url: author.url,
};
return this;
}
/**
* Set the fields for the embed, all fields must be an array of field objects
* @param {Array<field>} fields - The fields for the embed
* @returns {MessageEmbed} - The embed
* @example
* embed.setFields([
* {
* name: 'Field 1',
* value: 'This is field 1',
* inline: true
* },
* {
* name: 'Field 2',
* value: 'This is field 2',
* inline: false
* }
* ]);
*/
setFields(fields = []) {
if (!Array.isArray(fields)) return this;
if (fields.length > 25) return this;
let newFields = [];
fields.forEach((field) => {
if (!field.name) return this;
if (typeof field.name !== "string") return this;
if (field.name.length > 256) return this;
if (!field.value) return this;
if (typeof field.value !== "string") return this;
if (field.value.length > 1024) return this;
if (field.inline && typeof field.inline !== "boolean") return this;
newFields.push({
name: field.name,
value: field.value,
inline: field.inline ?? false,
});
});
this.fields = newFields;
return this;
}
/**
* Add a field to the embed
* @param {field} field - The field to add
* @returns {MessageEmbed} - The embed
* @example
* embed.addField({
* name: 'Field 1',
* value: 'This is field 1',
* inline: true
* });
* embed.addField({
* name: 'Field 2',
* value: 'This is field 2',
* inline: false
* });
*/
addField(name, value, inline = false) {
if (typeof name !== "string") return this;
if (name.length > 256) return this;
if (typeof value !== "string") return this;
if (value.length > 1024) return this;
if (typeof inline !== "boolean") return this;
if (!this.fields) this.fields = [];
if (this.fields.length > 25) return this;
this.fields.push({
name: name,
value: value,
inline: inline,
});
return this;
}
}
module.exports = MessageEmbed;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Sat Oct 08 2022 01:54:14 GMT-0500 (hora estándar de Colombia) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>