From 3b3dabf3da2e2f24b81967d68b581d7f7452273f Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 5 Apr 2022 11:26:09 +0100 Subject: [PATCH] feat(VoiceChannel): Support `video_quality_mode` (#7722) --- .../src/managers/GuildChannelManager.js | 2 ++ .../discord.js/src/managers/GuildManager.js | 3 +++ .../discord.js/src/structures/VoiceChannel.js | 24 +++++++++++++++++++ packages/discord.js/src/util/EnumResolvers.js | 24 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 8 +++++++ 5 files changed, 61 insertions(+) diff --git a/packages/discord.js/src/managers/GuildChannelManager.js b/packages/discord.js/src/managers/GuildChannelManager.js index 1cfb10fb6..fca3c75fd 100644 --- a/packages/discord.js/src/managers/GuildChannelManager.js +++ b/packages/discord.js/src/managers/GuildChannelManager.js @@ -223,6 +223,7 @@ class GuildChannelManager extends CachedManager { * @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration] * The default auto archive duration for all new threads in this channel * @property {?string} [rtcRegion] The RTC region of the channel + * @property {?VideoQualityMode} [videoQualityMode] The camera video quality mode of the channel */ /** @@ -274,6 +275,7 @@ class GuildChannelManager extends CachedManager { bitrate: data.bitrate ?? channel.bitrate, user_limit: data.userLimit ?? channel.userLimit, rtc_region: data.rtcRegion ?? channel.rtcRegion, + video_quality_mode: data.videoQualityMode, parent_id: parent, lock_permissions: data.lockPermissions, rate_limit_per_user: data.rateLimitPerUser, diff --git a/packages/discord.js/src/managers/GuildManager.js b/packages/discord.js/src/managers/GuildManager.js index 4b0bca122..8c45a126a 100644 --- a/packages/discord.js/src/managers/GuildManager.js +++ b/packages/discord.js/src/managers/GuildManager.js @@ -88,6 +88,7 @@ class GuildManager extends CachedManager { * @property {number} [bitrate] The bitrate of the voice channel * @property {number} [userLimit] The user limit of the channel * @property {?string} [rtcRegion] The RTC region of the channel + * @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the channel * @property {PartialOverwriteData[]} [permissionOverwrites] * Overwrites of the channel * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) of the channel in seconds @@ -185,6 +186,8 @@ class GuildManager extends CachedManager { delete channel.rateLimitPerUser; channel.rtc_region = channel.rtcRegion; delete channel.rtcRegion; + channel.video_quality_mode = channel.videoQualityMode; + delete channel.videoQualityMode; if (!channel.permissionOverwrites) continue; for (const overwrite of channel.permissionOverwrites) { diff --git a/packages/discord.js/src/structures/VoiceChannel.js b/packages/discord.js/src/structures/VoiceChannel.js index b4cbd1060..c1f12a80e 100644 --- a/packages/discord.js/src/structures/VoiceChannel.js +++ b/packages/discord.js/src/structures/VoiceChannel.js @@ -8,6 +8,20 @@ const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel'); * @extends {BaseGuildVoiceChannel} */ class VoiceChannel extends BaseGuildVoiceChannel { + _patch(data) { + super._patch(data); + + 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; + } + } + /** * Whether the channel is joinable by the client user * @type {boolean} @@ -66,6 +80,16 @@ class VoiceChannel extends BaseGuildVoiceChannel { return this.edit({ userLimit }, reason); } + /** + * 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} + */ + setVideoQualityMode(videoQualityMode, reason) { + return this.edit({ videoQualityMode }, reason); + } + /** * Sets the RTC region of the channel. * @name VoiceChannel#setRTCRegion diff --git a/packages/discord.js/src/util/EnumResolvers.js b/packages/discord.js/src/util/EnumResolvers.js index 5f036e2a2..4ac9ae1f9 100644 --- a/packages/discord.js/src/util/EnumResolvers.js +++ b/packages/discord.js/src/util/EnumResolvers.js @@ -21,6 +21,7 @@ const { GuildScheduledEventEntityType, IntegrationExpireBehavior, AuditLogEvent, + VideoQualityMode, } = require('discord-api-types/v10'); function unknownKeyStrategy(val) { @@ -785,6 +786,29 @@ class EnumResolvers extends null { return unknownKeyStrategy(key); } } + + /** + * A string that can be resolved to a {@link VideoQualityMode} enum value. Here are the available types: + * * AUTO (automatic) + * * FULL (720p) + * @typedef {string} VideoQualityModeEnumResolvable + */ + + /** + * Resolves enum key to {@link VideoQualityMode} enum value + * @param {VideoQualityModeEnumResolvable|VideoQualityMode} key The key to lookup + * @returns {VideoQualityMode} + */ + static resolveVideoQualityMode(key) { + switch (key) { + case 'AUTO': + return VideoQualityMode.Auto; + case 'FULL': + return VideoQualityMode.Full; + default: + return unknownKeyStrategy(key); + } + } } // Precondition logic wrapper diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 509010e29..cb206472b 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -111,6 +111,7 @@ import { APIEmbedAuthor, APIEmbedFooter, APIEmbedImage, + VideoQualityMode, } from 'discord-api-types/v10'; import { ChildProcess } from 'node:child_process'; import { EventEmitter } from 'node:events'; @@ -1003,6 +1004,7 @@ export class EnumResolvers extends null { key: IntegrationExpireBehaviorEnumResolvable | IntegrationExpireBehavior, ): IntegrationExpireBehavior; public static resolveAuditLogEvent(key: AuditLogEventEnumResolvable | AuditLogEvent): AuditLogEvent; + public static resolveVideoQualityMode(key: VideoQualityModeEnumResolvable | VideoQualityMode): VideoQualityMode; } export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete']) { @@ -2573,10 +2575,12 @@ export type ComponentData = | ActionRowData; export class VoiceChannel extends BaseGuildVoiceChannel { + public videoQualityMode: VideoQualityMode; public get speakable(): boolean; public type: ChannelType.GuildVoice; public setBitrate(bitrate: number, reason?: string): Promise; public setUserLimit(userLimit: number, reason?: string): Promise; + public setVideoQualityMode(videoQualityMode: VideoQualityMode, reason?: string): Promise; } export class VoiceRegion { @@ -3692,6 +3696,7 @@ export interface ChannelData { permissionOverwrites?: readonly OverwriteResolvable[] | Collection; defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX'; rtcRegion?: string | null; + videoQualityMode?: VideoQualityMode | null; } export interface ChannelLogsQueryOptions { @@ -4178,6 +4183,8 @@ export type AuditLogEventEnumResolvable = | 'THREAD_UPDATE' | 'THREAD_DELETE'; +export type VideoQualityModeEnumResolvable = 'AUTO' | 'FULL'; + export interface ErrorEvent { error: unknown; message: string; @@ -4916,6 +4923,7 @@ export interface PartialChannelData { bitrate?: number; userLimit?: number; rtcRegion?: string | null; + videoQualityMode?: VideoQualityMode; permissionOverwrites?: PartialOverwriteData[]; rateLimitPerUser?: number; }