feat(VoiceChannel): Support video_quality_mode (#7722)

This commit is contained in:
Jiralite
2022-04-05 11:26:09 +01:00
committed by GitHub
parent eb6b472f72
commit 3b3dabf3da
5 changed files with 61 additions and 0 deletions

View File

@@ -223,6 +223,7 @@ class GuildChannelManager extends CachedManager {
* @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration] * @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration]
* The default auto archive duration for all new threads in this channel * The default auto archive duration for all new threads in this channel
* @property {?string} [rtcRegion] The RTC region of the 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, bitrate: data.bitrate ?? channel.bitrate,
user_limit: data.userLimit ?? channel.userLimit, user_limit: data.userLimit ?? channel.userLimit,
rtc_region: data.rtcRegion ?? channel.rtcRegion, rtc_region: data.rtcRegion ?? channel.rtcRegion,
video_quality_mode: data.videoQualityMode,
parent_id: parent, parent_id: parent,
lock_permissions: data.lockPermissions, lock_permissions: data.lockPermissions,
rate_limit_per_user: data.rateLimitPerUser, rate_limit_per_user: data.rateLimitPerUser,

View File

@@ -88,6 +88,7 @@ class GuildManager extends CachedManager {
* @property {number} [bitrate] The bitrate of the voice channel * @property {number} [bitrate] The bitrate of the voice channel
* @property {number} [userLimit] The user limit of the channel * @property {number} [userLimit] The user limit of the channel
* @property {?string} [rtcRegion] The RTC region 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] * @property {PartialOverwriteData[]} [permissionOverwrites]
* Overwrites of the channel * Overwrites of the channel
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) of the channel in seconds * @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; delete channel.rateLimitPerUser;
channel.rtc_region = channel.rtcRegion; channel.rtc_region = channel.rtcRegion;
delete channel.rtcRegion; delete channel.rtcRegion;
channel.video_quality_mode = channel.videoQualityMode;
delete channel.videoQualityMode;
if (!channel.permissionOverwrites) continue; if (!channel.permissionOverwrites) continue;
for (const overwrite of channel.permissionOverwrites) { for (const overwrite of channel.permissionOverwrites) {

View File

@@ -8,6 +8,20 @@ const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel');
* @extends {BaseGuildVoiceChannel} * @extends {BaseGuildVoiceChannel}
*/ */
class VoiceChannel 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 * Whether the channel is joinable by the client user
* @type {boolean} * @type {boolean}
@@ -66,6 +80,16 @@ class VoiceChannel extends BaseGuildVoiceChannel {
return this.edit({ userLimit }, reason); 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<VoiceChannel>}
*/
setVideoQualityMode(videoQualityMode, reason) {
return this.edit({ videoQualityMode }, reason);
}
/** /**
* Sets the RTC region of the channel. * Sets the RTC region of the channel.
* @name VoiceChannel#setRTCRegion * @name VoiceChannel#setRTCRegion

View File

@@ -21,6 +21,7 @@ const {
GuildScheduledEventEntityType, GuildScheduledEventEntityType,
IntegrationExpireBehavior, IntegrationExpireBehavior,
AuditLogEvent, AuditLogEvent,
VideoQualityMode,
} = require('discord-api-types/v10'); } = require('discord-api-types/v10');
function unknownKeyStrategy(val) { function unknownKeyStrategy(val) {
@@ -785,6 +786,29 @@ class EnumResolvers extends null {
return unknownKeyStrategy(key); 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 // Precondition logic wrapper

View File

@@ -111,6 +111,7 @@ import {
APIEmbedAuthor, APIEmbedAuthor,
APIEmbedFooter, APIEmbedFooter,
APIEmbedImage, APIEmbedImage,
VideoQualityMode,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process'; import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events'; import { EventEmitter } from 'node:events';
@@ -1003,6 +1004,7 @@ export class EnumResolvers extends null {
key: IntegrationExpireBehaviorEnumResolvable | IntegrationExpireBehavior, key: IntegrationExpireBehaviorEnumResolvable | IntegrationExpireBehavior,
): IntegrationExpireBehavior; ): IntegrationExpireBehavior;
public static resolveAuditLogEvent(key: AuditLogEventEnumResolvable | AuditLogEvent): AuditLogEvent; public static resolveAuditLogEvent(key: AuditLogEventEnumResolvable | AuditLogEvent): AuditLogEvent;
public static resolveVideoQualityMode(key: VideoQualityModeEnumResolvable | VideoQualityMode): VideoQualityMode;
} }
export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete']) { export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete']) {
@@ -2573,10 +2575,12 @@ export type ComponentData =
| ActionRowData<MessageActionRowComponentData | ModalActionRowComponentData>; | ActionRowData<MessageActionRowComponentData | ModalActionRowComponentData>;
export class VoiceChannel extends BaseGuildVoiceChannel { export class VoiceChannel extends BaseGuildVoiceChannel {
public videoQualityMode: VideoQualityMode;
public get speakable(): boolean; public get speakable(): boolean;
public type: ChannelType.GuildVoice; public type: ChannelType.GuildVoice;
public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>; public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>;
public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>; public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>;
public setVideoQualityMode(videoQualityMode: VideoQualityMode, reason?: string): Promise<VoiceChannel>;
} }
export class VoiceRegion { export class VoiceRegion {
@@ -3692,6 +3696,7 @@ export interface ChannelData {
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>; permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX'; defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
rtcRegion?: string | null; rtcRegion?: string | null;
videoQualityMode?: VideoQualityMode | null;
} }
export interface ChannelLogsQueryOptions { export interface ChannelLogsQueryOptions {
@@ -4178,6 +4183,8 @@ export type AuditLogEventEnumResolvable =
| 'THREAD_UPDATE' | 'THREAD_UPDATE'
| 'THREAD_DELETE'; | 'THREAD_DELETE';
export type VideoQualityModeEnumResolvable = 'AUTO' | 'FULL';
export interface ErrorEvent { export interface ErrorEvent {
error: unknown; error: unknown;
message: string; message: string;
@@ -4916,6 +4923,7 @@ export interface PartialChannelData {
bitrate?: number; bitrate?: number;
userLimit?: number; userLimit?: number;
rtcRegion?: string | null; rtcRegion?: string | null;
videoQualityMode?: VideoQualityMode;
permissionOverwrites?: PartialOverwriteData[]; permissionOverwrites?: PartialOverwriteData[];
rateLimitPerUser?: number; rateLimitPerUser?: number;
} }