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]
* 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,

View File

@@ -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) {

View File

@@ -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<VoiceChannel>}
*/
setVideoQualityMode(videoQualityMode, reason) {
return this.edit({ videoQualityMode }, reason);
}
/**
* Sets the RTC region of the channel.
* @name VoiceChannel#setRTCRegion

View File

@@ -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

View File

@@ -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<MessageActionRowComponentData | ModalActionRowComponentData>;
export class VoiceChannel extends BaseGuildVoiceChannel {
public videoQualityMode: VideoQualityMode;
public get speakable(): boolean;
public type: ChannelType.GuildVoice;
public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>;
public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>;
public setVideoQualityMode(videoQualityMode: VideoQualityMode, reason?: string): Promise<VoiceChannel>;
}
export class VoiceRegion {
@@ -3692,6 +3696,7 @@ export interface ChannelData {
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
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;
}