fix: Package (read description)
- Security update + Update Discord Version + Update WS identify data - Fix Captcha Handler
This commit is contained in:
parent
328f95643d
commit
7e4a3ccd57
@ -40,7 +40,7 @@
|
|||||||
- [X] Guild: Fetch Members, Join / Leave, Roles, Channels, etc.
|
- [X] Guild: Fetch Members, Join / Leave, Roles, Channels, etc.
|
||||||
- [X] Interactions: Slash Commands, Click Buttons, Menu (classic), Modal, Context Menu, etc.
|
- [X] Interactions: Slash Commands, Click Buttons, Menu (classic), Modal, Context Menu, etc.
|
||||||
- [X] Voice: Connect, Disconnect, Mute, Deafen, Call, Play Audio, etc.
|
- [X] Voice: Connect, Disconnect, Mute, Deafen, Call, Play Audio, etc.
|
||||||
- [X] Captcha Handler (Must not use due to safety concerns)
|
- [X] Captcha Handler
|
||||||
- [X] Documentation
|
- [X] Documentation
|
||||||
- [ ] Video stream
|
- [ ] Video stream
|
||||||
- [ ] Everything
|
- [ ] Everything
|
||||||
|
@ -848,6 +848,12 @@ class Client extends BaseClient {
|
|||||||
* @param {string} url Discord Auth URL
|
* @param {string} url Discord Auth URL
|
||||||
* @param {Object} options Oauth2 options
|
* @param {Object} options Oauth2 options
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
|
* @example
|
||||||
|
* client.authorizeURL(`https://discord.com/api/oauth2/authorize?client_id=botID&permissions=8&scope=applications.commands%20bot`, {
|
||||||
|
guild_id: "guildID",
|
||||||
|
permissions: "62221393", // your permissions
|
||||||
|
authorize: true
|
||||||
|
})
|
||||||
*/
|
*/
|
||||||
async authorizeURL(url, options = {}) {
|
async authorizeURL(url, options = {}) {
|
||||||
const reg = /(api\/)*oauth2\/authorize/gim;
|
const reg = /(api\/)*oauth2\/authorize/gim;
|
||||||
@ -893,9 +899,6 @@ class Client extends BaseClient {
|
|||||||
*/
|
*/
|
||||||
_validateOptions(options = this.options) {
|
_validateOptions(options = this.options) {
|
||||||
const captchaService = ['2captcha'];
|
const captchaService = ['2captcha'];
|
||||||
if (options && options.captchaService) {
|
|
||||||
options.captchaService = undefined;
|
|
||||||
}
|
|
||||||
if (typeof options.intents === 'undefined') {
|
if (typeof options.intents === 'undefined') {
|
||||||
throw new TypeError('CLIENT_MISSING_INTENTS');
|
throw new TypeError('CLIENT_MISSING_INTENTS');
|
||||||
} else {
|
} else {
|
||||||
|
@ -207,6 +207,7 @@ const Messages = {
|
|||||||
NITRO_REQUIRED: 'This feature is only available for Nitro users.',
|
NITRO_REQUIRED: 'This feature is only available for Nitro users.',
|
||||||
NITRO_BOOST_REQUIRED: feature => `This feature (${feature}) is only available for Nitro Boost users.`,
|
NITRO_BOOST_REQUIRED: feature => `This feature (${feature}) is only available for Nitro Boost users.`,
|
||||||
ONLY_ME: 'This feature is only available for self.',
|
ONLY_ME: 'This feature is only available for self.',
|
||||||
|
MISSING_CAPTCHA_SERVICE: 'This feature is only available for enabled captcha handler.',
|
||||||
|
|
||||||
GUILD_FORUM_MESSAGE_REQUIRED: 'You must provide a message to create a guild forum thread',
|
GUILD_FORUM_MESSAGE_REQUIRED: 'You must provide a message to create a guild forum thread',
|
||||||
};
|
};
|
||||||
|
@ -46,12 +46,17 @@ class APIRequest {
|
|||||||
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
|
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
|
||||||
const url = API + this.path;
|
const url = API + this.path;
|
||||||
|
|
||||||
|
const chromeVersion = this.client.options.ws.properties.browser_version.split('.')[0];
|
||||||
|
|
||||||
let headers = {
|
let headers = {
|
||||||
...this.client.options.http.headers,
|
...this.client.options.http.headers,
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
'Accept-Language': 'en-US,en;q=0.9',
|
'Accept-Language': 'en-US,en;q=0.9',
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
Pragma: 'no-cache',
|
Pragma: 'no-cache',
|
||||||
|
'Sec-Ch-Ua': `"Google Chrome";v="${chromeVersion}", "Chromium";v="${chromeVersion}", "Not=A?Brand";v="24"`,
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||||
'Sec-Fetch-Dest': 'empty',
|
'Sec-Fetch-Dest': 'empty',
|
||||||
'Sec-Fetch-Mode': 'cors',
|
'Sec-Fetch-Mode': 'cors',
|
||||||
'Sec-Fetch-Site': 'same-origin',
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
@ -101,8 +106,8 @@ class APIRequest {
|
|||||||
headers = Object.assign(headers, body.getHeaders());
|
headers = Object.assign(headers, body.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers['Content-Type'] === 'application/json' && captchaKey && typeof captchaKey == 'string' && body) {
|
if (headers['Content-Type'] === 'application/json' && captchaKey && typeof captchaKey == 'string') {
|
||||||
body = JSON.parse(body);
|
body = JSON.parse(body || '{}');
|
||||||
body.captcha_key = captchaKey;
|
body.captcha_key = captchaKey;
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,15 @@ const {
|
|||||||
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
|
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
|
||||||
} = require('../util/Constants');
|
} = require('../util/Constants');
|
||||||
|
|
||||||
|
const captchaMessage = [
|
||||||
|
'incorrect-captcha',
|
||||||
|
'response-already-used',
|
||||||
|
'captcha-required',
|
||||||
|
'invalid-input-response',
|
||||||
|
'invalid-response',
|
||||||
|
'You need to update your app',
|
||||||
|
];
|
||||||
|
|
||||||
function parseResponse(res) {
|
function parseResponse(res) {
|
||||||
if (res.headers.get('content-type').startsWith('application/json')) return res.json();
|
if (res.headers.get('content-type').startsWith('application/json')) return res.json();
|
||||||
return res.arrayBuffer(); // Cre: TheDevYellowy
|
return res.arrayBuffer(); // Cre: TheDevYellowy
|
||||||
@ -343,7 +352,12 @@ class RequestHandler {
|
|||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await parseResponse(res);
|
data = await parseResponse(res);
|
||||||
if (data?.captcha_service && this.manager.client.options.captchaService) {
|
if (
|
||||||
|
data?.captcha_service &&
|
||||||
|
this.manager.client.options.captchaService &&
|
||||||
|
request.retries < 4 &&
|
||||||
|
captchaMessage.includes(data.captcha_key[0])
|
||||||
|
) {
|
||||||
// Retry the request after a captcha is solved
|
// Retry the request after a captcha is solved
|
||||||
this.manager.client.emit(
|
this.manager.client.emit(
|
||||||
DEBUG,
|
DEBUG,
|
||||||
@ -362,6 +376,7 @@ class RequestHandler {
|
|||||||
Route : ${request.route}
|
Route : ${request.route}
|
||||||
Key : ${captcha}`,
|
Key : ${captcha}`,
|
||||||
);
|
);
|
||||||
|
request.retries++;
|
||||||
return this.execute(request, captcha);
|
return this.execute(request, captcha);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -10,7 +10,6 @@ const Integration = require('./Integration');
|
|||||||
const Webhook = require('./Webhook');
|
const Webhook = require('./Webhook');
|
||||||
const WelcomeScreen = require('./WelcomeScreen');
|
const WelcomeScreen = require('./WelcomeScreen');
|
||||||
const { Error } = require('../errors');
|
const { Error } = require('../errors');
|
||||||
// Disable: const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
|
|
||||||
const GuildBanManager = require('../managers/GuildBanManager');
|
const GuildBanManager = require('../managers/GuildBanManager');
|
||||||
const GuildChannelManager = require('../managers/GuildChannelManager');
|
const GuildChannelManager = require('../managers/GuildChannelManager');
|
||||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||||
@ -33,6 +32,7 @@ const {
|
|||||||
PremiumTiers,
|
PremiumTiers,
|
||||||
} = require('../util/Constants');
|
} = require('../util/Constants');
|
||||||
const DataResolver = require('../util/DataResolver');
|
const DataResolver = require('../util/DataResolver');
|
||||||
|
const Permissions = require('../util/Permissions');
|
||||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
@ -1494,8 +1494,39 @@ class Guild extends AnonymousGuild {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addBot() {
|
/**
|
||||||
console.log('Test only (Addbot)');
|
* Add Bot to the guild
|
||||||
|
* @param {UserResolvable} bot Bot user / BotId / ApplicationId
|
||||||
|
* @param {?PermissionsResolvable} permissions Permissions
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
addBot(bot, permissions) {
|
||||||
|
if (!this.me.permissions.has('MANAGE_WEBHOOKS')) {
|
||||||
|
throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS');
|
||||||
|
}
|
||||||
|
if (!this.me.permissions.has('MANAGE_GUILD')) {
|
||||||
|
throw new Error('MISSING_PERMISSIONS', 'MANAGE_GUILD');
|
||||||
|
}
|
||||||
|
if (!this.client.options.captchaService) throw new Error('MISSING_CAPTCHA_SERVICE');
|
||||||
|
const botId = this.client.users.resolveId(bot);
|
||||||
|
const permission = new Permissions(Permissions.resolve(permissions ?? 0n));
|
||||||
|
if (!botId) throw new TypeError('INVALID_BOT_ID');
|
||||||
|
// Check permission
|
||||||
|
const selfPerm = this.me.permissions.toArray();
|
||||||
|
for (const perm of permission.toArray()) {
|
||||||
|
if (!selfPerm.includes(perm)) {
|
||||||
|
throw new Error('MISSING_PERMISSIONS', perm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add bot
|
||||||
|
return this.client.authorizeURL(
|
||||||
|
`https://discord.com/api/oauth2/authorize?client_id=${botId}&permissions=${permission.bitfield}&scope=applications.commands%20bot`,
|
||||||
|
{
|
||||||
|
guild_id: this.id,
|
||||||
|
permissions: `${permission.bitfield}`,
|
||||||
|
authorize: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
@ -321,14 +321,13 @@ class Invite extends Base {
|
|||||||
/**
|
/**
|
||||||
* Join this Guild using this invite.
|
* Join this Guild using this invite.
|
||||||
* @param {boolean} autoVerify Whether to automatically verify member
|
* @param {boolean} autoVerify Whether to automatically verify member
|
||||||
* @param {string} [captcha] The captcha key to add
|
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
* @example
|
* @example
|
||||||
* await client.fetchInvite('code').then(async invite => {
|
* await client.fetchInvite('code').then(async invite => {
|
||||||
* await invite.acceptInvite();
|
* await invite.acceptInvite();
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
async acceptInvite(autoVerify = true, captcha = null) {
|
async acceptInvite(autoVerify = true) {
|
||||||
if (!this.guild) throw new Error('INVITE_NO_GUILD');
|
if (!this.guild) throw new Error('INVITE_NO_GUILD');
|
||||||
const dataHeader = {
|
const dataHeader = {
|
||||||
location: 'Join Guild',
|
location: 'Join Guild',
|
||||||
@ -337,11 +336,7 @@ class Invite extends Base {
|
|||||||
location_channel_type: ChannelTypes[this.channel?.type] ?? 0,
|
location_channel_type: ChannelTypes[this.channel?.type] ?? 0,
|
||||||
};
|
};
|
||||||
await this.client.api.invites(this.code).post({
|
await this.client.api.invites(this.code).post({
|
||||||
data: captcha
|
data: {},
|
||||||
? {
|
|
||||||
captcha_key: captcha,
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
headers: {
|
headers: {
|
||||||
'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'),
|
'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'),
|
||||||
},
|
},
|
||||||
|
@ -188,13 +188,14 @@ class Options extends null {
|
|||||||
referrer_current: '',
|
referrer_current: '',
|
||||||
referring_domain_current: '',
|
referring_domain_current: '',
|
||||||
release_channel: 'stable',
|
release_channel: 'stable',
|
||||||
client_build_number: 156668,
|
client_build_number: 156904,
|
||||||
client_event_source: null,
|
client_event_source: null,
|
||||||
},
|
},
|
||||||
// ? capabilities: 1021,
|
// ? capabilities: 2045,
|
||||||
version: 9,
|
version: 9,
|
||||||
client_state: {
|
client_state: {
|
||||||
guild_hashes: {},
|
api_code_version: 0,
|
||||||
|
guild_versions: {},
|
||||||
highest_last_message_id: '0',
|
highest_last_message_id: '0',
|
||||||
read_state_version: 0,
|
read_state_version: 0,
|
||||||
user_guild_settings_version: -1,
|
user_guild_settings_version: -1,
|
||||||
|
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@ -1404,6 +1404,7 @@ export class GuildAuditLogsEntry<
|
|||||||
public targetType: TTargetType;
|
public targetType: TTargetType;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
public addIntegration(applicationId: Snowflake): Promise<void>;
|
public addIntegration(applicationId: Snowflake): Promise<void>;
|
||||||
|
public addBot(bot: UserResolvable | Snowflake, permissions?: PermissionResolvable): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildBan extends Base {
|
export class GuildBan extends Base {
|
||||||
|
Loading…
Reference in New Issue
Block a user