Skip to content

Commit

Permalink
feat(VoiceChannel): Support video_quality_mode (v13) (#7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Apr 14, 2022
1 parent 68498a8 commit 6daee1b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/managers/GuildChannelManager.js
Expand Up @@ -9,7 +9,7 @@ const GuildChannel = require('../structures/GuildChannel');
const PermissionOverwrites = require('../structures/PermissionOverwrites');
const ThreadChannel = require('../structures/ThreadChannel');
const Webhook = require('../structures/Webhook');
const { ThreadChannelTypes, ChannelTypes } = require('../util/Constants');
const { ThreadChannelTypes, ChannelTypes, VideoQualityModes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Util = require('../util/Util');

Expand Down Expand Up @@ -222,6 +222,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|number} [videoQualityMode] The camera video quality mode of the channel
*/

/**
Expand Down Expand Up @@ -270,6 +271,8 @@ class GuildChannelManager extends CachedManager {
bitrate: data.bitrate ?? channel.bitrate,
user_limit: data.userLimit ?? channel.userLimit,
rtc_region: data.rtcRegion ?? channel.rtcRegion,
video_quality_mode:
typeof data.videoQualityMode === 'string' ? VideoQualityModes[data.videoQualityMode] : data.videoQualityMode,
parent_id: parent,
lock_permissions: data.lockPermissions,
rate_limit_per_user: data.rateLimitPerUser,
Expand Down
7 changes: 7 additions & 0 deletions src/managers/GuildManager.js
Expand Up @@ -18,6 +18,7 @@ const {
VerificationLevels,
DefaultMessageNotificationLevels,
ExplicitContentFilterLevels,
VideoQualityModes,
} = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Permissions = require('../util/Permissions');
Expand Down Expand Up @@ -94,6 +95,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|number} [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
Expand Down Expand Up @@ -200,6 +202,11 @@ class GuildManager extends CachedManager {
delete channel.rateLimitPerUser;
channel.rtc_region = channel.rtcRegion;
delete channel.rtcRegion;
channel.video_quality_mode =
typeof channel.videoQualityMode === 'string'
? VideoQualityModes[channel.videoQualityMode]
: channel.videoQualityMode;
delete channel.videoQualityMode;

if (!channel.permissionOverwrites) continue;
for (const overwrite of channel.permissionOverwrites) {
Expand Down
25 changes: 25 additions & 0 deletions src/structures/VoiceChannel.js
Expand Up @@ -2,6 +2,7 @@

const process = require('node:process');
const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel');
const { VideoQualityModes } = require('../util/Constants');
const Permissions = require('../util/Permissions');

let deprecationEmittedForEditable = false;
Expand All @@ -11,6 +12,20 @@ let deprecationEmittedForEditable = false;
* @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 = VideoQualityModes[data.videoQualityMode];
} else {
this.videoQualityMode ??= null;
}
}

/**
* Whether the channel is editable by the client user
* @type {boolean}
Expand Down Expand Up @@ -87,6 +102,16 @@ class VoiceChannel extends BaseGuildVoiceChannel {
return this.edit({ userLimit }, reason);
}

/**
* 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<VoiceChannel>}
*/
setVideoQualityMode(videoQualityMode, reason) {
return this.edit({ videoQualityMode }, reason);
}

/**
* Sets the RTC region of the channel.
* @name VoiceChannel#setRTCRegion
Expand Down
10 changes: 10 additions & 0 deletions src/util/Constants.js
Expand Up @@ -1203,6 +1203,15 @@ exports.GuildScheduledEventStatuses = createEnum([null, 'SCHEDULED', 'ACTIVE', '
* @see {@link https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types}
*/
exports.GuildScheduledEventEntityTypes = createEnum([null, 'STAGE_INSTANCE', 'VOICE', 'EXTERNAL']);

/**
* The camera video quality mode of a {@link VoiceChannel}:
* * AUTO
* * FULL
* @typedef {string} VideoQualityMode
* @see {@link https://discord.com/developers/docs/resources/channel#channel-object-video-quality-modes}
*/
exports.VideoQualityModes = createEnum([null, 'AUTO', 'FULL']);
/* eslint-enable max-len */

exports._cleanupSymbol = Symbol('djsCleanup');
Expand Down Expand Up @@ -1256,6 +1265,7 @@ function createEnum(keys) {
* @property {StickerFormatType} StickerFormatTypes The value set for a sticker's format type.
* @property {StickerType} StickerTypes The value set for a sticker's type.
* @property {VerificationLevel} VerificationLevels The value set for the verification levels for a guild.
* @property {VideoQualityMode} VideoQualityModes The camera video quality mode for a {@link VoiceChannel}.
* @property {WebhookType} WebhookTypes The value set for a webhook's type.
* @property {WSEventType} WSEvents The type of a WebSocket message event.
*/
5 changes: 5 additions & 0 deletions typings/enums.d.ts
Expand Up @@ -205,6 +205,11 @@ export const enum VerificationLevels {
VERY_HIGH = 4,
}

export const enum VideoQualityModes {
AUTO = 1,
FULL = 2,
}

export const enum WebhookTypes {
Incoming = 1,
'Channel Follower' = 2,
Expand Down
8 changes: 8 additions & 0 deletions typings/index.d.ts
Expand Up @@ -89,6 +89,7 @@ import {
GuildScheduledEventEntityTypes,
GuildScheduledEventStatuses,
GuildScheduledEventPrivacyLevels,
VideoQualityModes,
} from './enums';
import {
RawActivityData,
Expand Down Expand Up @@ -2635,12 +2636,14 @@ export class Formatters extends null {
}

export class VoiceChannel extends BaseGuildVoiceChannel {
public videoQualityMode: VideoQualityMode | null;
/** @deprecated Use manageable instead */
public readonly editable: boolean;
public readonly speakable: boolean;
public type: 'GUILD_VOICE';
public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>;
public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>;
public setVideoQualityMode(videoQualityMode: VideoQualityMode | number, reason?: string): Promise<VoiceChannel>;
}

export class VoiceRegion {
Expand Down Expand Up @@ -2992,6 +2995,7 @@ export const Constants: {
GuildScheduledEventEntityTypes: EnumHolder<typeof GuildScheduledEventEntityTypes>;
GuildScheduledEventStatuses: EnumHolder<typeof GuildScheduledEventStatuses>;
GuildScheduledEventPrivacyLevels: EnumHolder<typeof GuildScheduledEventPrivacyLevels>;
VideoQualityModes: EnumHolder<typeof VideoQualityModes>;
};

export const version: string;
Expand Down Expand Up @@ -4048,6 +4052,7 @@ export interface ChannelData {
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
rtcRegion?: string | null;
videoQualityMode?: VideoQualityMode | null;
}

export interface ChannelLogsQueryOptions {
Expand Down Expand Up @@ -5553,6 +5558,7 @@ export interface PartialChannelData {
bitrate?: number;
userLimit?: number;
rtcRegion?: string | null;
videoQualityMode?: VideoQualityMode;
permissionOverwrites?: PartialOverwriteData[];
rateLimitPerUser?: number;
}
Expand Down Expand Up @@ -5890,6 +5896,8 @@ export interface Vanity {

export type VerificationLevel = keyof typeof VerificationLevels;

export type VideoQualityMode = keyof typeof VideoQualityModes;

export type VoiceBasedChannelTypes = VoiceBasedChannel['type'];

export type VoiceChannelResolvable = Snowflake | VoiceChannel;
Expand Down

0 comments on commit 6daee1b

Please sign in to comment.