djs-selfbot-v13 3.1.6 → 3.1.7

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 (148) hide show
  1. package/README.md +31 -16
  2. package/package.json +15 -8
  3. package/src/client/BaseClient.js +3 -2
  4. package/src/client/Client.js +539 -187
  5. package/src/client/actions/Action.js +13 -18
  6. package/src/client/actions/ActionsManager.js +1 -7
  7. package/src/client/actions/AutoModerationActionExecution.js +0 -1
  8. package/src/client/actions/AutoModerationRuleCreate.js +0 -1
  9. package/src/client/actions/AutoModerationRuleDelete.js +0 -1
  10. package/src/client/actions/AutoModerationRuleUpdate.js +0 -1
  11. package/src/client/actions/InteractionCreate.js +115 -0
  12. package/src/client/actions/MessageCreate.js +4 -0
  13. package/src/client/actions/PresenceUpdate.js +16 -17
  14. package/src/client/websocket/WebSocketManager.js +31 -11
  15. package/src/client/websocket/WebSocketShard.js +38 -39
  16. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
  17. package/src/client/websocket/handlers/CALL_CREATE.js +3 -3
  18. package/src/client/websocket/handlers/CALL_DELETE.js +2 -2
  19. package/src/client/websocket/handlers/CALL_UPDATE.js +2 -2
  20. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +13 -16
  21. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  22. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
  23. package/src/client/websocket/handlers/GUILD_CREATE.js +0 -7
  24. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
  25. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  26. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  27. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  28. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  29. package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
  30. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
  31. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +0 -1
  32. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
  33. package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
  34. package/src/client/websocket/handlers/READY.js +137 -47
  35. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +5 -7
  36. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +4 -6
  37. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +9 -32
  38. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  39. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +8 -2
  40. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  41. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -1
  42. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  43. package/src/client/websocket/handlers/index.js +20 -15
  44. package/src/errors/Messages.js +69 -24
  45. package/src/index.js +43 -12
  46. package/src/managers/ApplicationCommandManager.js +12 -9
  47. package/src/managers/ApplicationCommandPermissionsManager.js +11 -3
  48. package/src/managers/ChannelManager.js +4 -2
  49. package/src/managers/ClientUserSettingManager.js +279 -161
  50. package/src/managers/DeveloperPortalManager.js +104 -0
  51. package/src/managers/GuildApplicationCommandManager.js +28 -0
  52. package/src/managers/GuildBanManager.js +1 -1
  53. package/src/managers/GuildChannelManager.js +0 -2
  54. package/src/managers/GuildFolderManager.js +24 -0
  55. package/src/managers/GuildForumThreadManager.js +28 -22
  56. package/src/managers/GuildMemberManager.js +216 -40
  57. package/src/managers/GuildSettingManager.js +15 -22
  58. package/src/managers/MessageManager.js +44 -42
  59. package/src/managers/PermissionOverwriteManager.js +1 -1
  60. package/src/managers/ReactionUserManager.js +5 -5
  61. package/src/managers/RelationshipManager.js +74 -81
  62. package/src/managers/SessionManager.js +57 -0
  63. package/src/managers/ThreadManager.js +45 -12
  64. package/src/managers/ThreadMemberManager.js +1 -1
  65. package/src/managers/UserManager.js +10 -6
  66. package/src/rest/APIRequest.js +20 -42
  67. package/src/rest/CaptchaSolver.js +132 -0
  68. package/src/rest/DiscordAPIError.js +16 -17
  69. package/src/rest/RESTManager.js +21 -1
  70. package/src/rest/RequestHandler.js +21 -35
  71. package/src/structures/ApplicationCommand.js +456 -19
  72. package/src/structures/ApplicationRoleConnectionMetadata.js +0 -3
  73. package/src/structures/AutoModerationRule.js +5 -5
  74. package/src/structures/AutocompleteInteraction.js +0 -1
  75. package/src/structures/BaseGuildTextChannel.js +12 -10
  76. package/src/structures/BaseGuildVoiceChannel.js +18 -16
  77. package/src/structures/{CallState.js → Call.js} +12 -17
  78. package/src/structures/CategoryChannel.js +0 -2
  79. package/src/structures/Channel.js +3 -2
  80. package/src/structures/ClientApplication.js +204 -0
  81. package/src/structures/ClientPresence.js +8 -12
  82. package/src/structures/ClientUser.js +336 -117
  83. package/src/structures/ContextMenuInteraction.js +1 -1
  84. package/src/structures/DMChannel.js +92 -29
  85. package/src/structures/DeveloperPortalApplication.js +520 -0
  86. package/src/structures/ForumChannel.js +10 -0
  87. package/src/structures/Guild.js +271 -135
  88. package/src/structures/GuildAuditLogs.js +5 -0
  89. package/src/structures/GuildChannel.js +2 -16
  90. package/src/structures/GuildFolder.js +75 -0
  91. package/src/structures/GuildMember.js +145 -27
  92. package/src/structures/Interaction.js +62 -1
  93. package/src/structures/InteractionResponse.js +114 -0
  94. package/src/structures/Invite.js +52 -35
  95. package/src/structures/Message.js +202 -222
  96. package/src/structures/MessageAttachment.js +0 -11
  97. package/src/structures/MessageButton.js +67 -1
  98. package/src/structures/MessageEmbed.js +1 -1
  99. package/src/structures/MessageMentions.js +2 -3
  100. package/src/structures/MessagePayload.js +46 -4
  101. package/src/structures/MessageReaction.js +1 -1
  102. package/src/structures/MessageSelectMenu.js +252 -1
  103. package/src/structures/Modal.js +180 -75
  104. package/src/structures/PartialGroupDMChannel.js +433 -0
  105. package/src/structures/Presence.js +2 -2
  106. package/src/structures/RichPresence.js +34 -14
  107. package/src/structures/Role.js +2 -18
  108. package/src/structures/SelectMenuInteraction.js +151 -2
  109. package/src/structures/Session.js +81 -0
  110. package/src/structures/Team.js +49 -0
  111. package/src/structures/TextInputComponent.js +70 -0
  112. package/src/structures/ThreadChannel.js +19 -0
  113. package/src/structures/User.js +345 -117
  114. package/src/structures/UserContextMenuInteraction.js +2 -2
  115. package/src/structures/VoiceState.js +39 -74
  116. package/src/structures/WebEmbed.js +52 -38
  117. package/src/structures/Webhook.js +11 -17
  118. package/src/structures/interfaces/Application.js +23 -146
  119. package/src/structures/interfaces/TextBasedChannel.js +256 -411
  120. package/src/util/ApplicationFlags.js +1 -1
  121. package/src/util/Constants.js +284 -106
  122. package/src/util/Formatters.js +2 -16
  123. package/src/util/LimitedCollection.js +1 -1
  124. package/src/util/Options.js +68 -48
  125. package/src/util/Permissions.js +0 -5
  126. package/src/util/PurchasedFlags.js +0 -2
  127. package/src/util/RemoteAuth.js +356 -221
  128. package/src/util/Sweepers.js +1 -1
  129. package/src/util/Util.js +36 -76
  130. package/src/util/Voice.js +1456 -0
  131. package/src/util/arRPC/index.js +229 -0
  132. package/src/util/arRPC/process/detectable.json +1 -0
  133. package/src/util/arRPC/process/index.js +102 -0
  134. package/src/util/arRPC/process/native/index.js +5 -0
  135. package/src/util/arRPC/process/native/linux.js +37 -0
  136. package/src/util/arRPC/process/native/win32.js +25 -0
  137. package/src/util/arRPC/transports/ipc.js +281 -0
  138. package/src/util/arRPC/transports/websocket.js +128 -0
  139. package/typings/enums.d.ts +73 -18
  140. package/typings/index.d.ts +1249 -897
  141. package/typings/rawDataTypes.d.ts +9 -68
  142. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +0 -78
  143. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +0 -12
  144. package/src/managers/UserNoteManager.js +0 -53
  145. package/src/structures/GroupDMChannel.js +0 -387
  146. package/src/util/AttachmentFlags.js +0 -38
  147. package/src/util/InviteFlags.js +0 -29
  148. package/src/util/RoleFlags.js +0 -37
