feat: update OAuth2 authorization options and add method warnings for deprecated functionality

This commit is contained in:
Elysia
2024-11-27 20:34:27 +07:00
parent 30a714786f
commit a12b84da74
3 changed files with 25 additions and 3 deletions

View File

@@ -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');
}

View File

@@ -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);