diff --git a/package.json b/package.json index 2ff7af5..6711206 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "@types/node-fetch": "^2.6.2", "@types/ws": "^8.5.3", "axios": "1.1", - "bignumber.js": "^9.1.0", "chalk": "^4.1.2", "discord-api-types": "^0.37.19", "form-data": "^4.0.0", diff --git a/src/client/Client.js b/src/client/Client.js index 319061a..c81c81b 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -1026,6 +1026,9 @@ class Client extends BaseClient { } break; case 'nopecha': { + if (options.captchaKey.length !== 16) { + throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 16 character string'); + } break; } } diff --git a/src/client/websocket/WebSocketManager.js b/src/client/websocket/WebSocketManager.js index 4a6006a..d23cc0d 100644 --- a/src/client/websocket/WebSocketManager.js +++ b/src/client/websocket/WebSocketManager.js @@ -144,8 +144,8 @@ class WebSocketManager extends EventEmitter { }); const recommendedShards = 1; const sessionStartLimit = { - total: 1000000000, - remaining: 1000000000, + total: Infinity, + remaining: Infinity, }; const { total, remaining } = sessionStartLimit; diff --git a/src/client/websocket/WebSocketShard.js b/src/client/websocket/WebSocketShard.js index 50b654c..df90240 100644 --- a/src/client/websocket/WebSocketShard.js +++ b/src/client/websocket/WebSocketShard.js @@ -710,7 +710,7 @@ class WebSocketShard extends EventEmitter { this.debug( `[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${Intents.resolve( client.options.intents, - )} :)`, + )} 😊`, ); this.send({ op: Opcodes.IDENTIFY, d }, true); } diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 803bc78..4390dd0 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -1,7 +1,6 @@ 'use strict'; const { Collection } = require('@discordjs/collection'); -const BigNumber = require('bignumber.js'); const CachedManager = require('./CachedManager'); const { TypeError, Error } = require('../errors'); const { Message } = require('../structures/Message'); @@ -246,8 +245,8 @@ class MessageManager extends CachedManager { await this.client.api.guilds[this.channel.guild.id].messages.search.get({ query: { channel_id: this.channel.id, - max_id: new BigNumber.BigNumber(messageId).plus(1).toString(), - min_id: new BigNumber.BigNumber(messageId).minus(1).toString(), + max_id: `${BigInt(messageId) + 1n}`, + min_id: `${BigInt(messageId) - 1n}`, include_nsfw: true, }, }) @@ -258,8 +257,8 @@ class MessageManager extends CachedManager { const data = ( await this.client.api.channels[this.channel.id].messages.search.get({ query: { - max_id: new BigNumber.BigNumber(messageId).plus(1).toString(), - min_id: new BigNumber.BigNumber(messageId).minus(1).toString(), + max_id: `${BigInt(messageId) + 1n}`, + min_id: `${BigInt(messageId) - 1n}`, }, }) ).messages[0]; diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 4d1c645..63eda14 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -4,7 +4,6 @@ const Buffer = require('node:buffer').Buffer; const https = require('node:https'); const { setTimeout } = require('node:timers'); const FormData = require('form-data'); -const JSONBig = require('json-bigint'); const fetch = require('node-fetch'); const proxy = require('proxy-agent'); @@ -61,9 +60,10 @@ class APIRequest { 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', 'X-Debug-Options': 'bugReporterEnabled', - 'X-Super-Properties': `${Buffer.from(JSONBig.stringify(this.client.options.ws.properties), 'ascii').toString( - 'base64', - )}`, + 'X-Super-Properties': `${Buffer.from( + this.client.options.jsonTransformer(this.client.options.ws.properties), + 'ascii', + ).toString('base64')}`, 'X-Discord-Locale': 'en-US', 'User-Agent': this.client.options.http.headers['User-Agent'], }; diff --git a/src/rest/CaptchaSolver.js b/src/rest/CaptchaSolver.js index de3e064..1b8a15e 100644 --- a/src/rest/CaptchaSolver.js +++ b/src/rest/CaptchaSolver.js @@ -31,7 +31,7 @@ module.exports = class CaptchaSolver { } } case 'nopecha': { - if (!key || typeof key !== 'string') throw new Error('Nopecha key is not provided'); + if (!key || typeof key !== 'string') throw new Error('NopeCHA key is not provided'); try { const { Configuration, NopeCHAApi } = require('nopecha'); const configuration = new Configuration({ diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index d9b7738..e4b37d7 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -257,10 +257,6 @@ class DMChannel extends Channel { this.client.voice.adapters.set(this.id, methods); return { sendPayload: data => { - data.d = { - ...data.d, - self_video: false, - }; if (this.shard.status !== Status.READY) return false; this.shard.send(data); return true; diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 3d61f99..a2eb63c 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -1471,9 +1471,9 @@ class Guild extends AnonymousGuild { /** * Add Integrations to the guild. * @param {Snowflake} applicationId Application (ID) target - * @returns {Promise} + * @returns {Promise} */ - async addIntegration(applicationId) { + addIntegration(applicationId) { if (!this.me.permissions.has('MANAGE_WEBHOOKS')) { throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS'); } @@ -1481,18 +1481,14 @@ class Guild extends AnonymousGuild { throw new Error('MISSING_PERMISSIONS', 'MANAGE_GUILD'); } if (!applicationId || typeof applicationId !== 'string') throw new TypeError('INVALID_APPLICATION_ID'); - // Check permission - await this.client.api.oauth2.authorize.post({ - query: { - client_id: applicationId, - scope: 'applications.commands', - }, - data: { + return this.client.authorizeURL( + `https://discord.com/api/oauth2/authorize?client_id=${applicationId}&scope=applications.commands`, + { guild_id: this.id, - permissions: '0', + permissions: `0`, authorize: true, }, - }); + ); } /** @@ -1501,7 +1497,7 @@ class Guild extends AnonymousGuild { * @param {?PermissionResolvable} permissions Permissions * @returns {Promise} */ - addBot(bot, permissions) { + addBot(bot, permissions = 0n) { if (!this.me.permissions.has('MANAGE_WEBHOOKS')) { throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS'); } @@ -1514,8 +1510,8 @@ class Guild extends AnonymousGuild { if (!botId) throw new TypeError('INVALID_BOT_ID'); // Check permission const selfPerm = this.me.permissions.toArray(); - const missingPerms = permission.toArray().filter(x => selfPerm.indexOf(x) === -1); - if (missingPerms[0]) { + const missingPerms = permission.toArray().filter(x => selfPerm.includes(x)); + if (missingPerms.length) { throw new Error('MISSING_PERMISSIONS', missingPerms.join(', ')); } // Add bot diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 63edd1c..34af7cf 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -321,7 +321,7 @@ class Invite extends Base { /** * Join this Guild using this invite. * @param {boolean} autoVerify Whether to automatically verify member - * @returns {Promise} + * @returns {Promise} * @example * await client.fetchInvite('code').then(async invite => { * await invite.acceptInvite(); @@ -329,6 +329,7 @@ class Invite extends Base { */ async acceptInvite(autoVerify = true) { if (!this.guild) throw new Error('INVITE_NO_GUILD'); + if (this.client.guilds.cache.get(this.guild.id)) return this.guild; const dataHeader = { location: 'Join Guild', location_guild_id: this.guild?.id, @@ -341,18 +342,19 @@ class Invite extends Base { 'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'), }, }); + const guild = this.client.guilds.cache.get(this.guild.id); if (autoVerify) { const getForm = await this.client.api .guilds(this.guild.id) ['member-verification'].get({ query: { with_guild: false, invite_code: this.code } }) .catch(() => {}); - if (!getForm) return undefined; + if (!getForm) return guild; const form = Object.assign(getForm.form_fields[0], { response: true }); // Respond to the form // https://discord.com/api/v9/guilds/:id/requests/@me await this.client.api.guilds(this.guild.id).requests['@me'].put({ data: { form_fields: [form] } }); } - return undefined; + return guild; } } diff --git a/src/structures/MessageSelectMenu.js b/src/structures/MessageSelectMenu.js index 6b18138..919ccb4 100644 --- a/src/structures/MessageSelectMenu.js +++ b/src/structures/MessageSelectMenu.js @@ -2,10 +2,11 @@ const { setTimeout } = require('node:timers'); const BaseMessageComponent = require('./BaseMessageComponent'); -const { Message } = require('./Message'); const { MessageComponentTypes, InteractionTypes, ChannelTypes } = require('../util/Constants'); const SnowflakeUtil = require('../util/SnowflakeUtil'); const Util = require('../util/Util'); +const { lazy } = require('../util/Util'); +const Message = lazy(() => require('./Message').Message); /** * Represents a select menu message component @@ -284,7 +285,7 @@ class MessageSelectMenu extends BaseMessageComponent { * @returns {Promise} */ async select(message, values = []) { - if (!(message instanceof Message)) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message'); + if (!(message instanceof Message())) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message'); if (!Array.isArray(values)) throw new TypeError('[INVALID_VALUES] Please pass an array of values'); if (!this.customId || this.disabled) return false; // Disabled or null customID // Check value is invalid [Max options is 20] => For loop diff --git a/src/structures/PartialGroupDMChannel.js b/src/structures/PartialGroupDMChannel.js index ba5c45a..b638ae9 100644 --- a/src/structures/PartialGroupDMChannel.js +++ b/src/structures/PartialGroupDMChannel.js @@ -407,10 +407,6 @@ class PartialGroupDMChannel extends Channel { this.client.voice.adapters.set(this.id, methods); return { sendPayload: data => { - data.d = { - ...data.d, - self_video: false, - }; if (this.shard.status !== Status.READY) return false; this.shard.send(data); return true; diff --git a/src/structures/RichPresence.js b/src/structures/RichPresence.js index 3c16777..87fff59 100644 --- a/src/structures/RichPresence.js +++ b/src/structures/RichPresence.js @@ -294,7 +294,7 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP * @returns {RichPresence} */ setType(type) { - this.type = ActivityTypes[type?.toUpperCase()]; + this.type = ActivityTypes[type]; if (typeof this.type == 'string') this.type = ActivityTypes[this.type]; if (typeof this.type != 'number') throw new Error('Type must be a valid ActivityType'); return this; @@ -471,11 +471,9 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP delete obj.name; delete obj.url; obj.type = 0; - let buttonData = []; - if (obj.buttons) { - buttonData = obj.buttons.map((b, i) => ({ label: b, url: obj.metadata.button_urls[i] })); + if (obj.buttons?.length) { + obj.buttons = obj.buttons.map((b, i) => ({ label: b, url: obj.metadata.button_urls[i] })); delete obj.metadata; - obj.buttons = buttonData; } return obj; } @@ -566,6 +564,10 @@ class SpotifyRPC extends RichPresence { * @private */ setup(options) { + this.name = options.name || 'Spotify'; + + this.type = ActivityTypes.LISTENING; + this.party = { id: `spotify:${this.client.user.id}`, }; @@ -638,8 +640,8 @@ class SpotifyRPC extends RichPresence { toJSON() { if (!this.sync_id) throw new Error('Song id is required'); const obj = { - name: 'Spotify', - type: ActivityTypes.LISTENING, + name: this.name, + type: this.type, application_id: this.application_id, url: this.url, state: this.state, diff --git a/src/util/Constants.js b/src/util/Constants.js index a403b11..7b0b042 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -6,11 +6,11 @@ const Package = (exports.Package = require('../../package.json')); const { Error, RangeError, TypeError } = require('../errors'); // #88: https://jnrbsn.github.io/user-agents/user-agents.json const listUserAgent = [ - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13.0; rv:107.0) Gecko/20100101 Firefox/107.0', 'Mozilla/5.0 (X11; Linux i686; rv:107.0) Gecko/20100101 Firefox/107.0', @@ -26,8 +26,8 @@ const listUserAgent = [ 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/107.0.1418.68', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/107.0.1418.68', ]; /** diff --git a/src/util/Options.js b/src/util/Options.js index 72c8e8f..264a654 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -188,7 +188,7 @@ class Options extends null { browser: 'Chrome', device: '', system_locale: 'en-US', - browser_version: '107.0.0.0', + browser_version: '108.0.0.0', os_version: '10', referrer: '', referring_domain: '', diff --git a/typings/index.d.ts b/typings/index.d.ts index 2493ce1..1052b93 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1412,7 +1412,7 @@ export class GuildAuditLogsEntry< : Role | GuildEmoji | { id: Snowflake } | null; public targetType: TTargetType; public toJSON(): unknown; - public addIntegration(applicationId: Snowflake): Promise; + public addIntegration(applicationId: Snowflake): Promise; public addBot(bot: UserResolvable | Snowflake, permissions?: PermissionResolvable): Promise; } @@ -1813,7 +1813,7 @@ export class Invite extends Base { public delete(reason?: string): Promise; public toJSON(): unknown; public toString(): string; - public acceptInvite(autoVerify?: boolean): Promise; + public acceptInvite(autoVerify?: boolean): Promise; public static INVITES_PATTERN: RegExp; public stageInstance: InviteStageInstance | null; public guildScheduledEvent: GuildScheduledEvent | null;