djs-selfbot-v13 3.1.7 → 3.2.2

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 (155) hide show
  1. package/README.md +18 -35
  2. package/package.json +85 -100
  3. package/src/client/BaseClient.js +3 -4
  4. package/src/client/Client.js +249 -530
  5. package/src/client/actions/Action.js +18 -13
  6. package/src/client/actions/ActionsManager.js +7 -1
  7. package/src/client/actions/AutoModerationActionExecution.js +1 -0
  8. package/src/client/actions/AutoModerationRuleCreate.js +1 -0
  9. package/src/client/actions/AutoModerationRuleDelete.js +1 -0
  10. package/src/client/actions/AutoModerationRuleUpdate.js +1 -0
  11. package/src/client/actions/GuildMemberRemove.js +0 -1
  12. package/src/client/actions/GuildMemberUpdate.js +0 -1
  13. package/src/client/actions/MessageCreate.js +0 -4
  14. package/src/client/actions/PresenceUpdate.js +17 -16
  15. package/src/client/websocket/WebSocketManager.js +11 -31
  16. package/src/client/websocket/WebSocketShard.js +39 -38
  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 +16 -13
  21. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  22. package/src/client/websocket/handlers/GUILD_CREATE.js +19 -13
  23. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +0 -1
  24. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +1 -0
  25. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +22 -0
  26. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +12 -0
  27. package/src/client/websocket/handlers/READY.js +90 -140
  28. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +7 -5
  29. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +7 -5
  30. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +32 -9
  31. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +2 -8
  32. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  33. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
  34. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +1 -5
  35. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  36. package/src/client/websocket/handlers/index.js +17 -20
  37. package/src/errors/Messages.js +25 -69
  38. package/src/index.js +13 -43
  39. package/src/managers/ApplicationCommandManager.js +9 -12
  40. package/src/managers/ApplicationCommandPermissionsManager.js +3 -11
  41. package/src/managers/ChannelManager.js +2 -3
  42. package/src/managers/ClientUserSettingManager.js +162 -280
  43. package/src/managers/GuildBanManager.js +47 -1
  44. package/src/managers/GuildChannelManager.js +2 -16
  45. package/src/managers/GuildForumThreadManager.js +24 -30
  46. package/src/managers/GuildManager.js +1 -1
  47. package/src/managers/GuildMemberManager.js +50 -222
  48. package/src/managers/GuildSettingManager.js +22 -15
  49. package/src/managers/MessageManager.js +42 -44
  50. package/src/managers/PermissionOverwriteManager.js +1 -1
  51. package/src/managers/ReactionUserManager.js +5 -5
  52. package/src/managers/RelationshipManager.js +83 -76
  53. package/src/managers/ThreadManager.js +12 -45
  54. package/src/managers/ThreadMemberManager.js +1 -1
  55. package/src/managers/UserManager.js +6 -10
  56. package/src/managers/UserNoteManager.js +53 -0
  57. package/src/rest/APIRequest.js +48 -20
  58. package/src/rest/DiscordAPIError.js +17 -16
  59. package/src/rest/RESTManager.js +1 -21
  60. package/src/rest/RequestHandler.js +35 -21
  61. package/src/structures/ApplicationCommand.js +19 -456
  62. package/src/structures/ApplicationRoleConnectionMetadata.js +3 -0
  63. package/src/structures/AutoModerationRule.js +5 -5
  64. package/src/structures/AutocompleteInteraction.js +1 -0
  65. package/src/structures/BaseGuildTextChannel.js +10 -12
  66. package/src/structures/BaseGuildVoiceChannel.js +16 -18
  67. package/src/structures/{Call.js → CallState.js} +17 -12
  68. package/src/structures/CategoryChannel.js +2 -0
  69. package/src/structures/Channel.js +2 -3
  70. package/src/structures/ClientPresence.js +20 -19
  71. package/src/structures/ClientUser.js +117 -338
  72. package/src/structures/ContextMenuInteraction.js +1 -1
  73. package/src/structures/DMChannel.js +29 -92
  74. package/src/structures/ForumChannel.js +0 -10
  75. package/src/structures/GroupDMChannel.js +387 -0
  76. package/src/structures/Guild.js +135 -271
  77. package/src/structures/GuildAuditLogs.js +0 -5
  78. package/src/structures/GuildChannel.js +16 -2
  79. package/src/structures/GuildMember.js +27 -145
  80. package/src/structures/Interaction.js +1 -62
  81. package/src/structures/Invite.js +35 -52
  82. package/src/structures/Message.js +220 -203
  83. package/src/structures/MessageAttachment.js +11 -0
  84. package/src/structures/MessageButton.js +1 -67
  85. package/src/structures/MessageEmbed.js +1 -1
  86. package/src/structures/MessageMentions.js +3 -2
  87. package/src/structures/MessagePayload.js +6 -46
  88. package/src/structures/MessagePoll.js +238 -0
  89. package/src/structures/MessageReaction.js +1 -1
  90. package/src/structures/MessageSelectMenu.js +1 -252
  91. package/src/structures/Modal.js +70 -188
  92. package/src/structures/Presence.js +787 -129
  93. package/src/structures/Role.js +18 -2
  94. package/src/structures/SelectMenuInteraction.js +2 -151
  95. package/src/structures/Team.js +0 -49
  96. package/src/structures/TextInputComponent.js +0 -70
  97. package/src/structures/ThreadChannel.js +0 -19
  98. package/src/structures/User.js +145 -339
  99. package/src/structures/UserContextMenuInteraction.js +2 -2
  100. package/src/structures/VoiceState.js +74 -39
  101. package/src/structures/WebEmbed.js +38 -52
  102. package/src/structures/Webhook.js +17 -11
  103. package/src/structures/interfaces/Application.js +146 -23
  104. package/src/structures/interfaces/TextBasedChannel.js +409 -256
  105. package/src/util/ApplicationFlags.js +1 -1
  106. package/src/util/AttachmentFlags.js +38 -0
  107. package/src/util/Constants.js +120 -285
  108. package/src/util/Formatters.js +16 -2
  109. package/src/util/InviteFlags.js +29 -0
  110. package/src/util/LimitedCollection.js +1 -1
  111. package/src/util/Options.js +48 -74
  112. package/src/util/Permissions.js +15 -0
  113. package/src/util/PurchasedFlags.js +2 -0
  114. package/src/util/RemoteAuth.js +221 -356
  115. package/src/util/RoleFlags.js +37 -0
  116. package/src/util/Sweepers.js +1 -1
  117. package/src/util/Util.js +158 -32
  118. package/typings/enums.d.ts +24 -73
  119. package/typings/index.d.ts +978 -1288
  120. package/typings/rawDataTypes.d.ts +68 -9
  121. package/src/client/actions/InteractionCreate.js +0 -115
  122. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +0 -23
  123. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +0 -11
  124. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +0 -55
  125. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  126. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  127. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  128. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  129. package/src/client/websocket/handlers/INTERACTION_CREATE.js +0 -16
  130. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +0 -18
  131. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +0 -30
  132. package/src/client/websocket/handlers/MESSAGE_ACK.js +0 -16
  133. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  134. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  135. package/src/managers/DeveloperPortalManager.js +0 -104
  136. package/src/managers/GuildApplicationCommandManager.js +0 -28
  137. package/src/managers/GuildFolderManager.js +0 -24
  138. package/src/managers/SessionManager.js +0 -57
  139. package/src/rest/CaptchaSolver.js +0 -132
  140. package/src/structures/ClientApplication.js +0 -204
  141. package/src/structures/DeveloperPortalApplication.js +0 -520
  142. package/src/structures/GuildFolder.js +0 -75
  143. package/src/structures/InteractionResponse.js +0 -114
  144. package/src/structures/PartialGroupDMChannel.js +0 -433
  145. package/src/structures/RichPresence.js +0 -722
  146. package/src/structures/Session.js +0 -81
  147. package/src/util/Voice.js +0 -1456
  148. package/src/util/arRPC/index.js +0 -229
  149. package/src/util/arRPC/process/detectable.json +0 -1
  150. package/src/util/arRPC/process/index.js +0 -102
  151. package/src/util/arRPC/process/native/index.js +0 -5
  152. package/src/util/arRPC/process/native/linux.js +0 -37
  153. package/src/util/arRPC/process/native/win32.js +0 -25
  154. package/src/util/arRPC/transports/ipc.js +0 -281
  155. package/src/util/arRPC/transports/websocket.js +0 -128
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const { setTimeout } = require('node:timers');
4
3
  const BaseMessageComponent = require('./BaseMessageComponent');
