Add creating channels

This commit is contained in:
Samuel Elliott 2018-04-30 19:16:06 +01:00
parent 6da58ef6bb
commit 591d44dee4
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 56 additions and 1 deletions

View File

@ -271,6 +271,26 @@ export class ChannelCategory extends GuildChannel {
get channels() {
return List.from(this.guild.channels, c => c.parentId === this.id);
}
/**
* Opens the create channel modal for this guild.
* @param {Number} type The type of channel to create - either 0 (text), 2 (voice) or 4 (category)
* @param {GuildChannel} clone A channel to clone permissions of
*/
openCreateChannelModal(type, category, clone) {
this.guild.openCreateChannelModal(type, this.id, this, clone);
}
/**
* Creates a channel in this category.
* @param {Number} type The type of channel to create - either 0 (text) or 2 (voice)
* @param {String} name A name for the new channel
* @param {Array} permission_overwrites An array of PermissionOverwrite-like objects - leave to use the permissions of the category
* @return {Promise => GuildChannel}
*/
createChannel(type, name, permission_overwrites) {
return this.guild.createChannel(type, name, this, permission_overwrites);
}
}
export class PrivateChannel extends Channel {

View File

@ -159,6 +159,13 @@ export class Guild {
if (this.afkChannelId) return Channel.fromId(this.afkChannelId);
}
/**
* The channel system messages are sent to.
*/
get systemChannel() {
if (this.systemChannelId) return Channel.fromId(this.systemChannelId);
}
/**
* A list of GuildMember objects.
*/
@ -259,10 +266,38 @@ export class Guild {
* @param {ChannelCategory} category The category to create the channel in
* @param {GuildChannel} clone A channel to clone permissions of
*/
openCreateChannelModal(type = 0, category, clone) {
openCreateChannelModal(type, category, clone) {
this.assertPermissions('MANAGE_CHANNELS', Modules.DiscordPermissions.MANAGE_CHANNELS);
Modules.CreateChannelModal.open(type, this.id, category ? category.id : undefined, clone ? clone.id : undefined);
}
/**
* Creates a channel in this guild.
* @param {Number} type The type of channel to create - either 0 (text), 2 (voice) or 4 (category)
* @param {String} name A name for the new channel
* @param {ChannelCategory} category The category to create the channel in
* @param {Array} permission_overwrites An array of PermissionOverwrite-like objects - leave to use the permissions of the category
* @return {Promise => GuildChannel}
*/
async createChannel(type, name, category, permission_overwrites) {
this.assertPermissions('MANAGE_CHANNELS', Modules.DiscordPermissions.MANAGE_CHANNELS);
const response = await Modules.APIModule.post({
url: Modules.DiscordConstants.Endpoints.GUILD_CHANNELS(this.id),
body: {
type, name,
parent_id: category ? category.id : undefined,
permission_overwrites: permission_overwrites ? permission_overwrites.map(p => ({
type: p.type,
id: p.type === 'user' ? p.userId : p.roleId,
allow: p.allow,
deny: p.deny
})) : undefined
}
});
return Channel.fromId(response.body.id);
}
openNotificationSettingsModal() {
Modules.NotificationSettingsModal.open(this.id);
}