Skip to content

Commit

Permalink
feat(StageChannel): add messages (#9134)
Browse files Browse the repository at this point in the history
* feat(StageChannel): add messages

* fix: missing implements jsdoc

* Apply suggestions from code review

Co-authored-by: MateoDeveloper <79017590+Mateo-tem@users.noreply.github.com>

* Update packages/discord.js/src/util/Constants.js

Co-authored-by: MateoDeveloper <79017590+Mateo-tem@users.noreply.github.com>

* feat: use common class

* Apply suggestions from code review

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* feat: add stage to text based channels + fix webhook.channel typings

* fix: some fixes

* Update packages/discord.js/src/structures/BaseGuildVoiceChannel.js

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>

* Update packages/discord.js/src/structures/VoiceChannel.js

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* Update packages/discord.js/src/structures/interfaces/TextBasedChannel.js

Co-authored-by: Aura Román <kyradiscord@gmail.com>

* Update packages/discord.js/src/structures/BaseGuildVoiceChannel.js

Co-authored-by: space <spaceeec@yahoo.com>

---------

Co-authored-by: MateoDeveloper <79017590+Mateo-tem@users.noreply.github.com>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
Co-authored-by: Aura Román <kyradiscord@gmail.com>
Co-authored-by: space <spaceeec@yahoo.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
7 people committed Feb 25, 2023
1 parent 095bd77 commit ffdb197
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 158 deletions.
3 changes: 2 additions & 1 deletion packages/discord.js/src/client/actions/WebhooksUpdate.js
Original file line number Diff line number Diff line change
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.WebhooksUpdate, channel);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class GuildChannelManager extends CachedManager {

/**
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
* @property {TextChannel|NewsChannel|VoiceChannel|ForumChannel|Snowflake} channel
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake} channel
* The channel to create the webhook for
*/

Expand Down
138 changes: 124 additions & 14 deletions packages/discord.js/src/structures/BaseGuildVoiceChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
const { Collection } = require('@discordjs/collection');
const { PermissionFlagsBits } = require('discord-api-types/v10');
const GuildChannel = require('./GuildChannel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const MessageManager = require('../managers/MessageManager');

/**
* 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);

Expand All @@ -35,6 +55,40 @@ class BaseGuildVoiceChannel extends GuildChannel {
*/
this.userLimit = data.user_limit;
}

if ('video_quality_mode' in data) {
/**
* The camera video quality mode of the channel.
* @type {?VideoQualityMode}
*/
this.videoQualityMode = 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.rateLimitPerUser = data.rate_limit_per_user;
}

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

/**
Expand Down Expand Up @@ -80,6 +134,44 @@ class BaseGuildVoiceChannel extends GuildChannel {
);
}

/**
* Creates an invite to this guild channel.
* @param {InviteCreateOptions} [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.
* @param {boolean} [cache=true] Whether 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 +189,46 @@ class BaseGuildVoiceChannel extends GuildChannel {
}

/**
* Creates an invite to this guild channel.
* @param {InviteCreateOptions} [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} 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;
46 changes: 43 additions & 3 deletions packages/discord.js/src/structures/StageChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,33 @@ class StageChannel extends BaseGuildVoiceChannel {
* Sets a new topic for the guild channel.
* @param {?string} topic The new topic for the guild channel
* @param {string} [reason] Reason for changing the guild channel's topic
* @returns {Promise<GuildChannel>}
* @returns {Promise<StageChannel>}
* @example
* // Set a new channel topic
* channel.setTopic('needs more rate limiting')
* .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
* stageChannel.setTopic('needs more rate limiting')
* .then(channel => console.log(`Channel's new topic is ${channel.topic}`))
* .catch(console.error);
*/
setTopic(topic, reason) {
return this.edit({ topic, reason });
}
}

/**
* Sets the bitrate of the channel.
* @method setBitrate
* @memberof StageChannel
* @instance
* @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.
* @method setRTCRegion
Expand All @@ -69,4 +84,29 @@ class StageChannel extends BaseGuildVoiceChannel {
* stageChannel.setRTCRegion(null, 'We want to let Discord decide.');
*/

/**
* Sets the user limit of the channel.
* @method setUserLimit
* @memberof StageChannel
* @instance
* @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.
* @method setVideoQualityMode
* @memberof StageChannel
* @instance
* @param {VideoQualityMode} videoQualityMode The new camera video quality mode.
* @param {string} [reason] Reason for changing the camera video quality mode.
* @returns {Promise<StageChannel>}
*/

module.exports = StageChannel;
Loading

2 comments on commit ffdb197

@vercel
Copy link

@vercel vercel bot commented on ffdb197 Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on ffdb197 Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.