5
- const User = require('./User');
4
+ const { InteractionTypes } = require('../util/Constants');
6
5
  const SnowflakeUtil = require('../util/SnowflakeUtil');
7
6
  const Util = require('../util/Util');
8
7
 
@@ -11,15 +10,7 @@ const Util = require('../util/Util');
11
10
  */
12
11
  class Modal {
13
12
  /**
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
13
+ * @param {Object} data Modal to clone or raw data
23
14
  * @param {Client} client The client constructing this Modal, if provided
24
15
  */
25
16
  constructor(data = {}, client = null) {
@@ -33,106 +24,75 @@ class Modal {
33
24
  * A unique string to be sent in the interaction when submitted
34
25
  * @type {?string}
35
26
  */
36
- this.customId = data.custom_id ?? data.customId ?? null;
27
+ this.customId = data.custom_id;
37
28
 
38
29
  /**
39
30
  * The title to be displayed on this modal
40
31
  * @type {?string}
41
32
  */
42
- this.title = data.title ?? null;
33
+ this.title = data.title;
43
34
 
44
35
  /**
45
36
  * Timestamp (Discord epoch) of when this modal was created
46
- * @type {?Snowflake}
37
+ * @type {Snowflake}
47
38
  */
48
- this.nonce = data.nonce ?? null;
39
+ this.nonce = data.nonce;
49
40
 
50
41
  /**
51
42
  * ID slash / button / menu when modal is displayed
52
- * @type {?Snowflake}
43
+ * @type {Snowflake}
53
44
  */
54
- this.id = data.id ?? null;
45
+ this.id = data.id;
55
46
 
56
47
  /**
57
48
  * Application sending the modal
58
- * @type {?Object}
49
+ * @type {Snowflake}
59
50
  */
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;
66
-
67
- this.client = client;
68
- }
51
+ this.applicationId = data.application.id;
69
52
 
70
- /**
71
- * Get Interaction Response
72
- * @type {?InteractionResponse}
73
- * @readonly
74
- */
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;
84
- }
53
+ /**
54
+ * The id of the channel the message was sent in
55
+ * @type {Snowflake}
56
+ */
57
+ this.channelId = data.channel_id;
85
58
 
86
- /**
87
- * Adds components to the modal.
88
- * @param {...MessageActionRowResolvable[]} components The components to add
89
- * @returns {Modal}
90
- */
91
- addComponents(...components) {
92
- this.components.push(...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
93
- return this;
94
- }
59
+ /**
60
+ * Whether this interaction has already been replied to
61
+ * @type {boolean}
62
+ */
63
+ this.replied = false;
95
64
 
96
- /**
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;
65
+ Object.defineProperty(this, 'client', {
66
+ value: client,
67
+ writable: false,
68
+ });
104
69
  }
105
70
 
106
71
  /**
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}
72
+ * The id of the guild the message was sent in, if any
73
+ * @type {?Snowflake}
74
+ * @readonly
110
75
  */
111
- setCustomId(customId) {
112
- this.customId = Util.verifyString(customId, RangeError, 'MODAL_CUSTOM_ID');
113
- return this;
76
+ get guildId() {
77
+ return this.client.channels.cache.get(this.channelId)?.guildId || null;
114
78
  }
115
79
 
116
80
  /**
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}
81
+ * The channel that the message was sent in
82
+ * @type {TextBasedChannels}
83
+ * @readonly
122
84
  */
123
- spliceComponents(index, deleteCount, ...components) {
124
- this.components.splice(index, deleteCount, ...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
125
- return this;
85
+ get channel() {
86
+ return this.client.channels.resolve(this.channelId);
126
87
  }
127
88
 
128
89
  /**
129
- * Sets the title of this modal
130
- * @param {string} title The title to be displayed on this modal
131
- * @returns {Modal}
90
+ * The guild the message was sent in (if in a guild channel)
91
+ * @type {?Guild}
92
+ * @readonly
132
93
  */
133
- setTitle(title) {
134
- this.title = Util.verifyString(title, RangeError, 'MODAL_TITLE');
135
- return this;
94
+ get guild() {
95
+ return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
136
96
  }
137
97
 
138
98
  toJSON() {
@@ -144,135 +104,57 @@ class Modal {
144
104
  };
145
105
  }
146
106
 
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
-
160
107
  /**
161
108
  * Reply to this modal with data. (Event only)
162
- * @param {ModalReplyData} data Data to send with the modal
163
- * @returns {Promise<InteractionResponse>}
109
+ * @returns {Promise<Message|Modal>}
164
110
  * @example
165
111
  * client.on('interactionModalCreate', modal => {
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();
112
+ * // Modal > ActionRow > TextInput
113
+ * modal.components[0].components[0].setValue('1+1');
114
+ * modal.components[1].components[0].setValue('hello');
115
+ * modal.reply();
184
116
  * })
185
117
  */
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
- }
118
+ reply() {
119
+ if (!this.applicationId || !this.client || !this.channelId || this.replied) throw new Error('Modal cannot reply');
215
120
  // Get Object
216
121
  const dataFinal = this.toJSON();
217
122
  dataFinal.components = dataFinal.components
218
123
  .map(c => {
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;
124
+ c.components[0] = {
125
+ type: c.components[0].type,
126
+ value: c.components[0].value,
127
+ custom_id: c.components[0].custom_id,
128
+ };
225
129
  return c;
226
130
  })
227
- .filter(c => c.components[0].value && c.components[0].value !== '');
131
+ .filter(c => typeof c.components[0].value == 'string');
228
132
  delete dataFinal.title;
229
133
  const nonce = SnowflakeUtil.generate();
230
134
  const postData = {
231
- type: 5, // Modal
232
- application_id: this.application.id,
233
- guild_id: guild || null,
234
- channel_id: channel,
135
+ type: InteractionTypes.MODAL_SUBMIT, // Modal
136
+ application_id: this.applicationId,
137
+ guild_id: this.guildId,
138
+ channel_id: this.channelId,
235
139
  data: dataFinal,
236
140
  nonce,
237
- session_id: this.client.session_id,
141
+ session_id: this.client.sessionId,
238
142
  };
239
- await this.client.api.interactions.post({
143
+ this.client.api.interactions.post({
240
144
  data: postData,
241
145
  });
242
- this.client._interactionCache.set(nonce, {
243
- channelId: channel,
244
- guildId: guild,
245
- metadata: postData,
246
- });
247
- return new Promise((resolve, reject) => {
248
- const handler = data => {
249
- timeout.refresh();
250
- if (data.metadata?.nonce !== nonce) return;
251
- clearTimeout(timeout);
252
- this.client.removeListener('interactionResponse', handler);
253
- this.client.decrementMaxListeners();
254
- if (data.status) {
255
- resolve(data.metadata);
256
- } else {
257
- reject(
258
- new Error('INTERACTION_ERROR', {
259
- cause: data,
260
- }),
261
- );
262
- }
263
- };
264
- const timeout = setTimeout(() => {
265
- this.client.removeListener('interactionResponse', handler);
266
- this.client.decrementMaxListeners();
267
- reject(
268
- new Error('INTERACTION_TIMEOUT', {
269
- cause: postData,
270
- }),
271
- );
272
- }, this.client.options.interactionTimeout).unref();
273
- this.client.incrementMaxListeners();
274
- this.client.on('interactionResponse', handler);
275
- });
146
+ this.replied = true;
147
+ return Util.createPromiseInteraction(this.client, nonce, 5_000, true, this);
148
+ }
149
+
150
+ // TypeScript
151
+ /**
152
+ * Check data
153
+ * @type {boolean}
154
+ * @readonly
155
+ */
156
+ get isMessage() {
157
+ return false;
276
158
  }
277
159
  }
278
160