djs-selfbot-v13 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -45
  3. package/package.json +8 -37
  4. package/src/client/BaseClient.js +2 -3
  5. package/src/client/Client.js +187 -539
  6. package/src/client/actions/Action.js +18 -13
  7. package/src/client/actions/ActionsManager.js +7 -1
  8. package/src/client/actions/AutoModerationActionExecution.js +1 -0
  9. package/src/client/actions/AutoModerationRuleCreate.js +1 -0
  10. package/src/client/actions/AutoModerationRuleDelete.js +1 -0
  11. package/src/client/actions/AutoModerationRuleUpdate.js +1 -0
  12. package/src/client/actions/MessageCreate.js +0 -4
  13. package/src/client/actions/PresenceUpdate.js +17 -16
  14. package/src/client/websocket/WebSocketManager.js +11 -31
  15. package/src/client/websocket/WebSocketShard.js +39 -38
  16. package/src/client/websocket/handlers/CALL_CREATE.js +3 -3
  17. package/src/client/websocket/handlers/CALL_DELETE.js +2 -2
  18. package/src/client/websocket/handlers/CALL_UPDATE.js +2 -2
  19. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +16 -13
  20. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  21. package/src/client/websocket/handlers/GUILD_CREATE.js +7 -0
  22. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +1 -0
  23. package/src/client/websocket/handlers/READY.js +47 -137
  24. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +7 -5
  25. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +6 -4
  26. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +32 -9
  27. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +2 -8
  28. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  29. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
  30. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +1 -5
  31. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  32. package/src/client/websocket/handlers/index.js +15 -20
  33. package/src/errors/Messages.js +24 -69
  34. package/src/index.js +12 -43
  35. package/src/managers/ApplicationCommandManager.js +9 -12
  36. package/src/managers/ApplicationCommandPermissionsManager.js +3 -11
  37. package/src/managers/ChannelManager.js +3 -4
  38. package/src/managers/ClientUserSettingManager.js +161 -279
  39. package/src/managers/GuildBanManager.js +1 -1
  40. package/src/managers/GuildChannelManager.js +2 -0
  41. package/src/managers/GuildForumThreadManager.js +22 -28
  42. package/src/managers/GuildMemberManager.js +40 -216
  43. package/src/managers/GuildSettingManager.js +22 -15
  44. package/src/managers/MessageManager.js +42 -44
  45. package/src/managers/PermissionOverwriteManager.js +1 -1
  46. package/src/managers/ReactionUserManager.js +5 -5
  47. package/src/managers/RelationshipManager.js +81 -74
  48. package/src/managers/ThreadManager.js +12 -45
  49. package/src/managers/ThreadMemberManager.js +1 -1
  50. package/src/managers/UserManager.js +6 -10
  51. package/src/managers/UserNoteManager.js +53 -0
  52. package/src/rest/APIRequest.js +42 -20
  53. package/src/rest/DiscordAPIError.js +17 -16
  54. package/src/rest/RESTManager.js +1 -21
  55. package/src/rest/RequestHandler.js +35 -21
  56. package/src/structures/ApplicationCommand.js +19 -456
  57. package/src/structures/ApplicationRoleConnectionMetadata.js +3 -0
  58. package/src/structures/AutoModerationRule.js +5 -5
  59. package/src/structures/AutocompleteInteraction.js +1 -0
  60. package/src/structures/BaseGuildTextChannel.js +10 -12
  61. package/src/structures/BaseGuildVoiceChannel.js +16 -18
  62. package/src/structures/{Call.js → CallState.js} +17 -12
  63. package/src/structures/CategoryChannel.js +2 -0
  64. package/src/structures/Channel.js +2 -3
  65. package/src/structures/ClientPresence.js +12 -8
  66. package/src/structures/ClientUser.js +117 -336
  67. package/src/structures/ContextMenuInteraction.js +1 -1
  68. package/src/structures/DMChannel.js +29 -92
  69. package/src/structures/ForumChannel.js +0 -10
  70. package/src/structures/GroupDMChannel.js +387 -0
  71. package/src/structures/Guild.js +135 -271
  72. package/src/structures/GuildAuditLogs.js +0 -5
  73. package/src/structures/GuildChannel.js +16 -2
  74. package/src/structures/GuildMember.js +27 -145
  75. package/src/structures/Interaction.js +1 -62
  76. package/src/structures/Invite.js +35 -52
  77. package/src/structures/Message.js +228 -202
  78. package/src/structures/MessageAttachment.js +11 -0
  79. package/src/structures/MessageButton.js +1 -67
  80. package/src/structures/MessageEmbed.js +1 -1
  81. package/src/structures/MessageMentions.js +3 -2
  82. package/src/structures/MessagePayload.js +4 -46
  83. package/src/structures/MessageReaction.js +1 -1
  84. package/src/structures/MessageSelectMenu.js +1 -252
  85. package/src/structures/Modal.js +75 -180
  86. package/src/structures/Presence.js +2 -2
  87. package/src/structures/RichPresence.js +14 -34
  88. package/src/structures/Role.js +18 -2
  89. package/src/structures/SelectMenuInteraction.js +2 -151
  90. package/src/structures/Team.js +0 -49
  91. package/src/structures/TextInputComponent.js +0 -70
  92. package/src/structures/ThreadChannel.js +0 -19
  93. package/src/structures/User.js +117 -345
  94. package/src/structures/UserContextMenuInteraction.js +2 -2
  95. package/src/structures/VoiceState.js +74 -39
  96. package/src/structures/WebEmbed.js +38 -52
  97. package/src/structures/Webhook.js +17 -11
  98. package/src/structures/interfaces/Application.js +146 -23
  99. package/src/structures/interfaces/TextBasedChannel.js +411 -256
  100. package/src/util/ApplicationFlags.js +1 -1
  101. package/src/util/AttachmentFlags.js +38 -0
  102. package/src/util/Constants.js +106 -284
  103. package/src/util/Formatters.js +16 -2
  104. package/src/util/InviteFlags.js +29 -0
  105. package/src/util/LimitedCollection.js +1 -1
  106. package/src/util/Options.js +48 -68
  107. package/src/util/Permissions.js +5 -0
  108. package/src/util/PurchasedFlags.js +2 -0
  109. package/src/util/RemoteAuth.js +221 -356
  110. package/src/util/RoleFlags.js +37 -0
  111. package/src/util/Sweepers.js +1 -1
  112. package/src/util/Util.js +76 -36
  113. package/typings/enums.d.ts +18 -73
  114. package/typings/index.d.ts +873 -1225
  115. package/typings/rawDataTypes.d.ts +68 -9
  116. package/src/client/actions/InteractionCreate.js +0 -115
  117. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +0 -23
  118. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +0 -11
  119. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +0 -55
  120. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  121. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  122. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  123. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  124. package/src/client/websocket/handlers/INTERACTION_CREATE.js +0 -16
  125. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +0 -18
  126. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +0 -30
  127. package/src/client/websocket/handlers/MESSAGE_ACK.js +0 -16
  128. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  129. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  130. package/src/managers/DeveloperPortalManager.js +0 -104
  131. package/src/managers/GuildApplicationCommandManager.js +0 -28
  132. package/src/managers/GuildFolderManager.js +0 -24
  133. package/src/managers/SessionManager.js +0 -57
  134. package/src/rest/CaptchaSolver.js +0 -132
  135. package/src/structures/ClientApplication.js +0 -204
  136. package/src/structures/DeveloperPortalApplication.js +0 -520
  137. package/src/structures/GuildFolder.js +0 -75
  138. package/src/structures/InteractionResponse.js +0 -114
  139. package/src/structures/PartialGroupDMChannel.js +0 -433
  140. package/src/structures/Session.js +0 -81
  141. package/src/util/Voice.js +0 -1456
  142. package/src/util/arRPC/index.js +0 -229
  143. package/src/util/arRPC/process/detectable.json +0 -1
  144. package/src/util/arRPC/process/index.js +0 -102
  145. package/src/util/arRPC/process/native/index.js +0 -5
  146. package/src/util/arRPC/process/native/linux.js +0 -37
  147. package/src/util/arRPC/process/native/win32.js +0 -25
  148. package/src/util/arRPC/transports/ipc.js +0 -281
  149. package/src/util/arRPC/transports/websocket.js +0 -128
