-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes_client_client.js.html
375 lines (330 loc) · 17.4 KB
/
classes_client_client.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>classes/client/client.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/client/client.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const { EventEmitter } = require('events')
const ClientWebSocket = require('./webSocket.js')
/**
* The main class for the Guilded.js library
* @class Client
* @extends EventEmitter
* @param {String} token The token of the bot
*/
class Client extends EventEmitter {
/**
* Creates a new bot instance.
* See {@tutorial example-bot} for an example
* @param {String} token Your guilded bot's Auth Token
* @param {Object} [options] Options for the client
* @param {String} [options.maxReconnectTries=Infinity] The maximum number of times to retry a request or reconnect
* @returns {Client}
* @example
* const { Client } = require('guilded.js');
* const client = new Client('token');
*/
constructor (token = String, options = Object) {
super()
/**
* The token of the bot
* @type {String}
* @readonly
*/
this.token = token
/**
* The websocket of the bot
* @type {ClientWebSocket}
* @readonly
*/
this.ws = null
/**
* The options of the bot
* @type {Object}
* @readonly
*/
this.options = options
}
/**
* Connects the bot to the Guilded API
* @returns {Promise<void>}
* @example
* client.login();
* @example
* client.login().then(() => {
* console.log('Bot is ready!');
* });
*/
login () {
/**
* Create a new WebSocket connection
* @param {Client} client
* @returns {ClientWebSocket}
* @constructor
* @private
* @ignore
*/
this.ws = new ClientWebSocket(this)
/**
* Connects the bot to the Guilded API
* @returns {Promise<void>}
* @example
* client.ws.connect();
* @example
* client.ws.connect().then(() => {
* console.log('Bot is ready!');
* });
* @private
* @ignore
*/
this.ws.connect()
/**
* Emitted when the bot is ready
* @event Client#ready
* @param {Client} client The client that emitted the event
* @example
* client.on('ready', () => {
* console.log('Bot is ready!');
* });
*/
this.ws.on('clientReady', (client) => {
this.emit('ready', client)
})
/**
* Emitted when the bot receives a message
* @event Client#message
* @param {Message} message
* @example
* client.on('serverMessageCreate', (message) => {
* console.log(message.content);
* });
*/
this.ws.on('messageCreated', (message) => {
this.emit('serverMessageCreate', message)
})
/**
* Emitted when the bot receives a updated message
* @event Client#messageUpdate
* @param {Message} message
* @example
* client.on('serverMessageUpdate', (message) => {
* console.log(message.content);
* });
*/
this.ws.on('messageUpdated', (message) => {
this.emit('serverMessageUpdate', message)
})
/**
* Emitted when the bot receives a deleted message
* @event Client#messageDelete
* @param {Message} message
* @example
* client.on('serverMessageDelete', (message) => {
* console.log(message.content);
* });
*/
this.ws.on('messageDeleted', (message) => {
this.emit('serverMessageDelete', message)
})
/**
* Emitted when the bot receives a member join
* @event Client#memberJoin
* @param {Member} member
* @example
* client.on('serverMemberJoin', (member) => {
* console.log(member.nickname);
* });
*/
this.ws.on('memberAdded', (member) => {
this.emit('serverMemberJoin', member)
})
/**
* Emitted when the bot receives a member leave
* @event Client#memberLeave
* @param {MemberRemoved} member
* @example
* client.on('serverMemberLeft', (member) => {
* console.log(member.username);
* });
*/
this.ws.on('memberRemoved', (member) => {
this.emit('serverMemberLeft', member)
})
/**
* Emitted when the bot receives a member ban
* @event Client#memberBan
* @param {MemberBan} memberBan
* @example
* client.on('serverMemberBan', (member) => {
* console.log(member.nickname);
* });
*/
this.ws.on('memberBanned', (member) => {
this.emit('serverMemberBan', member)
})
/**
* Emitted when the bot receives a member unban
* @event Client#memberUnban
* @param {MemberBan} memberBan
* @example
* client.on('serverMemberUnban', (member) => {
* console.log(member.nickname);
* });
*/
this.ws.on('memberUnbanned', (member) => {
this.emit('serverMemberUnban', member)
})
/**
* Emitted when the bot receives a member update
* @event Client#memberUpdate
* @param {MemberUpdated} member
* @example
* client.on('serverMemberUpdate', (member) => {
* console.log(member.username);
* });
*/
this.ws.on('memberUpdated', (member) => {
this.emit('serverMemberUpdate', member)
})
/**
* Emitted when the bot receives a member role update
* @event Client#memberRoleUpdate
* @param {RolesUpdated} rolesUpdated
* @example
* client.on('serverMemberUpdate', (rolesUpdated) => {
* console.log(rolesUpdated[0]);
* });
*/
this.ws.on('memberRolesUpdated', (rolesUpdated) => {
this.emit('serverMemberUpdate', rolesUpdated)
})
/**
* Emitted when the bot receives a webhook create
* @event Client#webhookCreate
* @param {Webhook} webhook
* @example
* client.on('serverWebhookCreate', (webhook) => {
* console.log(webhook.name);
* });
*/
this.ws.on('webhookCreated', (webhook) => {
this.emit('serverWebhookCreate', webhook)
})
/**
* Emitted when the bot receives a webhook update
* @event Client#webhookUpdate
* @param {Webhook} webhook
* @example
* client.on('serverWebhookUpdate', (webhook) => {
* console.log(webhook.name);
* });
*/
this.ws.on('webhookUpdated', (webhook) => {
this.emit('serverWebhookUpdate', webhook)
})
/**
* Emitted when the bot receives a reaction add
* @event Client#reactionAdd
* @param {Reaction} reaction
* @example
* client.on('messageReactionCreated', (reaction) => {
* console.log(reaction.emoteId);
* });
*/
this.ws.on('messageReactionCreated', (reaction) => {
this.emit('messageReactionCreated', reaction)
})
/**
* Emitted when the bot receives a reaction remove
* @event Client#reactionRemove
* @param {Reaction} reaction
* @example
* client.on('messageReactionDeleted', (reaction) => {
* console.log(reaction.emoteId);
* });
*/
this.ws.on('ChannelMessageReactionDeleted', (reaction) => {
this.emit('ChannelMessageReactionDeleted', reaction)
})
/**
* Emitted when the bot receives a closed event
* @event Client#closed
* @example
* client.on('closed', () => {
* console.log('Bot is closed!');
* });
*/
this.ws.on('closed', () => {
this.emit('disconnect')
})
/**
* Emitted when the bot receives a error event
* @event Client#error
* @param {Error} error
* @example
* client.on('error', (error) => {
* console.log(error);
* });
*/
this.ws.on('clientError', (error) => {
this.emit('error', error)
})
/**
* Emitted when the bot receives a debug event
* @event Client#debug
* @param {String} message
* @example
* client.on('debug', (message) => {
* console.log(message);
* });
*/
this.ws.on('clientDebug', (message) => {
this.emit('debug', message)
})
/**
* Delete the client
* @event Client#destroy
* @example
* client.destroy();
*/
this.destroy = async () => {
this.emit('destroy')
await this.ws.close()
}
}
}
module.exports = Client
</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>