@@ -2,15 +2,24 @@
2
2
 
3
3
  const { setTimeout } = require('node:timers');
4
4
  const BaseMessageComponent = require('./BaseMessageComponent');
5
- const { InteractionTypes, Events } = require('../util/Constants');
5
+ const User = require('./User');
6
6
  const SnowflakeUtil = require('../util/SnowflakeUtil');
7
+ const Util = require('../util/Util');
7
8
 
8
9
  /**
9
10
  * Represents a modal (form) to be shown in response to an interaction
10
11
  */
11
12
  class Modal {
12
13
  /**
13
- * @param {Object} data Modal to clone or raw data
14
+ * @typedef {Object} ModalOptions
15
+ * @property {string} [customId] A unique string to be sent in the interaction when clicked
16
+ * @property {string} [title] The title to be displayed on this modal
17
+ * @property {Array<(MessageActionRow|MessageActionRowOptions)>} [components]
18
+ * Action rows containing interactive components for the modal (text input components)
19
+ */
20
+
21
+ /**
22
+ * @param {Modal|ModalOptions} data Modal to clone or raw data
14
23
  * @param {Client} client The client constructing this Modal, if provided
15
24
  */
16
25
  constructor(data = {}, client = null) {
@@ -24,69 +33,106 @@ class Modal {
24
33
  * A unique string to be sent in the interaction when submitted
25
34
  * @type {?string}
26
35
  */
27
- this.customId = data.custom_id;
36
+ this.customId = data.custom_id ?? data.customId ?? null;
28
37
 
29
38
  /**
30
39
  * The title to be displayed on this modal
31
40
  * @type {?string}
32
41
  */
33
- this.title = data.title;
42
+ this.title = data.title ?? null;
34
43
 
35
44
  /**
36
45
  * Timestamp (Discord epoch) of when this modal was created
37
- * @type {Snowflake}
46
+ * @type {?Snowflake}
38
47
  */
39
- this.nonce = data.nonce;
48
+ this.nonce = data.nonce ?? null;
40
49
 
41
50
  /**
42
51
  * ID slash / button / menu when modal is displayed
43
- * @type {Snowflake}
52
+ * @type {?Snowflake}
44
53
  */
45
- this.id = data.id;
54
+ this.id = data.id ?? null;
46
55
 
47
56
  /**
48
57
  * Application sending the modal
49
- * @type {Snowflake}
58
+ * @type {?Object}
50
59
  */
51
- this.applicationId = data.application.id;
60
+ this.application = data.application
61
+ ? {
62
+ ...data.application,
63
+ bot: data.application.bot ? new User(client, data.application.bot, data.application) : null,
64
+ }
65
+ : null;
52
66
 
53
- /**
54
- * The id of the channel the message was sent in
55
- * @type {Snowflake}
56
- */
57
- this.channelId = data.channel_id;
58
-
59
- Object.defineProperty(this, 'client', {
60
- value: client,
61
- writable: false,
62
- });
67
+ this.client = client;
63
68
  }
64
69
 
65
70
  /**
66
- * The id of the guild the message was sent in, if any
67
- * @type {?Snowflake}
71
+ * Get Interaction Response
72
+ * @type {?InteractionResponse}
68
73
  * @readonly
69
74
  */
70
- get guildId() {
71
- return this.client.channels.cache.get(this.channelId)?.guildId || null;
75
+ get sendFromInteraction() {
76
+ if (this.id && this.nonce && this.client) {
77
+ const cache = this.client._interactionCache.get(this.nonce);
78
+ const channel = cache.guildId
79
+ ? this.client.guilds.cache.get(cache.guildId)?.channels.cache.get(cache.channelId)
80
+ : this.client.channels.cache.get(cache.channelId);
81
+ return channel.interactions.cache.get(this.id);
82
+ }
83
+ return null;
72
84
  }
73
85
 
74
86
  /**
75
- * The channel that the message was sent in
76
- * @type {TextBasedChannels}
77
- * @readonly
87
+ * Adds components to the modal.
88
+ * @param {...MessageActionRowResolvable[]} components The components to add
89
+ * @returns {Modal}
78
90
  */
79
- get channel() {
80
- return this.client.channels.resolve(this.channelId);
91
+ addComponents(...components) {
92
+ this.components.push(...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
93
+ return this;
81
94
  }
82
95
 
83
96
  /**
84
- * The guild the message was sent in (if in a guild channel)
85
- * @type {?Guild}
86
- * @readonly
97
+ * Sets the components of the modal.
98
+ * @param {...MessageActionRowResolvable[]} components The components to set
99
+ * @returns {Modal}
100
+ */
101
+ setComponents(...components) {
102
+ this.spliceComponents(0, this.components.length, components);
103
+ return this;
104
+ }
105
+
106
+ /**
107
+ * Sets the custom id for this modal
108
+ * @param {string} customId A unique string to be sent in the interaction when submitted
109
+ * @returns {Modal}
110
+ */
111
+ setCustomId(customId) {
112
+ this.customId = Util.verifyString(customId, RangeError, 'MODAL_CUSTOM_ID');
113
+ return this;
114
+ }
115
+
116
+ /**
117
+ * Removes, replaces, and inserts components in the modal.
118
+ * @param {number} index The index to start at
119
+ * @param {number} deleteCount The number of components to remove
120
+ * @param {...MessageActionRowResolvable[]} [components] The replacing components
121
+ * @returns {Modal}
87
122
  */
88
- get guild() {
89
- return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
123
+ spliceComponents(index, deleteCount, ...components) {
124
+ this.components.splice(index, deleteCount, ...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
125
+ return this;
126
+ }
127
+
128
+ /**
129
+ * Sets the title of this modal
130
+ * @param {string} title The title to be displayed on this modal
131
+ * @returns {Modal}
132
+ */
133
+ setTitle(title) {
134
+ this.title = Util.verifyString(title, RangeError, 'MODAL_TITLE');
135
+ return this;
90
136
  }
91
137
 
92
138
  toJSON() {
@@ -98,77 +144,136 @@ class Modal {
98
144
  };
99
145
  }
100
146
 
147
+ /**
148
+ * @typedef {Object} TextInputComponentReplyData
149
+ * @property {string} [customId] TextInputComponent custom id
150
+ * @property {string} [value] TextInputComponent value
151
+ */
152
+
153
+ /**
154
+ * @typedef {Object} ModalReplyData
155
+ * @property {?GuildResolvable} [guild] Guild to send the modal to
156
+ * @property {?TextChannelResolvable} [channel] User to send the modal to
157
+ * @property {?TextInputComponentReplyData[]} [data] Reply data
158
+ */
159
+
101
160
  /**
102
161
  * Reply to this modal with data. (Event only)
103
- * @returns {Promise<Message|Modal>}
162
+ * @param {ModalReplyData} data Data to send with the modal
163
+ * @returns {Promise<InteractionResponse>}
104
164
  * @example
105
165
  * client.on('interactionModalCreate', modal => {
106
- * // Modal > ActionRow > TextInput
107
- * modal.components[0].components[0].setValue('1+1');
108
- * modal.components[1].components[0].setValue('hello');
109
- * modal.reply();
166
+ * // 1.
167
+ * modal.reply({
168
+ * data: [
169
+ * {
170
+ * customId: 'code',
171
+ * value: '1+1'
172
+ * }, {
173
+ * customId: 'message',
174
+ * value: 'hello'
175
+ * }
176
+ * ],
177
+ * channel: 'id', // optional
178
+ * guild: 'id', // optional
179
+ * })
180
+ * // or 2.
181
+ * modal.components[0].components[0].setValue('1+1');
182
+ * modal.components[1].components[0].setValue('hello');
183
+ * modal.reply();
110
184
  * })
111
185
  */
112
- reply() {
113
- if (!this.applicationId || !this.client || !this.channelId) throw new Error('Modal cannot reply');
186
+ async reply(data = {}) {
187
+ if (!this.application) throw new Error('Modal cannot reply (Missing Application)');
188
+ const data_cache = this.sendFromInteraction;
189
+ const guild = this.client.guilds.resolveId(data?.guild) || data_cache.guildId || null;
190
+ const channel = this.client.channels.resolveId(data?.channel) || data_cache.channelId;
191
+ if (!channel) throw new Error('Modal cannot reply (Missing data)');
192
+ // Add data to components
193
+ // this.components = [ MessageActionRow.components = [ TextInputComponent ] ]
194
+ // 5 MessageActionRow / Modal, 1 TextInputComponent / 1 MessageActionRow
195
+ if (Array.isArray(data?.data) && data?.data?.length > 0) {
196
+ for (let i = 0; i < this.components.length; i++) {
197
+ const value = data.data.find(d => d.customId == this.components[i].components[0].customId);
198
+ if (this.components[i].components[0].required == true && !value) {
199
+ throw new Error(
200
+ 'MODAL_REQUIRED_FIELD_MISSING\n' +
201
+ `Required fieldId ${this.components[i].components[0].customId} missing value`,
202
+ );
203
+ }
204
+ if (value) {
205
+ if (value?.value?.includes('\n') && this.components[i].components[0].style == 'SHORT') {
206
+ throw new Error(
207
+ 'MODAL_REPLY_DATA_INVALID\n' +
208
+ `value must be a single line, got multiple lines [Custom ID: ${value.customId}]`,
209
+ );
210
+ }
211
+ this.components[i].components[0].setValue(value.value);
212
+ }
213
+ }
214
+ }
114
215
  // Get Object
115
216
  const dataFinal = this.toJSON();
116
217
  dataFinal.components = dataFinal.components
117
218
  .map(c => {
118
- c.components[0] = {
119
- type: c.components[0].type,
120
- value: c.components[0].value,
121
- custom_id: c.components[0].custom_id,
122
- };
219
+ delete c.components[0].max_length;
220
+ delete c.components[0].min_length;
221
+ delete c.components[0].required;
222
+ delete c.components[0].placeholder;
223
+ delete c.components[0].label;
224
+ delete c.components[0].style;
123
225
  return c;
124
226
  })
125
- .filter(c => typeof c.components[0].value == 'string');
227
+ .filter(c => c.components[0].value && c.components[0].value !== '');
126
228
  delete dataFinal.title;
127
229
  const nonce = SnowflakeUtil.generate();
128
230
  const postData = {
129
- type: InteractionTypes.MODAL_SUBMIT, // Modal
130
- application_id: this.applicationId,
131
- guild_id: this.guildId,
132
- channel_id: this.channelId,
231
+ type: 5, // Modal
232
+ application_id: this.application.id,
233
+ guild_id: guild || null,
234
+ channel_id: channel,
133
235
  data: dataFinal,
134
236
  nonce,
135
- session_id: this.client.sessionId,
237
+ session_id: this.client.session_id,
136
238
  };
137
- this.client.api.interactions.post({
239
+ await this.client.api.interactions.post({
138
240
  data: postData,
139
241
  });
242
+ this.client._interactionCache.set(nonce, {
243
+ channelId: channel,
244
+ guildId: guild,
245
+ metadata: postData,
246
+ });
140
247
  return new Promise((resolve, reject) => {
141
- const timeoutMs = 5_000;
142
- // Waiting for MsgCreate / ModalCreate
143
248
  const handler = data => {
144
- if (data.nonce !== nonce) return;
249
+ timeout.refresh();
250
+ if (data.metadata?.nonce !== nonce) return;
145
251
  clearTimeout(timeout);
146
- this.client.removeListener(Events.MESSAGE_CREATE, handler);
147
- this.client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
252
+ this.client.removeListener('interactionResponse', handler);
148
253
  this.client.decrementMaxListeners();
149
- resolve(data);
254
+ if (data.status) {
255
+ resolve(data.metadata);
256
+ } else {
257
+ reject(
258
+ new Error('INTERACTION_ERROR', {
259
+ cause: data,
260
+ }),
261
+ );
262
+ }
150
263
  };
151
264
  const timeout = setTimeout(() => {
152
- this.client.removeListener(Events.MESSAGE_CREATE, handler);
153
- this.client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
265
+ this.client.removeListener('interactionResponse', handler);
154
266
  this.client.decrementMaxListeners();
155
- reject(new Error('INTERACTION_FAILED'));
156
- }, timeoutMs).unref();
267
+ reject(
268
+ new Error('INTERACTION_TIMEOUT', {
269
+ cause: postData,
270
+ }),
271
+ );
272
+ }, this.client.options.interactionTimeout).unref();
157
273
  this.client.incrementMaxListeners();
158
- this.client.on(Events.MESSAGE_CREATE, handler);
159
- this.client.on(Events.INTERACTION_MODAL_CREATE, handler);
274
+ this.client.on('interactionResponse', handler);
160
275
  });
161
276
  }
162
-
163
- // TypeScript
164
- /**
165
- * Check data
166
- * @type {boolean}
167
- * @readonly
168
- */
169
- get isMessage() {
170
- return false;
171
- }
172
277
  }
173
278
 
174
279
  module.exports = Modal;