-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add stage channel type * feat: initialise stage channel structure * feat: add STAGE_MODERATOR permissions bitfield * fix: typo in permissions * fix(Channel): type selection logic * feat: add rtcRegion to StageChannel and VoiceChannel * feat: rtc region editing for stage and voice channels * feat: stage channel userLimit * feat: add stage channels to exports * feat: add computed properties to stage channel * feat(VoiceState): include stage channel in docs * feat: allow ability to join stage channels * feat(StageChannel): join and leave methods * docs: add StageChannel link in GuildChannel docs * feat(VoiceState): suppress and requestToSpeakTimestamp * feat(StageChannel): setRequestToSpeak * refactor(StageChannel): update setRequestToSpeak * feat(VoiceState): add moveToSpeakers and moveToAudience * feat(VoiceState): add methods to move in/out of speakers * feat(VoiceState): add stage channel sanity checks * feat(Permissions): add REQUEST_TO_SPEAK * feat(VoiceState): simpler methods * docs(VoiceState): add documentation for new methods * refactor: remove unused error message * chore: remove debug statements * chore: revert changes to package-lock.json * docs(VoiceState): clarify suppress * docs(VoiceState): add missing @type param * feat(StageChannel): remove nsfw property * fix(VoiceState): check permissions in channel Co-authored-by: Advaith <[email protected]> * fix(VoiceState): instantiate error with new Co-authored-by: BannerBomb <[email protected]> * refactor(VoiceState): more readable API route builder Co-authored-by: Sugden <[email protected]> * style(VoiceState): fix lint errors * docs(VoiceState): add example usage for new methods * docs: setRTCRegion examples * chore: update typings * fix(VoiceState): calculate permissions for self * refactor(VoiceState): tidy up implementation * Update src/structures/VoiceState.js Co-authored-by: Jan <[email protected]> * refactor: vaporox's suggestions * style(VoiceState): fix linter errors * chore: update typings * chore: remove unused error message * refactor(VoiceState): use optional chaining Co-authored-by: Sugden <[email protected]> * chore: move getters below constructor in typings * refactor(StageChannel): optional chaining Co-authored-by: Sugden <[email protected]> * style(VoiceState): fix lint errors * docs: fix incorrect types Co-authored-by: izexi <[email protected]> * Update src/structures/VoiceChannel.js Co-authored-by: izexi <[email protected]> * Update src/structures/VoiceChannel.js Co-authored-by: izexi <[email protected]> * refactor(VoiceState): use optional chaining Co-authored-by: Sugden <[email protected]> * refactor(StageChannel): remove permission override check in joinable * refactor: make ChannelTypes a proper enum * Use createEnum Co-authored-by: izexi <[email protected]> * chore: remove unused code from Constants * refactor(StageChannel): remove unnecessary getters * chore: update typings * refactor: introduce BaseGuildVoiceChannel class * refactor(VoiceChannel): reduce code duplication * feat: export BaseGuildVoiceChannel * chore: update typings * docs: fix typos * refactor: move setRTCRegion to BaseGuildVoiceChannel * feat(VoiceState): remove permission checks * chore: update typings * Apply suggestions from code review Co-authored-by: Sugden <[email protected]> Co-authored-by: Jan <[email protected]> * chore: update esm exports and typings * Update src/structures/VoiceState.js Co-authored-by: Vlad Frangu <[email protected]> Co-authored-by: Advaith <[email protected]> Co-authored-by: BannerBomb <[email protected]> Co-authored-by: Sugden <[email protected]> Co-authored-by: Jan <[email protected]> Co-authored-by: izexi <[email protected]> Co-authored-by: Vlad Frangu <[email protected]>
- Loading branch information
1 parent
63ff6a0
commit eec7cf7
Showing
15 changed files
with
320 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
'use strict'; | ||
|
||
const GuildChannel = require('./GuildChannel'); | ||
const Collection = require('../util/Collection'); | ||
const Permissions = require('../util/Permissions'); | ||
|
||
/** | ||
* Represents a voice-based guild channel on Discord. | ||
* @extends {GuildChannel} | ||
*/ | ||
class BaseGuildVoiceChannel extends GuildChannel { | ||
_patch(data) { | ||
super._patch(data); | ||
|
||
/** | ||
* The RTC region for this voice-based channel. This region is automatically selected if `null`. | ||
* @type {?string} | ||
*/ | ||
this.rtcRegion = data.rtc_region; | ||
|
||
/** | ||
* The bitrate of this voice-based channel | ||
* @type {number} | ||
*/ | ||
this.bitrate = data.bitrate; | ||
|
||
/** | ||
* The maximum amount of users allowed in this channel. | ||
* @type {number} | ||
*/ | ||
this.userLimit = data.user_limit; | ||
} | ||
|
||
/** | ||
* The members in this voice-based channel | ||
* @type {Collection<Snowflake, GuildMember>} | ||
* @readonly | ||
*/ | ||
get members() { | ||
const coll = new Collection(); | ||
for (const state of this.guild.voiceStates.cache.values()) { | ||
if (state.channelID === this.id && state.member) { | ||
coll.set(state.id, state.member); | ||
} | ||
} | ||
return coll; | ||
} | ||
|
||
/** | ||
* Checks if the voice-based channel is full | ||
* @type {boolean} | ||
* @readonly | ||
*/ | ||
get full() { | ||
return this.userLimit > 0 && this.members.size >= this.userLimit; | ||
} | ||
|
||
/** | ||
* Whether the channel is joinable by the client user | ||
* @type {boolean} | ||
* @readonly | ||
*/ | ||
get joinable() { | ||
if (!this.viewable) return false; | ||
if (!this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false)) return false; | ||
return true; | ||
} | ||
|
||
/** | ||
* Attempts to join this voice-based channel. | ||
* @returns {Promise<VoiceConnection>} | ||
* @example | ||
* // Join a voice-based channel | ||
* channel.join() | ||
* .then(connection => console.log('Connected!')) | ||
* .catch(console.error); | ||
*/ | ||
join() { | ||
return this.client.voice.joinChannel(this); | ||
} | ||
|
||
/** | ||
* Leaves this voice-based channel. | ||
* @example | ||
* // Leave a voice-based channel | ||
* channel.leave(); | ||
*/ | ||
leave() { | ||
const connection = this.client.voice.connections.get(this.guild.id); | ||
if (connection?.channel.id === this.id) connection.disconnect(); | ||
} | ||
|
||
/** | ||
* Sets the RTC region of the channel. | ||
* @param {?string} region The new region of the channel. Set to `null` to remove a specific region for the channel | ||
* @returns {Promise<BaseGuildVoiceChannel>} | ||
* @example | ||
* // Set the RTC region to europe | ||
* channel.setRTCRegion('europe'); | ||
* @example | ||
* // Remove a fixed region for this channel - let Discord decide automatically | ||
* channel.setRTCRegion(null); | ||
*/ | ||
setRTCRegion(region) { | ||
return this.edit({ rtcRegion: region }); | ||
} | ||
} | ||
|
||
module.exports = BaseGuildVoiceChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel'); | ||
|
||
/** | ||
* Represents a guild stage channel on Discord. | ||
* @extends {BaseGuildVoiceChannel} | ||
*/ | ||
class StageChannel extends BaseGuildVoiceChannel { | ||
_patch(data) { | ||
super._patch(data); | ||
|
||
/** | ||
* The topic of the stage channel | ||
* @type {?string} | ||
*/ | ||
this.topic = data.topic; | ||
} | ||
|
||
/** | ||
* Sets the RTC region of the channel. | ||
* @name StageChannel#setRTCRegion | ||
* @param {?string} region The new region of the channel. Set to `null` to remove a specific region for the channel | ||
* @returns {Promise<StageChannel>} | ||
* @example | ||
* // Set the RTC region to europe | ||
* stageChannel.setRTCRegion('europe'); | ||
* @example | ||
* // Remove a fixed region for this channel - let Discord decide automatically | ||
* stageChannel.setRTCRegion(null); | ||
*/ | ||
} | ||
|
||
module.exports = StageChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.