mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Added guildChannel.createInvite();
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ const getStructure = name => require(`../../structures/${name}`);
|
||||
const User = getStructure('User');
|
||||
const GuildMember = getStructure('GuildMember');
|
||||
const Role = getStructure('Role');
|
||||
const Invite = getStructure('Invite');
|
||||
|
||||
class RESTMethods {
|
||||
constructor(restManager) {
|
||||
@@ -496,6 +497,19 @@ class RESTMethods {
|
||||
getChannelPinnedMessages(channel) {
|
||||
return this.rest.makeRequest('get', `${Constants.Endpoints.channel(channel.id)}/pins`, true);
|
||||
}
|
||||
|
||||
createChannelInvite(channel, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payload = {};
|
||||
payload.temporary = options.temporary;
|
||||
payload.max_age = options.maxAge;
|
||||
payload.max_uses = options.maxUses;
|
||||
|
||||
this.rest.makeRequest('post', `${Constants.Endpoints.channelInvites(channel.id)}`, true, payload)
|
||||
.then(invite => resolve(new Invite(this.rest.client, invite)))
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RESTMethods;
|
||||
|
||||
@@ -245,7 +245,7 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.log);
|
||||
*/
|
||||
setPosition(position) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { position });
|
||||
return this.client.rest.methods.updateChannel(this, { position });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +259,7 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.log);
|
||||
*/
|
||||
setTopic(topic) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { topic });
|
||||
return this.client.rest.methods.updateChannel(this, { topic });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,6 +275,27 @@ class GuildChannel extends Channel {
|
||||
toString() {
|
||||
return `<#${this.id}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options given when creating a Guild Channel Invite:
|
||||
* ```js
|
||||
* {
|
||||
* temporary: false, // whether the invite should kick users after 24hrs if they are not given a new role
|
||||
* maxAge: 0, // the time in seconds the invite expires in
|
||||
* maxUses: 0, // the maximum amount of uses for this invite
|
||||
* }
|
||||
* ```
|
||||
* @typedef {Object} InviteOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create an invite to this Guild Channel
|
||||
* @param {InviteOptions} [options={}] the options to provide when creating the invite
|
||||
* @returns {Promise<Invite, Error>}
|
||||
*/
|
||||
createInvite(options = {}) {
|
||||
return this.client.rest.methods.createChannelInvite(this, options);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildChannel;
|
||||
|
||||
97
src/structures/Invite.js
Normal file
97
src/structures/Invite.js
Normal file
@@ -0,0 +1,97 @@
|
||||
const PartialGuild = require('./PartialGuild');
|
||||
const PartialGuildChannel = require('./PartialGuildChannel');
|
||||
|
||||
/*
|
||||
{ max_age: 86400,
|
||||
code: 'CG9A5',
|
||||
guild:
|
||||
{ splash: null,
|
||||
id: '123123123',
|
||||
icon: '123123123',
|
||||
name: 'name' },
|
||||
created_at: '2016-08-28T19:07:04.763368+00:00',
|
||||
temporary: false,
|
||||
uses: 0,
|
||||
max_uses: 0,
|
||||
inviter:
|
||||
{ username: '123',
|
||||
discriminator: '4204',
|
||||
bot: true,
|
||||
id: '123123123',
|
||||
avatar: '123123123' },
|
||||
channel: { type: 0, id: '123123', name: 'heavy-testing' } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents an Invitation to a Guild Channel
|
||||
*/
|
||||
class Invite {
|
||||
constructor(client, data) {
|
||||
/**
|
||||
* The client that instantiated the invite
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The maximum age of the invite, in seconds
|
||||
* @type {?Number}
|
||||
*/
|
||||
this.maxAge = data.max_age;
|
||||
|
||||
/**
|
||||
* The code for this invite
|
||||
* @type {String}
|
||||
*/
|
||||
this.code = data.code;
|
||||
|
||||
/**
|
||||
* The creation date of the invite
|
||||
* @type {Date}
|
||||
*/
|
||||
this.creationDate = new Date(data.created_at);
|
||||
|
||||
/**
|
||||
* Whether or not this invite is temporary
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.temporary = data.temporary;
|
||||
|
||||
/**
|
||||
* How many times this invite has been used
|
||||
* @type {Number}
|
||||
*/
|
||||
this.uses = data.uses;
|
||||
|
||||
/**
|
||||
* The maximum uses of this invite
|
||||
* @type {Number}
|
||||
*/
|
||||
this.maxUses = data.max_uses;
|
||||
|
||||
/**
|
||||
* The user who created this invite
|
||||
* @type {User}
|
||||
*/
|
||||
this.inviter = this.client.dataManager.newUser(data.inviter);
|
||||
|
||||
/**
|
||||
* The Guild the invite is for. If this Guild is already known, this will be a Guild object. If the Guild is
|
||||
* unknown, this will be a Partial Guild.
|
||||
* @type {Guild|PartialGuild}
|
||||
*/
|
||||
this.guild = this.client.guilds.get(data.guild.id) || new PartialGuild(this.client, data.guild);
|
||||
|
||||
/**
|
||||
* The Channel the invite is for. If this Channel is already known, this will be a GuildChannel object.
|
||||
* If the Channel is unknown, this will be a Partial Guild Channel.
|
||||
* @type {GuildChannel|PartialGuildChannel}
|
||||
*/
|
||||
this.channels = this.client.channels.get(data.channel.id) || new PartialGuildChannel(this.client, data.channel);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Invite;
|
||||
45
src/structures/PartialGuild.js
Normal file
45
src/structures/PartialGuild.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
{ splash: null,
|
||||
id: '123123123',
|
||||
icon: '123123123',
|
||||
name: 'name' }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a Guild that the client only has limited information for - e.g. from invites.
|
||||
*/
|
||||
class PartialGuild {
|
||||
constructor(client, data) {
|
||||
/**
|
||||
* The client that instantiated this PartialGuild
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The hash of the guild splash image, or null if no splash (VIP only)
|
||||
* @type {?String}
|
||||
*/
|
||||
this.splash = data.splash;
|
||||
/**
|
||||
* The ID of this guild
|
||||
* @type {String}
|
||||
*/
|
||||
this.id = data.id;
|
||||
/**
|
||||
* The hash of this guild's icon, or null if there is none.
|
||||
* @type {?String}
|
||||
*/
|
||||
this.icon = data.icon;
|
||||
/**
|
||||
* The name of this guild
|
||||
* @type {String}
|
||||
*/
|
||||
this.name = data.name;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PartialGuild;
|
||||
39
src/structures/PartialGuildChannel.js
Normal file
39
src/structures/PartialGuildChannel.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
/*
|
||||
{ type: 0, id: '123123', name: 'heavy-testing' } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a Guild Channel that the client only has limited information for - e.g. from invites.
|
||||
*/
|
||||
class PartialGuildChannel {
|
||||
constructor(client, data) {
|
||||
/**
|
||||
* The client that instantiated this PartialGuildChannel
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The ID of this Guild Channel
|
||||
* @type {String}
|
||||
*/
|
||||
this.id = data.id;
|
||||
/**
|
||||
* The name of this Guild Channel
|
||||
* @type {String}
|
||||
*/
|
||||
this.name = data.name;
|
||||
/**
|
||||
* The type of this Guild Channel - `text` or `voice`
|
||||
* @type {String}
|
||||
*/
|
||||
this.type = Constants.ChannelTypes.text === data.type ? 'text' : 'voice';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PartialGuildChannel;
|
||||
Reference in New Issue
Block a user