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
@@ -2,24 +2,15 @@
2
2
 
3
3
  const { setTimeout } = require('node:timers');
4
4
  const BaseMessageComponent = require('./BaseMessageComponent');
5
- const User = require('./User');
5
+ const { InteractionTypes, Events } = require('../util/Constants');
6
6
  const SnowflakeUtil = require('../util/SnowflakeUtil');
7
- const Util = require('../util/Util');
8
7
 
9
8
  /**
10
9
  * Represents a modal (form) to be shown in response to an interaction
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,69 @@ 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
- }
85
-
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
- }
53
+ /**
54
+ * The id of the channel the message was sent in
55
+ * @type {Snowflake}
56
+ */
57
+ this.channelId = data.channel_id;
95
58
 
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;
59
+ Object.defineProperty(this, 'client', {
60
+ value: client,
61
+ writable: false,
62
+ });
104
63
  }
105
64
 
106
65
  /**
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}
66
+ * The id of the guild the message was sent in, if any
67
+ * @type {?Snowflake}
68
+ * @readonly
110
69
  */
111
- setCustomId(customId) {
112
- this.customId = Util.verifyString(customId, RangeError, 'MODAL_CUSTOM_ID');
113
- return this;
70
+ get guildId() {
71
+ return this.client.channels.cache.get(this.channelId)?.guildId || null;
114
72
  }
115
73
 
116
74
  /**
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}
75
+ * The channel that the message was sent in
76
+ * @type {TextBasedChannels}
77
+ * @readonly
122
78
  */
123
- spliceComponents(index, deleteCount, ...components) {
124
- this.components.splice(index, deleteCount, ...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
125
- return this;
79
+ get channel() {
80
+ return this.client.channels.resolve(this.channelId);
126
81
  }
127
82
 
128
83
  /**
129
- * Sets the title of this modal
130
- * @param {string} title The title to be displayed on this modal
131
- * @returns {Modal}
84
+ * The guild the message was sent in (if in a guild channel)
85
+ * @type {?Guild}
86
+ * @readonly
132
87
  */
133
- setTitle(title) {
134
- this.title = Util.verifyString(title, RangeError, 'MODAL_TITLE');
135
- return this;
88
+ get guild() {
89
+ return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
136
90
  }
137
91
 
138
92
  toJSON() {
@@ -144,136 +98,77 @@ class Modal {
144
98
  };
145
99
  }
146
100
 
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
101
  /**
161
102
  * Reply to this modal with data. (Event only)
162
- * @param {ModalReplyData} data Data to send with the modal
163
- * @returns {Promise<InteractionResponse>}
103
+ * @returns {Promise<Message|Modal>}
164
104
  * @example
165
105
  * 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();
106
+ * // Modal > ActionRow > TextInput
107
+ * modal.components[0].components[0].setValue('1+1');
108
+ * modal.components[1].components[0].setValue('hello');
109
+ * modal.reply();
184
110
  * })
185
111
  */
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
- }
112
+ reply() {
113
+ if (!this.applicationId || !this.client || !this.channelId) throw new Error('Modal cannot reply');
215
114
  // Get Object
216
115
  const dataFinal = this.toJSON();
217
116
  dataFinal.components = dataFinal.components
218
117
  .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;
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
+ };
225
123
  return c;
226
124
  })
227
- .filter(c => c.components[0].value && c.components[0].value !== '');
125
+ .filter(c => typeof c.components[0].value == 'string');
228
126
  delete dataFinal.title;
229
127
  const nonce = SnowflakeUtil.generate();
230
128
  const postData = {
231
- type: 5, // Modal
232
- application_id: this.application.id,
233
- guild_id: guild || null,
234
- channel_id: channel,
129
+ type: InteractionTypes.MODAL_SUBMIT, // Modal
130
+ application_id: this.applicationId,
131
+ guild_id: this.guildId,
132
+ channel_id: this.channelId,
235
133
  data: dataFinal,
236
134
  nonce,
237
- session_id: this.client.session_id,
135
+ session_id: this.client.sessionId,
238
136
  };
239
- await this.client.api.interactions.post({
137
+ this.client.api.interactions.post({
240
138
  data: postData,
241
139
  });
242
- this.client._interactionCache.set(nonce, {
243
- channelId: channel,
244
- guildId: guild,
245
- metadata: postData,
246
- });
247
140
  return new Promise((resolve, reject) => {
141
+ const timeoutMs = 5_000;
142
+ // Waiting for MsgCreate / ModalCreate
248
143
  const handler = data => {
249
- timeout.refresh();
250
- if (data.metadata?.nonce !== nonce) return;
144
+ if (data.nonce !== nonce) return;
251
145
  clearTimeout(timeout);
252
- this.client.removeListener('interactionResponse', handler);
146
+ this.client.removeListener(Events.MESSAGE_CREATE, handler);
147
+ this.client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
253
148
  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
- }
149
+ resolve(data);
263
150
  };
264
151
  const timeout = setTimeout(() => {
265
- this.client.removeListener('interactionResponse', handler);
152
+ this.client.removeListener(Events.MESSAGE_CREATE, handler);
153
+ this.client.removeListener(Events.INTERACTION_MODAL_CREATE, handler);
266
154
  this.client.decrementMaxListeners();
267
- reject(
268
- new Error('INTERACTION_TIMEOUT', {
269
- cause: postData,
270
- }),
271
- );
272
- }, this.client.options.interactionTimeout).unref();
155
+ reject(new Error('INTERACTION_FAILED'));
156
+ }, timeoutMs).unref();
273
157
  this.client.incrementMaxListeners();
274
- this.client.on('interactionResponse', handler);
158
+ this.client.on(Events.MESSAGE_CREATE, handler);
159
+ this.client.on(Events.INTERACTION_MODAL_CREATE, handler);
275
160
  });