@@ -1,433 +0,0 @@
1
- 'use strict';
2
-
3
- const { Collection } = require('@discordjs/collection');
4
- const { joinVoiceChannel, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
5
- const { Channel } = require('./Channel');
6
- const Invite = require('./Invite');
7
- const TextBasedChannel = require('./interfaces/TextBasedChannel');
8
- const { Error } = require('../errors');
9
- const MessageManager = require('../managers/MessageManager');
10
- const { Status, Opcodes } = require('../util/Constants');
11
- const DataResolver = require('../util/DataResolver');
12
-
13
- /**
14
- * Represents a Partial Group DM Channel on Discord.
15
- * @extends {Channel}
16
- */
17
- class PartialGroupDMChannel extends Channel {
18
- constructor(client, data) {
19
- super(client, data);
20
-
21
- // No flags are present when fetching partial group DM channels.
22
- this.flags = null;
23
-
24
- /**
25
- * The name of this Group DM Channel
26
- * @type {?string}
27
- */
28
- this.name = null;
29
-
30
- /**
31
- * The hash of the channel icon
32
- * @type {?string}
33
- */
34
- this.icon = null;
35
-
36
- /**
37
- * Messages data
38
- * @type {Collection}
39
- */
40
- this.messages = new MessageManager(this);
41
-
42
- /**
43
- * Last Message ID
44
- * @type {?Snowflake}
45
- */
46
- this.lastMessageId = null;
47
-
48
- /**
49
- * Last Pin Timestamp
50
- * @type {UnixTimestamp}
51
- */
52
- this.lastPinTimestamp = null;
53
-
54
- /**
55
- * Owner ID
56
- * @type {?Snowflake}
57
- */
58
- this.ownerId = null;
59
-
60
- /**
61
- * Invites fetch
62
- * @type {Collection<string, Invite>}
63
- */
64
- this.invites = new Collection();
65
-
66
- this._recipients = [];
67
-
68
- this._patch(data);
69
- }
70
-
71
- /**
72
- * The recipients of this Group DM Channel.
73
- * @type {Collection<Snowflake, User>}
74
- * @readonly
75
- */
76
- get recipients() {
77
- const collect = new Collection();
78
- this._recipients.map(recipient => collect.set(recipient.id, this.client.users._add(recipient)));
79
- collect.set(this.client.user.id, this.client.user);
80
- return collect;
81
- }
82
-
83
- /**
84
- * The owner of this Group DM Channel
85
- * @type {?User}
86
- * @readonly
87
- */
88
- get owner() {
89
- return this.client.users.cache.get(this.ownerId);
90
- }
91
-
92
- /**
93
- *
94
- * @param {Object} data Channel Data
95
- * @private
96
- */
97
- _patch(data) {
98
- super._patch(data);
99
- if ('recipients' in data && Array.isArray(data.recipients)) {
100
- this._recipients = data.recipients;
101
- }
102
- if ('last_pin_timestamp' in data) {
103
- const date = new Date(data.last_pin_timestamp);
104
- this.lastPinTimestamp = date.getTime();
105
- }
106
- if ('last_message_id' in data) {
107
- this.lastMessageId = data.last_message_id;
108
- }
109
- if ('owner_id' in data) {
110
- this.ownerId = data.owner_id;
111
- }
112
- if ('name' in data) {
113
- this.name = data.name;
114
- }
115
- if ('icon' in data) {
116
- this.icon = data.icon;
117
- }
118
- }
119
-
120
- /**
121
- * Edit channel data
122
- * @param {Object} data name, icon owner
123
- * @returns {Promise<undefined>}
124
- * @private
125
- */
126
- async edit(data) {
127
- const _data = {};
128
- if ('name' in data) _data.name = data.name?.trim() ?? null;
129
- if (typeof data.icon !== 'undefined') {
130
- _data.icon = await DataResolver.resolveImage(data.icon);
131
- }
132
- if ('owner' in data) {
133
- _data.owner = data.owner;
134
- }
135
- const newData = await this.client.api.channels(this.id).patch({
136
- data: _data,
137
- });
138
-
139
- return this.client.actions.ChannelUpdate.handle(newData).updated;
140
- }
141
-
142
- /**
143
- * The URL to this channel's icon.
144
- * @param {StaticImageURLOptions} [options={}] Options for the Image URL
145
- * @returns {?string}
146
- */
147
- iconURL({ format, size } = {}) {
148
- return this.icon && this.client.rest.cdn.GDMIcon(this.id, this.icon, format, size);
149
- }
150
-
151
- /**
152
- * Adds a user to this Group DM Channel.
153
- * @param {UserResolvable} user User to add to the group
154
- * @returns {Promise<PartialGroupDMChannel>}
155
- */
156
- async addMember(user) {
157
- const userId = this.client.users.resolveId(user);
158
- user = this.client.users.resolve(userId);
159
- if (!userId) {
160
- return Promise.reject(new TypeError('User is not a User or User ID'));
161
- }
162
- // API
163
- // if (this.recipients.get(userId)) return Promise.reject(new Error('USER_ALREADY_IN_GROUP_DM_CHANNEL')); // Fails sometimes if member leaves recently (ex. user leave msg's channel used for adding)
164
- await this.client.api.channels[this.id].recipients[userId].put();
165
- this._recipients.push(user);
166
- return this;
167
- }
168
-
169
- /**
170
- * Removes a user from this Group DM Channel.
171
- * @param {UserResolvable} user User to remove from the group
172
- * @returns {Promise<PartialGroupDMChannel>}
173
- */
174
- async removeMember(user) {
175
- if (this.ownerId !== this.client.user.id) {
176
- return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
177
- }
178
- user = this.client.users.resolveId(user);
179
- if (!user) {
180
- return Promise.reject(new TypeError('User is not a User or User ID'));
181
- }
182
- // API
183
- // if (!this.recipients.get(user)) return Promise.reject(new Error('USER_NOT_IN_GROUP_DM_CHANNEL'));
184
- await this.client.api.channels[this.id].recipients[user].delete();
185
- this._recipients = this._recipients.filter(r => r.id !== user);
186
- return this;
187
- }
188
-
189
- /**
190
- * Renames this Group DM Channel.
191
- * @param {?string} name Name of the channel
192
- * @returns {Promise<PartialGroupDMChannel>}
193
- */
194
- setName(name) {
195
- return this.edit({ name });
196
- }
197
-
198
- /**
199
- * Sets the icon of this Group DM Channel.
200
- * @param {?(Base64Resolvable|BufferResolvable)} icon Icon of the channel
201
- * @returns {Promise<PartialGroupDMChannel>}
202
- */
203
- setIcon(icon) {
204
- return this.edit({ icon });
205
- }
206
-
207
- /**
208
- * Changes the owner of this Group DM Channel.
209
- * @param {UserResolvable} user User to transfer ownership to
210
- * @returns {Promise<PartialGroupDMChannel>}
211
- */
212
- setOwner(user) {
213
- const id = this.client.users.resolveId(user);
214
- if (!id) {
215
- throw new TypeError('User is not a User or User ID');
216
- }
217
- if (this.ownerId !== this.client.user.id) {
218
- throw new Error('NOT_OWNER_GROUP_DM_CHANNEL');
219
- }
220
- if (this.ownerId === id) {
221
- return this;
222
- }
223
- return this.edit({ owner: id });
224
- }
225
-
226
- /**
227
- * Gets the invite for this Group DM Channel.
228
- * @returns {Promise<Invite>}
229
- */
230
- async getInvite() {
231
- const inviteCode = await this.client.api.channels(this.id).invites.post({
232
- data: {
233
- max_age: 86400,
234
- },
235
- });
236
- const invite = new Invite(this.client, inviteCode);
237
- this.invites.set(invite.code, invite);
238
- return invite;
239
- }
240
-
241
- /**
242
- * Get all the invites for this Group DM Channel.
243
- * @param {boolean} force Using API to fetch invites or cache
244
- * @returns {Promise<Collection<string, Invite>>}
245
- */
246
- async fetchInvite(force = false) {
247
- if (this.ownerId !== this.client.user.id) {
248
- return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
249
- }
250
- if (!force && this.invites.size) return this.invites;
251
- const invites = await this.client.api.channels(this.id).invites.get();
252
- await Promise.all(invites.map(invite => this.invites.set(invite.code, new Invite(this.client, invite))));
253
- return this.invites;
254
- }
255
-
256
- /**
257
- * Delete invites from this Group DM Channel.
258
- * @param {Invite} invite Invite to add to the channel
259
- * @returns {Promise<PartialGroupDMChannel>}
260
- */
261
- async removeInvite(invite) {
262
- if (this.ownerId !== this.client.user.id) {
263
- return Promise.reject(new Error('NOT_OWNER_GROUP_DM_CHANNEL'));
264
- }
265
- if (!(invite instanceof Invite)) {
266
- return Promise.reject(new TypeError('Invite is not an instance of Discord.Invite'));
267
- }
268
- await this.client.api.channels(this.id).invites[invite.code].delete();
269
- this.invites.delete(invite.code);
270
- return this;
271
- }
272
-
273
- /**
274
- * Leave this Group DM Channel.
275
- * @param {?boolean} slient Leave without notifying other members
276
- * @returns {Promise<Channel>}
277
- * @example
278
- * // Delete the channel
279
- * channel.delete()
280
- * .then(console.log)
281
- * .catch(console.error);
282
- */
283
- async delete(slient = false) {
284
- if (typeof slient === 'boolean' && slient) {
285
- await this.client.api.channels(this.id).delete({
286
- query: {
287
- silent: true,
288
- },
289
- });
290
- } else {
291
- await this.client.api.channels(this.id).delete();
292
- }
293
- return this;
294
- }
295
-
296
- // These are here only for documentation purposes - they are implemented by TextBasedChannel
297
- /* eslint-disable no-empty-function */
298
- get lastMessage() {}
299
- get lastPinAt() {}
300
- send() {}
301
- sendTyping() {}
302
-
303
- /**
304
- * @typedef {Object} CallOptions
305
- * @property {boolean} [selfDeaf] Whether to deafen yourself
306
- * @property {boolean} [selfMute] Whether to mute yourself
307
- * @property {boolean} [ring=true] Emit a ringtone
308
- */
309
- // Testing feature: Call
310
- // URL: https://discord.com/api/v9/channels/DMchannelId/call/ring
311
- /**
312
- * Call this Group DMChannel. Return discordjs/voice VoiceConnection
313
- * @param {CallOptions} options Options for the call
314
- * @returns {Promise<VoiceConnection>}
315
- */
316
- call(options = {}) {
317
- options = Object.assign(
318
- {
319
- ring: true,
320
- },
321
- options || {},
322
- );
323
- return new Promise((resolve, reject) => {
324
- if (!this.client.options.patchVoice) {
325
- reject(
326
- new Error(
327
- 'VOICE_NOT_PATCHED',
328
- 'Enable voice patching in client options\nhttps://discordjs-self-v13.netlify.app/#/docs/docs/main/typedef/ClientOptions',
329
- ),
330
- );
331
- } else {
332
- if (options.ring) {
333
- this.client.api.channels(this.id).call.ring.post({
334
- data: {
335
- recipients: null,
336
- },
337
- });
338
- }
339
- const connection = joinVoiceChannel({
340
- channelId: this.id,
341
- guildId: null,
342
- adapterCreator: this.voiceAdapterCreator,
343
- selfDeaf: options.selfDeaf ?? false,
344
- selfMute: options.selfMute ?? false,
345
- });
346
- entersState(connection, VoiceConnectionStatus.Ready, 30000)
347
- .then(connection => {
348
- resolve(connection);
349
- })
350
- .catch(err => {
351
- connection.destroy();
352
- reject(err);
353
- });
354
- }
355
- });
356
- }
357
- /**
358
- * Sync VoiceState of this Group DMChannel.
359
- * @returns {undefined}
360
- */
361
- sync() {
362
- this.client.ws.broadcast({
363
- op: Opcodes.DM_UPDATE,
364
- d: {
365
- channel_id: this.id,
366
- },
367
- });
368
- }
369
- /**
370
- * The user in this voice-based channel
371
- * @type {Collection<Snowflake, User>}
372
- * @readonly
373
- */
374
- get voiceUsers() {
375
- const coll = new Collection();
376
- for (const state of this.client.voiceStates.cache.values()) {
377
- if (state.channelId === this.id && state.user) {
378
- coll.set(state.id, state.user);
379
- }
380
- }
381
- return coll;
382
- }
383
- /**
384
- * Get connection to current call
385
- * @type {?VoiceConnection}
386
- * @readonly
387
- */
388
- get voiceConnection() {
389
- const check = this.client.callVoice?.joinConfig?.channelId == this.id;
390
- if (check) {
391
- return this.client.callVoice;
392
- }
393
- return null;
394
- }
395
- /**
396
- * Get current shard
397
- * @type {WebSocketShard}
398
- * @readonly
399
- */
400
- get shard() {
401
- return this.client.ws.shards.first();
402
- }
403
- /**
404
- * The voice state adapter for this client that can be used with @discordjs/voice to play audio in DM / Group DM channels.
405
- * @type {?Function}
406
- * @readonly
407
- */
408
- get voiceAdapterCreator() {
409
- return methods => {
410
- this.client.voice.adapters.set(this.id, methods);
411
- return {
412
- sendPayload: data => {
413
- if (this.shard.status !== Status.READY) return false;
414
- this.shard.send(data);
415
- return true;
416
- },
417
- destroy: () => {
418
- this.client.voice.adapters.delete(this.id);
419
- },
420
- };
421
- };
422
- }
423
- }
424
-
425
- TextBasedChannel.applyToClass(PartialGroupDMChannel, true, [
426
- 'bulkDelete',
427
- 'fetchWebhooks',
428
- 'createWebhook',
429
- 'setRateLimitPerUser',
430
- 'setNSFW',
431
- ]);
432
-
433
- module.exports = PartialGroupDMChannel;
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
-
5
- /**
6
- * @typedef {Object} SessionClientInfo
7
- * @property {string} location Location of the client (using IP address)
8
- * @property {string} platform Platform of the client
9
- * @property {string} os Operating system of the client
10
- */
11
-
12
- /**
13
- * Represents a Client OAuth2 Application Team.
14
- * @extends {Base}
15
- */
16
- class Session extends Base {
17
- constructor(client, data) {
18
- super(client);
19
- this._patch(data);
20
- }
21
-
22
- _patch(data) {
23
- if ('id_hash' in data) {
24
- /**
25
- * The session hash id
26
- * @type {string}
27
- */
28
- this.id = data.id_hash;
29
- }
30
- if ('approx_last_used_time' in data) {
31
- this.approxLastUsedTime = data.approx_last_used_time;
32
- }
33
- if ('client_info' in data) {
34
- /**
35
- * The client info
36
- * @type {SessionClientInfo}
37
- */
38
- this.clientInfo = data.client_info;
39
- }
40
- }
41
-
42
- /**
43
- * The timestamp the client was last used at.
44
- * @type {number}
45
- * @readonly
46
- */
47
- get createdTimestamp() {
48
- return this.createdAt.getTime();
49
- }
50
-
51
- /**
52
- * The time the client was last used at.
53
- * @type {Date}
54
- * @readonly
55
- */
56
- get createdAt() {
57
- return new Date(this.approxLastUsedTime);
58
- }
59
-
60
- /**
61
- * Logout the client (remote).
62
- * @param {string | null} mfaCode MFA code (if 2FA is enabled)
63
- * @returns {Promise<undefined>}
64
- */
65
- logout(mfaCode) {
66
- if (typeof this.client.password !== 'string') throw new Error('REQUIRE_PASSWORD', 'You must provide a password.');
67
- return this.client.api.auth.sessions.logout({
68
- data: {
69
- session_id_hashes: [this.id],
70
- password: this.client.password,
71
- code: typeof mfaCode === 'string' ? mfaCode : undefined,
72
- },
73
- });
74
- }
75
-
76
- toJSON() {
77
- return super.toJSON();
78
- }
79
- }
80
-
81
- module.exports = Session;