From a12b84da74250a7d73c8626b9aa794b641698476 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:34:27 +0700 Subject: [PATCH] feat: update OAuth2 authorization options and add method warnings for deprecated functionality --- examples/AddBot.js | 5 ++++- src/client/Client.js | 20 ++++++++++++++++++-- src/errors/Messages.js | 3 +++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/examples/AddBot.js b/examples/AddBot.js index 1d144e23..438b292b 100644 --- a/examples/AddBot.js +++ b/examples/AddBot.js @@ -19,11 +19,14 @@ const client = new Discord.Client({ client.on('ready', async () => { console.log('Ready!', client.user.tag); + // Note + // You need to include `guild_id` and `permissions` to invite the bot. + // These two fields can appear either in the URL or in the options. await client.authorizeURL( `https://discord.com/api/oauth2/authorize?client_id=289066747443675143&permissions=414501424448&scope=bot%20applications.commands`, { guild_id: 'guild id', - permissions: '8', // Admin + permissions: '414501424448', authorize: true, }, ); diff --git a/src/client/Client.js b/src/client/Client.js index a0bc1214..eaa1ce47 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -588,6 +588,7 @@ class Client extends BaseClient { * await client.acceptInvite('https://discord.gg/genshinimpact', { bypassOnboarding: true, bypassVerify: true }) */ async acceptInvite(invite, options = { bypassOnboarding: true, bypassVerify: true }) { + throw new Error('METHOD_WARNING'); const code = DataResolver.resolveInviteCode(invite); if (!code) throw new Error('INVITE_RESOLVE_CODE'); const i = await this.fetchInvite(code); @@ -709,7 +710,8 @@ class Client extends BaseClient { authorize: true }) */ - authorizeURL(url, options = { authorize: true, permissions: '0' }) { + authorizeURL(url, options = { authorize: true }) { + throw new Error('METHOD_WARNING'); const pathnameAPI = /\/api\/(v\d{1,2}\/)?oauth2\/authorize/; const pathnameURL = /\/oauth2\/authorize/; const url_ = new URL(url); @@ -720,8 +722,19 @@ class Client extends BaseClient { throw new Error('INVALID_URL', url); } const searchParams = Object.fromEntries(url_.searchParams); - options.permissions = `${Permissions.resolve(searchParams.permissions || options.permissions) || 0}`; + options.permissions ??= `${Permissions.resolve(searchParams.permissions || 0)}`; + options.integration_type ??= searchParams.integration_type || 0; + options.location_context = { + guild_id: '10000', + channel_id: '10000', + channel_type: 10000, + }; + options.guild_id ??= searchParams.guild_id; + options.authorize ??= true; delete searchParams.permissions; + delete searchParams.integration_type; + delete searchParams.guild_id; + if (!options.permissions || !options.guild_id) throw new Error('INVALID_OAUTH_OPTIONS'); return this.api.oauth2.authorize.post({ query: searchParams, data: options, @@ -790,6 +803,9 @@ class Client extends BaseClient { * @private */ _validateOptions(options = this.options) { + options.captchaSolver = () => { + throw new Error('METHOD_WARNING'); + }; if (typeof options.makeCache !== 'function') { throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function'); } diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 2ae255ec..17608547 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -209,6 +209,9 @@ const Messages = { STREAM_CANNOT_JOIN: 'Cannot join a stream to itself', VOICE_USER_NOT_STREAMING: 'User is not streaming', POLL_ALREADY_EXPIRED: 'This poll has already expired.', + INVALID_OAUTH_OPTIONS: 'Invalid options for authenticating with OAuth2.', + METHOD_WARNING: + 'This method is flagged as it may lead to a temporary or permanent account ban. Do not use until further notice.', }; for (const [name, message] of Object.entries(Messages)) register(name, message);