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
@@ -25,7 +25,7 @@ class DiscordAPIError extends Error {
25
25
 
26
26
  /**
27
27
  * HTTP error code returned by Discord
28
- * @type {number | string}
28
+ * @type {number}
29
29
  */
30
30
  this.code = error.code;
31
31
 
@@ -35,21 +35,6 @@ class DiscordAPIError extends Error {
35
35
  */
36
36
  this.httpStatus = status;
37
37
 
38
- /**
39
- * @typedef {Object} Captcha
40
- * @property {Array<string>} captcha_key ['message']
41
- * @property {string} captcha_sitekey Captcha sitekey (hcaptcha)
42
- * @property {string} captcha_service hcaptcha
43
- * @property {string} [captcha_rqdata]
44
- * @property {string} [captcha_rqtoken]
45
- */
46
-
47
- /**
48
- * Captcha response data if the request requires a captcha
49
- * @type {Captcha | null}
50
- */
51
- this.captcha = error?.captcha_service ? error : null;
52
-
53
38
  /**
54
39
  * The data associated with the request that caused this error
55
40
  * @type {HTTPErrorData}
@@ -57,6 +42,7 @@ class DiscordAPIError extends Error {
57
42
  this.requestData = {
58
43
  json: request.options.data,
59
44
  files: request.options.files ?? [],
45
+ headers: request.options.headers,
60
46
  };
61
47
 
62
48
  /**
@@ -64,6 +50,21 @@ class DiscordAPIError extends Error {
64
50
  * @type {number}
65
51
  */
66
52
  this.retries = request.retries;
53
+
54
+ /**
55
+ * @typedef {Object} Captcha
56
+ * @property {Array<string>} captcha_key ['message']
57
+ * @property {string} captcha_sitekey Captcha sitekey (hcaptcha)
58
+ * @property {string} captcha_service hcaptcha
59
+ * @property {string} [captcha_rqdata]
60
+ * @property {string} [captcha_rqtoken]
61
+ */
62
+
63
+ /**
64
+ * Captcha response data if the request requires a captcha
65
+ * @type {Captcha | null}
66
+ */
67
+ this.captcha = error?.captcha_service ? error : null;
67
68
  }
68
69
 
69
70
  /**
@@ -4,7 +4,6 @@ const { setInterval } = require('node:timers');
4
4
  const { Collection } = require('@discordjs/collection');
5
5
  const APIRequest = require('./APIRequest');
6
6
  const routeBuilder = require('./APIRouter');
7
- const CaptchaSolver = require('./CaptchaSolver');
8
7
  const RequestHandler = require('./RequestHandler');
9
8
  const { Error } = require('../errors');
10
9
  const { Endpoints } = require('../util/Constants');
@@ -23,17 +22,6 @@ class RESTManager {
23
22
  this.handlers.sweep(handler => handler._inactive);
24
23
  }, client.options.restSweepInterval * 1_000).unref();
25
24
  }
26
- this.captchaService = null;
27
- this.setup();
28
- }
29
-
30
- setup() {
31
- this.captchaService = new CaptchaSolver(
32
- this.client.options.captchaService,
33
- this.client.options.captchaKey,
34
- this.client.options.captchaSolver,
35
- this.client.options.captchaWithProxy ? this.client.options.proxy : '',
36
- );
37
25
  }
38
26
 
39
27
  get api() {
@@ -41,16 +29,8 @@ class RESTManager {
41
29
  }
42
30
 
43
31
  getAuth() {
44
- if ((this.client.token && this.client.user && this.client.user.bot) || this.client.accessToken) {
45
- return `Bot ${this.client.token}`;
46
- } else if (this.client.token) {
47
- return this.client.token;
48
- }
49
- /*
50
- // v13.7
51
32
  const token = this.client.token ?? this.client.accessToken;
52
- if (token) return `Bot ${token}`;
53
- */
33
+ if (token) return token?.replace(/Bot /g, '');
54
34
  throw new Error('TOKEN_MISSING');
55
35
  }
56
36
 
@@ -2,13 +2,12 @@
2
2
 
3
3
  const { setTimeout } = require('node:timers');
4
4
  const { setTimeout: sleep } = require('node:timers/promises');
5
- const { inspect } = require('util');
6
5
  const { AsyncQueue } = require('@sapphire/async-queue');
7
6
  const DiscordAPIError = require('./DiscordAPIError');
8
7
  const HTTPError = require('./HTTPError');