276
161
  }
162
+
163
+ // TypeScript
164
+ /**
165
+ * Check data
166
+ * @type {boolean}
167
+ * @readonly
168
+ */
169
+ get isMessage() {
170
+ return false;
171
+ }
277
172
  }
278
173
 
279
174
  module.exports = Modal;
@@ -90,8 +90,8 @@ class Presence extends Base {
90
90
 
91
91
  if ('activities' in data) {
92
92
  /**
93
- * The activities of this presence
94
- * @type {Activity[]}
93
+ * The activities of this presence (Always `Activity[]` if not ClientUser)
94
+ * @type {Activity[]|CustomStatus[]|RichPresence[]|SpotifyRPC[]}
95
95
  */
96
96
  this.activities = data.activities.map(activity => {
97
97
  if (fromClient === true) {
@@ -1,11 +1,8 @@
1
1
  'use strict';
2
+ const { randomUUID } = require('node:crypto');
2
3
  const { ActivityTypes } = require('../util/Constants');
3
4
  const { resolvePartialEmoji } = require('../util/Util');
4
5
 
5
- // eslint-disable-next-line
6
- const getUUID = () =>
7
- ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, a => (a ^ ((Math.random() * 16) >> (a / 4))).toString(16));
8
- // Function check url valid (ok copilot)
9
6
  // eslint-disable-next-line
10
7
  const checkUrl = url => {
11
8
  try {
@@ -183,9 +180,17 @@ class RichPresence {
183
180
  this.buttons = data.buttons;
184
181
  this.metadata = data.metadata;
185
182
  }
183
+ /**
184
+ * @typedef {string} RichPresenceImage
185
+ * Support:
186
+ * - cdn.discordapp.com
187
+ * - media.discordapp.net
188
+ * - Asset ID (From https://discord.com/api/v9/oauth2/applications/:id/assets)
189
+ * - ExternalAssets (mp:external/)
190
+ */
186
191
  /**
187
192
  * Set the large image of this activity
188
- * @param {?any} image The large image asset's id
193
+ * @param {?RichPresenceImage} image The large image asset's id
189
194
  * @returns {RichPresence}
190
195
  */
191
196
  setAssetsLargeImage(image) {
@@ -201,14 +206,7 @@ class RichPresence {
201
206
  .replace('http://media.discordapp.net/', 'mp:');
202
207
  //
203
208
  if (!image.startsWith('mp:') && !this.ipc) {
204
- throw new Error(
205
- 'INVALID_URL',
206
- `
207
- If you want to set the URL directly, it should be the Discord URL (cdn.discordapp.com | media.discordapp.net)
208
- Or follow these instructions:
209
- https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichPresence.md#method-3-custom-url-2378
210
- `,
211
- );
209
+ throw new Error('INVALID_URL');
212
210
  }
213
211
  } else if (/^[0-9]{17,19}$/.test(image)) {
214
212
  // ID Assets
@@ -222,7 +220,7 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
222
220
  }
223
221
  /**
224
222
  * Set the small image of this activity
225
- * @param {?any} image The small image asset's id
223
+ * @param {?RichPresenceImage} image The small image asset's id
226
224
  * @returns {RichPresence}
227
225
  */
228
226
  setAssetsSmallImage(image) {
@@ -238,14 +236,7 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
238
236
  .replace('http://media.discordapp.net/', 'mp:');
239
237
  //
240
238
  if (!image.startsWith('mp:') && !this.ipc) {
241
- throw new Error(
242
- 'INVALID_URL',
243
- `
244
- If you want to set the URL directly, it should be the Discord URL (cdn.discordapp.com | media.discordapp.net)
245
- Or follow these instructions:
246
- https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichPresence.md#method-3-custom-url-2378
247
- `,
248
- );
239
+ throw new Error('INVALID_URL');
249
240
  }
250
241
  } else if (/^[0-9]{17,19}$/.test(image)) {
251
242
  // ID Assets
@@ -351,7 +342,7 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
351
342
  if (!party.max || typeof party.max != 'number') throw new Error('Party must have max number');
352
343
  if (!party.current || typeof party.current != 'number') throw new Error('Party must have current');
353
344
  if (party.current > party.max) throw new Error('Party current must be less than max number');
354
- if (!party.id || typeof party.id != 'string') party.id = getUUID();
345
+ if (!party.id || typeof party.id != 'string') party.id = randomUUID();
355
346
  this.party = {
356
347
  size: [party.current, party.max],
357
348
  id: party.id,
@@ -488,16 +479,6 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
488
479
  }
489
480
  }
490
481
 
491
- /**
492
- * Get random UUID string (Util)
493
- * @returns {string}
494
- */
495
- static getUUID() {
496
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, a =>
497
- (a ^ ((Math.random() * 16) >> (a / 4))).toString(16),
498
- );
499
- }
500
-
501
482
  /**
502
483
  * Get Assets from a RichPresence (Util)
503
484
  * @param {Client} client Discord Client
@@ -718,5 +699,4 @@ module.exports = {
718
699
  CustomStatus,
719
700
  RichPresence,
720
701
  SpotifyRPC,
721
- getUUID,
722
702
  };
@@ -4,6 +4,7 @@ const process = require('node:process');
4
4
  const Base = require('./Base');
5
5
  const { Error } = require('../errors');
6
6
  const Permissions = require('../util/Permissions');
7
+ const RoleFlags = require('../util/RoleFlags');
7
8
  const SnowflakeUtil = require('../util/SnowflakeUtil');
8
9
 
9
10
  let deprecationEmittedForComparePositions = false;
@@ -142,6 +143,16 @@ class Role extends Base {
142
143
  this.tags.guildConnections = true;
143
144
  }
144
145
  }
146
+
147
+ if ('flags' in data) {
148
+ /**
149
+ * The flags of this role
150
+ * @type {Readonly<RoleFlags>}
151
+ */
152
+ this.flags = new RoleFlags(data.flags).freeze();
153
+ } else {
154
+ this.flags ??= new RoleFlags().freeze();
155
+ }
145
156
  }
146
157
 
147
158
  /**
@@ -228,8 +239,13 @@ class Role extends Base {
228
239
  * @readonly
229
240
  */
230
241
  get position() {
231
- const sorted = this.guild._sortedRoles();
232
- return [...sorted.values()].indexOf(sorted.get(this.id));
242
+ let count = 0;
243
+ for (const role of this.guild.roles.cache.values()) {
244
+ if (this.rawPosition > role.rawPosition) count++;
245
+ else if (this.rawPosition === role.rawPosition && BigInt(this.id) < BigInt(role.id)) count++;
246
+ }
247
+
248
+ return count;
233
249
  }
234
250
 
235
251
  /**
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const { Collection } = require('@discordjs/collection');
4
3
  const MessageComponentInteraction = require('./MessageComponentInteraction');
5
- const { Events } = require('../util/Constants');
6
4
 
7
5
  /**
8
- * Represents any select menu interaction.
6
+ * Represents a select menu interaction.
9
7
  * @extends {MessageComponentInteraction}
10
8
  */
11
9
  class SelectMenuInteraction extends MessageComponentInteraction {
@@ -20,151 +18,4 @@ class SelectMenuInteraction extends MessageComponentInteraction {
20
18
  }
21
19
  }
22
20
 
23
- module.exports.SelectMenuInteraction = SelectMenuInteraction;
24
-
25
- /**
26
- * Represents a CHANNEL_SELECT interaction.
27
- * @extends {SelectMenuInteraction}
28
- */
29
- class ChannelSelectInteraction extends SelectMenuInteraction {
30
- constructor(client, data) {
31
- super(client, data);
32
-
33
- const { channels } = data.data.resolved ?? {};
34
-
35
- /**
36
- * Collection of the selected channels
37
- * @type {Collection<Snowflake, Channel|APIChannel>}
38
- */
39
- this.channels = new Collection();
40
- for (const channel of Object.values(channels)) {
41
- this.channel.set(channel.id, this.client.channels._add(channel));
42
- }
43
- }
44
- }
45
-
46
- module.exports.ChannelSelectInteraction = ChannelSelectInteraction;
47
-
48
- /**
49
- * Represents a ROLE_SELECT interaction.
50
- * @extends {SelectMenuInteraction}
51
- */
52
- class RoleSelectInteraction extends SelectMenuInteraction {
53
- constructor(client, data) {
54
- super(client, data);
55
-
56
- const { roles } = data.data.resolved ?? {};
57
-
58
- /**
59
- * Collection of the selected roles
60
- * @type {Collection<Snowflake, Role|APIRole>}
61
- */
62
- this.roles = new Collection();
63
- for (const role of Object.values(roles)) {
64
- this.roles.set(role.id, this.guild?.roles._add(role) ?? role);
65
- }
66
- }
67
- }
68
-
69
- module.exports.RoleSelectInteraction = RoleSelectInteraction;
70
-
71
- /**
72
- * Represents a USER_SELECT interaction.
73
- * @extends {SelectMenuInteraction}
74
- */
75
- class UserSelectInteraction extends SelectMenuInteraction {
76
- constructor(client, data) {
77
- super(client, data);
78
-
79
- const { members, users } = data.data.resolved ?? {};
80
-
81
- /**
82
- * Collection of the selected users
83
- * @type {Collection<Snowflake, User>}
84
- */
85
- this.users = new Collection();
86
- for (const user of Object.values(users)) {
87
- this.users.set(user.id, this.client.users._add(user));
88
- }
89
-
90
- if (members) {
91
- /**
92
- * Collection of the selected members
93
- * @type {Collection<Snowflake, GuildMember|APIGuildMember>}
94
- */
95
- this.members = new Collection();
96
- for (const [id, member] of Object.entries(members)) {
97
- const user = users[id];
98
- if (!user) {
99
- this.client.emit(Events.DEBUG, `[SelectMenuInteraction] Received a member without a user, skipping ${id}`);
100
- continue;
101
- }
102
- this.members.set(id, this.guild?.members._add({ user, ...member }) ?? { user, ...member });
103
- }
104
- }
105
- }
106
- }
107
-
108
- module.exports.UserSelectInteraction = UserSelectInteraction;
109
-
110
- /**
111
- * Represents a MENTIONABLE_SELECT interaction.
112
- * @extends {SelectMenuInteraction}
113
- */
114
- class MentionableSelectInteraction extends SelectMenuInteraction {
115
- constructor(client, data) {
116
- super(client, data);
117
-
118
- const { members, users, roles, channels } = data.data.resolved ?? {};
119
-
120
- if (channels) {
121
- /**
122
- * Collection of the selected channels
123
- * @type {Collection<Snowflake, Channel|APIChannel>}
124
- */
125
- this.channels = new Collection();
126
- for (const channel of Object.values(channels)) {
127
- this.channels.set(channel.id, this.client?.channels._add(channel) ?? channel);
128
- }
129
- }
130
-
131
- if (members) {
132
- /**
133
- * Collection of the selected members
134
- * @type {Collection<Snowflake, GuildMember|APIGuildMember>}
135
- */
136
- this.members = new Collection();
137
- for (const [id, member] of Object.entries(members)) {
138
- const user = users[id];
139
- if (!user) {
140
- this.client.emit(Events.DEBUG, `[SelectMenuInteraction] Received a member without a user, skipping ${id}`);
141
- continue;
142
- }
143
- this.members.set(id, this.guild?.members._add({ user, ...member }) ?? { user, ...member });
144
- }
145
- }
146
-
147
- if (roles) {
148
- /**
149
- * Collection of the selected roles
150
- * @type {Collection<Snowflake, Role|APIRole>}
151
- */
152
- this.roles = new Collection();
153
- for (const role of Object.values(roles)) {
154
- this.roles.set(role.id, this.guild?.roles._add(role) ?? role);
155
- }
156
- }
157
-
158
- if (users) {
159
- /**
160
- * Collection of the selected users
161
- * @type {Collection<Snowflake, User>}
162
- */
163
- this.users = new Collection();
164
- for (const user of Object.values(users)) {
165
- this.users.set(user.id, this.client.users._add(user));
166
- }
167
- }
168
- }
169
- }
170
- module.exports.MentionableSelectInteraction = MentionableSelectInteraction;
21
+ module.exports = SelectMenuInteraction;