Skip to content

Commit

Permalink
feat(StageChannel): v13 support messages (#9145)
Browse files Browse the repository at this point in the history
Co-authored-by: kyranet <kyradiscord@gmail.com>
  • Loading branch information
jaw0r3k and kyranet committed Apr 14, 2023
1 parent add14ac commit 7cf9224
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 140 deletions.
3 changes: 2 additions & 1 deletion src/client/actions/WebhooksUpdate.js
Expand Up @@ -10,7 +10,8 @@ class WebhooksUpdate extends Action {
/**
* Emitted whenever a channel has its webhooks changed.
* @event Client#webhookUpdate
* @param {TextChannel|NewsChannel|VoiceChannel|ForumChannel} channel The channel that had a webhook update
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
* The channel that had a webhook update
*/
if (channel) client.emit(Events.WEBHOOKS_UPDATE, channel);
}
Expand Down
152 changes: 132 additions & 20 deletions src/structures/BaseGuildVoiceChannel.js
Expand Up @@ -2,16 +2,45 @@

const { Collection } = require('@discordjs/collection');
const GuildChannel = require('./GuildChannel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const MessageManager = require('../managers/MessageManager');
const { VideoQualityModes } = require('../util/Constants');
const Permissions = require('../util/Permissions');

/**
* Represents a voice-based guild channel on Discord.
* @extends {GuildChannel}
* @implements {TextBasedChannel}
*/
class BaseGuildVoiceChannel extends GuildChannel {
constructor(guild, data, client) {
super(guild, data, client, false);
/**
* A manager of the messages sent to this channel
* @type {MessageManager}
*/
this.messages = new MessageManager(this);

/**
* If the guild considers this channel NSFW
* @type {boolean}
*/
this.nsfw = Boolean(data.nsfw);

this._patch(data);
}

_patch(data) {
super._patch(data);

if ('bitrate' in data) {
/**
* The bitrate of this voice-based channel
* @type {number}
*/
this.bitrate = data.bitrate;
}

if ('rtc_region' in data) {
/**
* The RTC region for this voice-based channel. This region is automatically selected if `null`.
Expand All @@ -20,20 +49,46 @@ class BaseGuildVoiceChannel extends GuildChannel {
this.rtcRegion = data.rtc_region;
}

if ('bitrate' in data) {
if ('user_limit' in data) {
/**
* The bitrate of this voice-based channel
* The maximum amount of users allowed in this channel.
* @type {number}
*/
this.bitrate = data.bitrate;
this.userLimit = data.user_limit;
}

if ('user_limit' in data) {
if ('video_quality_mode' in data) {
/**
* The maximum amount of users allowed in this channel.
* The camera video quality mode of the channel.
* @type {?VideoQualityMode}
*/
this.videoQualityMode = VideoQualityModes[data.video_quality_mode];
} else {
this.videoQualityMode ??= null;
}

if ('last_message_id' in data) {
/**
* The last message id sent in the channel, if one was sent
* @type {?Snowflake}
*/
this.lastMessageId = data.last_message_id;
}

if ('messages' in data) {
for (const message of data.messages) this.messages._add(message);
}

if ('rate_limit_per_user' in data) {
/**
* The rate limit per user (slowmode) for this channel in seconds
* @type {number}
*/
this.userLimit = data.user_limit;
this.rateLimitPerUser = data.rate_limit_per_user;
}

if ('nsfw' in data) {
this.nsfw = data.nsfw;
}
}

Expand Down Expand Up @@ -80,6 +135,45 @@ class BaseGuildVoiceChannel extends GuildChannel {
);
}

/**
* Creates an invite to this guild channel.
* @param {CreateInviteOptions} [options={}] The options for creating the invite
* @returns {Promise<Invite>}
* @example
* // Create an invite to a channel
* channel.createInvite()
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
* .catch(console.error);
*/
createInvite(options) {
return this.guild.invites.create(this.id, options);
}

/**
* Fetches a collection of invites to this guild channel.
* Resolves with a collection mapping invites by their codes.
* @param {boolean} [cache=true] Whether or not to cache the fetched invites
* @returns {Promise<Collection<string, Invite>>}
*/
fetchInvites(cache = true) {
return this.guild.invites.fetch({ channelId: this.id, cache });
}

/**
* Sets the bitrate of the channel.
* @param {number} bitrate The new bitrate
* @param {string} [reason] Reason for changing the channel's bitrate
* @returns {Promise<BaseGuildVoiceChannel>}
* @example
* // Set the bitrate of a voice channel
* channel.setBitrate(48_000)
* .then(channel => console.log(`Set bitrate to ${channel.bitrate}bps for ${channel.name}`))
* .catch(console.error);
*/
setBitrate(bitrate, reason) {
return this.edit({ bitrate }, reason);
}

/**
* Sets the RTC region of the channel.
* @param {?string} rtcRegion The new region of the channel. Set to `null` to remove a specific region for the channel
Expand All @@ -97,28 +191,46 @@ class BaseGuildVoiceChannel extends GuildChannel {
}

/**
* Creates an invite to this guild channel.
* @param {CreateInviteOptions} [options={}] The options for creating the invite
* @returns {Promise<Invite>}
* Sets the user limit of the channel.
* @param {number} userLimit The new user limit
* @param {string} [reason] Reason for changing the user limit
* @returns {Promise<BaseGuildVoiceChannel>}
* @example
* // Create an invite to a channel
* channel.createInvite()
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
* // Set the user limit of a voice channel
* channel.setUserLimit(42)
* .then(channel => console.log(`Set user limit to ${channel.userLimit} for ${channel.name}`))
* .catch(console.error);
*/
createInvite(options) {
return this.guild.invites.create(this.id, options);
setUserLimit(userLimit, reason) {
return this.edit({ userLimit }, reason);
}

/**
* Fetches a collection of invites to this guild channel.
* Resolves with a collection mapping invites by their codes.
* @param {boolean} [cache=true] Whether or not to cache the fetched invites
* @returns {Promise<Collection<string, Invite>>}
* Sets the camera video quality mode of the channel.
* @param {VideoQualityMode|number} videoQualityMode The new camera video quality mode.
* @param {string} [reason] Reason for changing the camera video quality mode.
* @returns {Promise<BaseGuildVoiceChannel>}
*/
fetchInvites(cache = true) {
return this.guild.invites.fetch({ channelId: this.id, cache });
setVideoQualityMode(videoQualityMode, reason) {
return this.edit({ videoQualityMode }, reason);
}

// These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */
get lastMessage() {}
send() {}
sendTyping() {}
createMessageCollector() {}
awaitMessages() {}
createMessageComponentCollector() {}
awaitMessageComponent() {}
bulkDelete() {}
fetchWebhooks() {}
createWebhook() {}
setRateLimitPerUser() {}
setNSFW() {}
}

TextBasedChannel.applyToClass(BaseGuildVoiceChannel, true, ['lastPinAt']);

module.exports = BaseGuildVoiceChannel;
34 changes: 34 additions & 0 deletions src/structures/StageChannel.js
Expand Up @@ -52,6 +52,19 @@ class StageChannel extends BaseGuildVoiceChannel {
return this.edit({ topic }, reason);
}

/**
* Sets the bitrate of the channel.
* @name StageChannel#setBitrate
* @param {number} bitrate The new bitrate
* @param {string} [reason] Reason for changing the channel's bitrate
* @returns {Promise<StageChannel>}
* @example
* // Set the bitrate of a voice channel
* stageChannel.setBitrate(48_000)
* .then(channel => console.log(`Set bitrate to ${channel.bitrate}bps for ${channel.name}`))
* .catch(console.error);
*/

/**
* Sets the RTC region of the channel.
* @name StageChannel#setRTCRegion
Expand All @@ -65,6 +78,27 @@ class StageChannel extends BaseGuildVoiceChannel {
* // Remove a fixed region for this channel - let Discord decide automatically
* stageChannel.setRTCRegion(null, 'We want to let Discord decide.');
*/

/**
* Sets the user limit of the channel.
* @name StageChannel#setUserLimit
* @param {number} userLimit The new user limit
* @param {string} [reason] Reason for changing the user limit
* @returns {Promise<StageChannel>}
* @example
* // Set the user limit of a voice channel
* stageChannel.setUserLimit(42)
* .then(channel => console.log(`Set user limit to ${channel.userLimit} for ${channel.name}`))
* .catch(console.error);
*/

/**
* Sets the camera video quality mode of the channel.
* @name StageChannel#setVideoQualityMode
* @param {VideoQualityMode|number} videoQualityMode The new camera video quality mode.
* @param {string} [reason] Reason for changing the camera video quality mode.
* @returns {Promise<StageChannel>}
*/
}

module.exports = StageChannel;

0 comments on commit 7cf9224

Please sign in to comment.