From 304229071f4128c91ceeff7a6727fe2c83568b98 Mon Sep 17 00:00:00 2001 From: z03h Date: Sat, 17 Apr 2021 05:10:41 -0700 Subject: [PATCH] Add VoiceChannel.video_quality_mode --- discord/abc.py | 9 ++++++++- discord/audit_logs.py | 9 +++++++++ discord/channel.py | 23 +++++++++++++++++++++-- discord/enums.py | 8 ++++++++ discord/guild.py | 4 ++++ discord/http.py | 2 ++ docs/api.rst | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 3 deletions(-) diff --git a/discord/abc.py b/discord/abc.py index 73376b7c6..560f70e75 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -31,7 +31,7 @@ from typing import TYPE_CHECKING, Optional, Protocol, runtime_checkable from .iterators import HistoryIterator from .context_managers import Typing -from .enums import ChannelType +from .enums import ChannelType, VideoQualityMode from .errors import InvalidArgument, ClientException from .mentions import AllowedMentions from .permissions import PermissionOverwrite, Permissions @@ -266,6 +266,13 @@ class GuildChannel(Protocol): else: options['rtc_region'] = None if rtc_region is None else str(rtc_region) + try: + video_quality_mode = options.pop('video_quality_mode') + except KeyError: + pass + else: + options['video_quality_mode'] = int(video_quality_mode) + lock_permissions = options.pop('sync_permissions', False) try: diff --git a/discord/audit_logs.py b/discord/audit_logs.py index dbac7630d..c129fea8d 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -102,6 +102,12 @@ def _transform_overwrites(entry, data): return overwrites +def _transform_voiceregion(entry, data): + return enums.try_enum(enums.VoiceRegion, data) + +def _transform_video_quality_mode(entry, data): + return enums.try_enum(enums.VideoQualityMode, data) + class AuditLogDiff: def __len__(self): return len(self.__dict__) @@ -134,6 +140,9 @@ class AuditLogChanges: 'avatar_hash': ('avatar', None), 'rate_limit_per_user': ('slowmode_delay', None), 'default_message_notifications': ('default_notifications', _transform_default_notifications), + 'region': (None, _transform_voiceregion), + 'rtc_region': (None, _transform_voiceregion), + 'video_quality_mode': (None, _transform_video_quality_mode), } def __init__(self, entry, data: List[AuditLogChangePayload]): diff --git a/discord/channel.py b/discord/channel.py index 57ec56ca1..0ecf89e8c 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -27,7 +27,7 @@ import asyncio import discord.abc from .permissions import Permissions -from .enums import ChannelType, try_enum, VoiceRegion +from .enums import ChannelType, try_enum, VoiceRegion, VideoQualityMode from .mixins import Hashable from . import utils from .asset import Asset @@ -541,7 +541,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable): __slots__ = ('name', 'id', 'guild', 'bitrate', 'user_limit', '_state', 'position', '_overwrites', 'category_id', - 'rtc_region') + 'rtc_region', 'video_quality_mode') def __init__(self, *, state, guild, data): self._state = state @@ -560,6 +560,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha self.rtc_region = data.get('rtc_region') if self.rtc_region: self.rtc_region = try_enum(VoiceRegion, self.rtc_region) + self.video_quality_mode = try_enum(VideoQualityMode, data.get('video_quality_mode', 1)) self.category_id = utils._get_as_snowflake(data, 'parent_id') self.position = data['position'] self.bitrate = data.get('bitrate') @@ -654,6 +655,10 @@ class VoiceChannel(VocalGuildChannel): A value of ``None`` indicates automatic voice region detection. .. versionadded:: 1.7 + video_quality_mode: :class:`VideoQualityMode` + The camera video quality for the voice channel's participants. + + .. versionadded:: 2.0 """ __slots__ = () @@ -665,6 +670,7 @@ class VoiceChannel(VocalGuildChannel): ('rtc_region', self.rtc_region), ('position', self.position), ('bitrate', self.bitrate), + ('video_quality_mode', self.video_quality_mode), ('user_limit', self.user_limit), ('category_id', self.category_id) ] @@ -720,6 +726,10 @@ class VoiceChannel(VocalGuildChannel): A value of ``None`` indicates automatic voice region detection. .. versionadded:: 1.7 + video_quality_mode: :class:`VideoQualityMode` + The camera video quality for the voice channel's participants. + + .. versionadded:: 2.0 Raises ------ @@ -778,6 +788,10 @@ class StageChannel(VocalGuildChannel): rtc_region: Optional[:class:`VoiceRegion`] The region for the stage channel's voice communication. A value of ``None`` indicates automatic voice region detection. + video_quality_mode: :class:`VideoQualityMode` + The camera video quality for the stage channel's participants. + + .. versionadded:: 2.0 """ __slots__ = ('topic',) @@ -789,6 +803,7 @@ class StageChannel(VocalGuildChannel): ('rtc_region', self.rtc_region), ('position', self.position), ('bitrate', self.bitrate), + ('video_quality_mode', self.video_quality_mode), ('user_limit', self.user_limit), ('category_id', self.category_id) ] @@ -845,6 +860,10 @@ class StageChannel(VocalGuildChannel): rtc_region: Optional[:class:`VoiceRegion`] The new region for the stage channel's voice communication. A value of ``None`` indicates automatic voice region detection. + video_quality_mode: :class:`VideoQualityMode` + The camera video quality for the stage channel's participants. + + .. versionadded:: 2.0 Raises ------ diff --git a/discord/enums.py b/discord/enums.py index b83001da5..c2ccb037f 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -46,6 +46,7 @@ __all__ = ( 'ExpireBehaviour', 'ExpireBehavior', 'StickerType', + 'VideoQualityMode', ) def _create_value_cls(name): @@ -428,6 +429,13 @@ class InteractionType(Enum): ping = 1 application_command = 2 +class VideoQualityMode(Enum): + auto = 1 + full = 2 + + def __int__(self): + return self.value + T = TypeVar('T') def create_unknown_value(cls: Type[T], val: Any) -> T: diff --git a/discord/guild.py b/discord/guild.py index 20eff90ba..0dfb17397 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -867,6 +867,10 @@ class Guild(Hashable): A value of ``None`` indicates automatic voice region detection. .. versionadded:: 1.7 + video_quality_mode: :class:`VideoQualityMode` + The camera video quality for the voice channel's participants. + + .. versionadded:: 2.0 Raises ------ diff --git a/discord/http.py b/discord/http.py index 6aba2d21d..608487e86 100644 --- a/discord/http.py +++ b/discord/http.py @@ -681,6 +681,7 @@ class HTTPClient: 'rate_limit_per_user', 'type', 'rtc_region', + 'video_quality_mode', ) payload = {k: v for k, v in options.items() if k in valid_keys} return self.request(r, reason=reason, json=payload) @@ -705,6 +706,7 @@ class HTTPClient: 'permission_overwrites', 'rate_limit_per_user', 'rtc_region', + 'video_quality_mode', ) payload.update({k: v for k, v in options.items() if k in valid_keys and v is not None}) diff --git a/docs/api.rst b/docs/api.rst index d20a62c2a..7f461cf4f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1413,6 +1413,8 @@ of :class:`enum.Enum`. - :attr:`~AuditLogDiff.overwrites` - :attr:`~AuditLogDiff.topic` - :attr:`~AuditLogDiff.bitrate` + - :attr:`~AuditLogDiff.rtc_region` + - :attr:`~AuditLogDiff.video_quality_mode` .. attribute:: channel_delete @@ -1945,6 +1947,20 @@ of :class:`enum.Enum`. Represents a sticker with a lottie image. +.. class:: VideoQualityMode + + Represents the camera video quality mode for voice channel participants. + + .. versionadded:: 2.0 + + .. attribute:: auto + + Represents auto camera video quality. + + .. attribute:: full + + Represents full camera video quality. + Async Iterator ---------------- @@ -2482,6 +2498,23 @@ AuditLogDiff :type: :class:`int` + .. attribute:: rtc_region + + The region for the voice channel’s voice communication. + A value of ``None`` indicates automatic voice region detection. + + See also :attr:`VoiceChannel.rtc_region`. + + :type: :class:`VoiceRegion` + + .. attribute:: video_quality_mode + + The camera video quality for the voice channel's participants. + + See also :attr:`VoiceChannel.video_quality_mode`. + + :type: :class:`VideoQualityMode` + .. this is currently missing the following keys: reason and application_id I'm not sure how to about porting these