fix: Package (read description)

- Security update
 + Update Discord Version
 + Update WS identify data
- Fix Captcha Handler
This commit is contained in:
March 7th
2022-11-08 13:27:44 +07:00
parent 328f95643d
commit 7e4a3ccd57
9 changed files with 72 additions and 20 deletions

View File

@@ -10,7 +10,6 @@ const Integration = require('./Integration');
const Webhook = require('./Webhook');
const WelcomeScreen = require('./WelcomeScreen');
const { Error } = require('../errors');
// Disable: const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
const GuildBanManager = require('../managers/GuildBanManager');
const GuildChannelManager = require('../managers/GuildChannelManager');
const GuildEmojiManager = require('../managers/GuildEmojiManager');
@@ -33,6 +32,7 @@ const {
PremiumTiers,
} = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Permissions = require('../util/Permissions');
const SystemChannelFlags = require('../util/SystemChannelFlags');
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() {

View File

@@ -321,14 +321,13 @@ class Invite extends Base {
/**
* Join this Guild using this invite.
* @param {boolean} autoVerify Whether to automatically verify member
* @param {string} [captcha] The captcha key to add
* @returns {Promise<void>}
* @example
* await client.fetchInvite('code').then(async invite => {
* await invite.acceptInvite();
* });
*/
async acceptInvite(autoVerify = true, captcha = null) {
async acceptInvite(autoVerify = true) {
if (!this.guild) throw new Error('INVITE_NO_GUILD');
const dataHeader = {
location: 'Join Guild',
@@ -337,11 +336,7 @@ class Invite extends Base {
location_channel_type: ChannelTypes[this.channel?.type] ?? 0,
};
await this.client.api.invites(this.code).post({
data: captcha
? {
captcha_key: captcha,
}
: {},
data: {},
headers: {
'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'),
},