This commit is contained in:
Elysia
2024-01-14 09:10:25 +07:00
parent 14b76367bc
commit 39a74b22dc
9 changed files with 380 additions and 1201 deletions
+2 -50
View File
@@ -1,12 +1,11 @@
'use strict';
const Buffer = require('node:buffer').Buffer;
const Base = require('./Base');
const { GuildScheduledEvent } = require('./GuildScheduledEvent');
const IntegrationApplication = require('./IntegrationApplication');
const InviteStageInstance = require('./InviteStageInstance');
const { Error } = require('../errors');
const { ChannelTypes, Endpoints } = require('../util/Constants');
const { Endpoints } = require('../util/Constants');
const Permissions = require('../util/Permissions');
// TODO: Convert `inviter` and `channel` in this class to a getter.
@@ -179,7 +178,7 @@ class Invite extends Base {
this.channel = this.client.channels.cache.get(data.channel_id);
}
if ('channel' in data && data.channel) {
if ('channel' in data) {
/**
* The channel this invite is for
* @type {Channel}
@@ -317,53 +316,6 @@ class Invite extends Base {
valueOf() {
return this.code;
}
/**
* Join this Guild using this invite.
* @param {boolean} [autoVerify] Whether to automatically verify member
* @returns {Promise<Guild>}
* @example
* await client.fetchInvite('code').then(async invite => {
* await invite.acceptInvite();
* });
*/
async acceptInvite(autoVerify = false) {
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,
location_channel_id: this.channelId,
location_channel_type: ChannelTypes[this.channel?.type] ?? 0,
};
await this.client.api.invites(this.code).post({
data: {
session_id: this.client.sessionId,
},
headers: {
'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'),
},
});
const guild = this.client.guilds.cache.get(this.guild.id);
/*
//
if (autoVerify) {
console.warn('Feature is under maintenance - Invite#acceptInvite(true)');
}
*/
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 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 guild;
}
}
/**