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
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ const proxyParser = proxy => {
4
+ const protocolSplit = proxy.split('://');
5
+ const protocol = protocolSplit.length === 1 ? null : protocolSplit[0];
6
+ const rest = protocolSplit.length === 1 ? protocolSplit[0] : protocolSplit[1];
7
+ const authSplit = rest.split('@');
8
+ if (authSplit.length === 1) {
9
+ const host = authSplit[0].split(':')[0];
10
+ const port = Number(authSplit[0].split(':')[1]);
11
+ const proxyConfig = {
12
+ host,
13
+ port,
14
+ };
15
+ if (protocol != null) {
16
+ proxyConfig.protocol = protocol;
17
+ }
18
+ return proxyConfig;
19
+ }
20
+ const host = authSplit[1].split(':')[0];
21
+ const port = Number(authSplit[1].split(':')[1]);
22
+ const [username, password] = authSplit[0].split(':');
23
+ const proxyConfig = {
24
+ host,
25
+ port,
26
+ auth: {
27
+ username,
28
+ password,
29
+ },
30
+ };
31
+ if (protocol != null) {
32
+ proxyConfig.protocol = protocol;
33
+ }
34
+ return proxyConfig;
35
+ };
36
+
37
+ module.exports = class CaptchaSolver {
38
+ constructor(service, key, defaultCaptchaSolver, proxyString = '') {
39
+ this.service = 'custom';
40
+ this.solver = undefined;
41
+ this.defaultCaptchaSolver = defaultCaptchaSolver;
42
+ this.key = null;
43
+ this.proxy = proxyString.length ? proxyParser(proxyString) : null;
44
+ this._setup(service, key);
45
+ }
46
+ _missingModule(name) {
47
+ return new Error(`${name} module not found, please install it with \`npm i ${name}\``);
48
+ }
49
+ _setup(service, key) {
50
+ switch (service) {
51
+ case '2captcha': {
52
+ if (!key || typeof key !== 'string') throw new Error('2captcha key is not provided');
53
+ try {
54
+ const lib = require('2captcha');
55
+ this.service = '2captcha';
56
+ this.key = key;
57
+ this.solver = new lib.Solver(key);
58
+ this.solve = (data, userAgent) =>
59
+ new Promise((resolve, reject) => {
60
+ const siteKey = data.captcha_sitekey;
61
+ let postD = {};
62
+ if (this.proxy !== null) {
63
+ postD = {
64
+ proxytype: this.proxy.protocol?.toUpperCase(),
65
+ proxy: `${'auth' in this.proxy ? `${this.proxy.auth.username}:${this.proxy.auth.password}@` : ''}${
66
+ this.proxy.host
67
+ }:${this.proxy.port}`,
68
+ };
69
+ }
70
+ if (data.captcha_rqdata) {
71
+ postD = {
72
+ ...postD,
73
+ data: data.captcha_rqdata,
74
+ userAgent,
75
+ };
76
+ }
77
+ this.solver
78
+ .hcaptcha(siteKey, 'https://discord.com/channels/@me', postD)
79
+ .then(res => {
80
+ resolve(res.data);
81
+ })
82
+ .catch(reject);
83
+ });
84
+ break;
85
+ } catch (e) {
86
+ throw this._missingModule('2captcha');
87
+ }
88
+ }
89
+ case 'capmonster': {
90
+ if (!key || typeof key !== 'string') throw new Error('Capmonster key is not provided');
91
+ try {
92
+ const { HCaptchaTask } = require('node-capmonster');
93
+ this.service = 'capmonster';
94
+ this.key = key;
95
+ const client = new HCaptchaTask(this.key);
96
+ this.solve = (captchaData, userAgent) =>
97
+ new Promise((resolve, reject) => {
98
+ if (userAgent) client.setUserAgent(userAgent);
99
+ if (this.proxy !== null) {
100
+ client.setProxy(
101
+ this.proxy.protocol,
102
+ this.proxy.host,
103
+ this.proxy.port,
104
+ 'auth' in this.proxy ? this.proxy.auth.username : undefined,
105
+ 'auth' in this.proxy ? this.proxy.auth.password : undefined,
106
+ );
107
+ }
108
+ client
109
+ .createWithTask(
110
+ client.task({
111
+ websiteURL: 'https://discord.com/channels/@me',
112
+ websiteKey: captchaData.captcha_sitekey,
113
+ isInvisible: !!captchaData.captcha_rqdata,
114
+ data: captchaData.captcha_rqdata,
115
+ }),
116
+ )
117
+ .then(id => client.joinTaskResult(id))
118
+ .then(result => resolve(result.gRecaptchaResponse))
119
+ .catch(reject);
120
+ });
121
+ } catch (e) {
122
+ throw this._missingModule('node-capmonster');
123
+ }
124
+ break;
125
+ }
126
+ default: {
127
+ this.solve = this.defaultCaptchaSolver;
128
+ }
129
+ }
130
+ }
131
+ solve() {}
132
+ };
@@ -25,7 +25,7 @@ class DiscordAPIError extends Error {
25
25
 
26
26
  /**
27
27
  * HTTP error code returned by Discord
28
- * @type {number}
28
+ * @type {number | string}
29
29
  */
30
30
  this.code = error.code;
31
31
 
@@ -35,22 +35,6 @@ class DiscordAPIError extends Error {
35
35
  */
36
36
  this.httpStatus = status;
37
37
 
38
- /**
39
- * The data associated with the request that caused this error
40
- * @type {HTTPErrorData}
41
- */
42
- this.requestData = {
43
- json: request.options.data,
44
- files: request.options.files ?? [],
45
- headers: request.options.headers,
46
- };
47
-
48
- /**
49
- * The number of times this request has been retried
50
- * @type {number}
51
- */
52
- this.retries = request.retries;
53
-
54
38
  /**
55
39
  * @typedef {Object} Captcha
56
40
  * @property {Array<string>} captcha_key ['message']
@@ -65,6 +49,21 @@ class DiscordAPIError extends Error {
65
49
  * @type {Captcha | null}
66
50
  */
67
51
  this.captcha = error?.captcha_service ? error : null;
52
+
53
+ /**
54
+ * The data associated with the request that caused this error
55
+ * @type {HTTPErrorData}
56
+ */
57
+ this.requestData = {
58
+ json: request.options.data,
59
+ files: request.options.files ?? [],
60
+ };
61
+
62
+ /**
63
+ * The number of times this request has been retried
64
+ * @type {number}
65
+ */
66
+ this.retries = request.retries;
68
67
  }
69
68
 
70
69
  /**
@@ -4,6 +4,7 @@ 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');
7
8
  const RequestHandler = require('./RequestHandler');
8
9
  const { Error } = require('../errors');
9
10
  const { Endpoints } = require('../util/Constants');
@@ -22,6 +23,17 @@ class RESTManager {
22
23
  this.handlers.sweep(handler => handler._inactive);
23
24
  }, client.options.restSweepInterval * 1_000).unref();
24
25
  }
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
+ );
25
37
  }
26
38
 
27
39
  get api() {
@@ -29,8 +41,16 @@ class RESTManager {
29
41
  }
30
42
 
31
43
  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
32
51
  const token = this.client.token ?? this.client.accessToken;
33
- if (token) return token?.replace(/Bot /g, '');
52
+ if (token) return `Bot ${token}`;
53
+ */
34
54
  throw new Error('TOKEN_MISSING');
35
55
  }