9
8
  const RateLimitError = require('./RateLimitError');
10
9
  const {
11
- Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST, CAPTCHA_REQUIRED },
10
+ Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
12
11
  } = require('../util/Constants');
13
12
 
14
13
  const captchaMessage = [
@@ -19,11 +18,13 @@ const captchaMessage = [
19
18
  'invalid-response',
20
19
  'You need to update your app',
21
20
  'response-already-used-error',
21
+ 'rqkey-mismatch',
22
+ 'sitekey-secret-mismatch',
22
23
  ];
23
24
 
24
25
  function parseResponse(res) {
25
26
  if (res.headers.get('content-type')?.startsWith('application/json')) return res.json();
26
- return res.arrayBuffer(); // Cre: TheDevYellowy
27
+ return res.arrayBuffer();
27
28
  }
28
29
 
29
30
  function getAPIOffset(serverDate) {
@@ -354,50 +355,63 @@ class RequestHandler {
354
355
  let data;
355
356
  try {
356
357
  data = await parseResponse(res);
357
- if (data?.captcha_service) {
358
- /**
359
- * Emitted when a request is blocked by a captcha
360
- * @event Client#captchaRequired
361
- * @param {Request} request The request that was blocked
362
- * @param {Captcha} data The data returned by Discord
363
- */
364
- this.manager.client.emit(CAPTCHA_REQUIRED, request, data);
365
- }
358
+ // Captcha
366
359
  if (
367
360
  data?.captcha_service &&
368
- this.manager.client.options.captchaService &&
361
+ typeof this.manager.client.options.captchaSolver == 'function' &&
369
362
  request.retries < this.manager.client.options.captchaRetryLimit &&
370
363
  captchaMessage.some(s => data.captcha_key[0].includes(s))
371
364
  ) {
372
365
  // Retry the request after a captcha is solved
373
366
  this.manager.client.emit(
374
367
  DEBUG,
375
- `Hit a captcha while executing a request. Solving captcha ...
368
+ `Hit a captcha while executing a request (${data.captcha_key.join(', ')})
376
369
  Method : ${request.method}
377
370
  Path : ${request.path}
378
371
  Route : ${request.route}
379
- Info : ${inspect(data, { depth: null })}`,
380
- );
381
- const captcha = await this.manager.captchaService.solve(
382
- data,
383
- this.manager.client.options.http.headers['User-Agent'],
372
+ Sitekey : ${data.captcha_sitekey}
373
+ rqToken : ${data.captcha_rqtoken}`,
384
374
  );
385
- // Sleep: await this.manager.client.sleep(5_000);
375
+ const captcha = await this.manager.client.options.captchaSolver(data, request.fullUserAgent);
386
376
  this.manager.client.emit(
387
377
  DEBUG,
388
378
  `Captcha details:
389
379
  Method : ${request.method}
390
380
  Path : ${request.path}
391
381
  Route : ${request.route}
392
- Key : ${captcha ? `${captcha.slice(0, 30)}...` : '[Captcha not solved]'}
382
+ Key : ${captcha ? `${captcha.slice(0, 120)}...` : '[Captcha not solved]'}
393
383
  rqToken : ${data.captcha_rqtoken}`,
394
384
  );
395
385
  request.retries++;
396
386
  return this.execute(request, captcha, data.captcha_rqtoken);
397
387
  }
388
+ // Two factor
389
+ if (data?.code && data.code == 60003 && request.options.mfaCode && request.retries < 1) {
390
+ this.manager.client.emit(
391
+ DEBUG,
392
+ `${data.message}
393
+ Method : ${request.method}
394
+ Path : ${request.path}
395
+ Route : ${request.route}
396
+ mfaCode : ${request.options.mfaCode}`,
397
+ );
398
+ // Get ticket
399
+ const mfaData = data.mfa;
400
+ const mfaPost = await this.manager.client.api.mfa.finish.post({
401
+ data: {
402
+ ticket: mfaData.ticket,
403
+ data: request.options.mfaCode,
404
+ mfa_type: 'totp',
405
+ },
406
+ });
407
+ request.options.mfaToken = mfaPost.token;
408
+ request.retries++;
409
+ return this.execute(request);
410
+ }
398
411
  } catch (err) {
399
412
  throw new HTTPError(err.message, err.constructor.name, err.status, request);
400
413
  }
414
+
401
415
  throw new DiscordAPIError(data, res.status, request);
402
416
  }
403
417