36
56
 
@@ -2,12 +2,13 @@
2
2
 
3
3
  const { setTimeout } = require('node:timers');
4
4
  const { setTimeout: sleep } = require('node:timers/promises');
5
+ const { inspect } = require('util');
5
6
  const { AsyncQueue } = require('@sapphire/async-queue');
6
7
  const DiscordAPIError = require('./DiscordAPIError');
7
8
  const HTTPError = require('./HTTPError');
8
9
  const RateLimitError = require('./RateLimitError');
9
10
  const {
10
- Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
11
+ Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST, CAPTCHA_REQUIRED },
11
12
  } = require('../util/Constants');
12
13
 
13
14
  const captchaMessage = [
@@ -18,13 +19,11 @@ const captchaMessage = [
18
19
  'invalid-response',
19
20
  'You need to update your app',
20
21
  'response-already-used-error',
21
- 'rqkey-mismatch',
22
- 'sitekey-secret-mismatch',
23
22
  ];
24
23
 
25
24
  function parseResponse(res) {
26
25
  if (res.headers.get('content-type')?.startsWith('application/json')) return res.json();
27
- return res.arrayBuffer();
26
+ return res.arrayBuffer(); // Cre: TheDevYellowy
28
27
  }
29
28
 
30
29
  function getAPIOffset(serverDate) {
@@ -355,63 +354,50 @@ class RequestHandler {
355
354
  let data;
356
355
  try {
357
356
  data = await parseResponse(res);
358
- // Captcha
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
+ }
359
366
  if (
360
367
  data?.captcha_service &&
361
- typeof this.manager.client.options.captchaSolver == 'function' &&
368
+ this.manager.client.options.captchaService &&
362
369
  request.retries < this.manager.client.options.captchaRetryLimit &&
363
370
  captchaMessage.some(s => data.captcha_key[0].includes(s))
364
371
  ) {
365
372
  // Retry the request after a captcha is solved
366
373
  this.manager.client.emit(
367
374
  DEBUG,
368
- `Hit a captcha while executing a request (${data.captcha_key.join(', ')})
375
+ `Hit a captcha while executing a request. Solving captcha ...
369
376
  Method : ${request.method}
370
377
  Path : ${request.path}
371
378
  Route : ${request.route}
372
- Sitekey : ${data.captcha_sitekey}
373
- rqToken : ${data.captcha_rqtoken}`,
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'],
374
384
  );
375
- const captcha = await this.manager.client.options.captchaSolver(data, request.fullUserAgent);
385
+ // Sleep: await this.manager.client.sleep(5_000);
376
386
  this.manager.client.emit(
377
387
  DEBUG,
378
388
  `Captcha details:
379
389
  Method : ${request.method}
380
390
  Path : ${request.path}
381
391
  Route : ${request.route}
382
- Key : ${captcha ? `${captcha.slice(0, 120)}...` : '[Captcha not solved]'}
392
+ Key : ${captcha ? `${captcha.slice(0, 30)}...` : '[Captcha not solved]'}
383
393
  rqToken : ${data.captcha_rqtoken}`,
384
394
  );
385
395
  request.retries++;
386
396
  return this.execute(request, captcha, data.captcha_rqtoken);
387
397
  }
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
- }
411
398
  } catch (err) {
412
399
  throw new HTTPError(err.message, err.constructor.name, err.status, request);
413
400
  }
414
-
415
401
  throw new DiscordAPIError(data, res.status, request);
416
402
  }
417
403