From 76bb9018c451748eabd16ae1212c45df23af3562 Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Sun, 26 Feb 2023 22:55:23 +0300 Subject: [PATCH] [Feature] Text-In-Stage support & missing IVoiceChannel properties (#2610) * initial commit * add a check for voice/stage channels in `PinAsync` * moar refactoring * Update IStageChannel.cs * forgot about mocked. again. --- .../Entities/Channels/IStageChannel.cs | 8 - .../Entities/Channels/IVoiceChannel.cs | 40 +--- .../Channels/VoiceChannelProperties.cs | 49 +++-- .../API/Rest/ModifyVoiceChannelParams.cs | 2 +- .../Entities/Channels/ChannelHelper.cs | 2 + .../Entities/Channels/RestStageChannel.cs | 6 +- .../Entities/Channels/RestVoiceChannel.cs | 167 +-------------- .../Entities/Messages/MessageHelper.cs | 2 + .../Entities/Channels/SocketStageChannel.cs | 5 +- .../Entities/Channels/SocketVoiceChannel.cs | 199 +----------------- .../MockedEntities/MockedVoiceChannel.cs | 14 ++ 11 files changed, 59 insertions(+), 435 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs index 5e0be5b7..8dbc4c28 100644 --- a/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs @@ -8,14 +8,6 @@ namespace Discord /// public interface IStageChannel : IVoiceChannel { - /// - /// Gets the topic of the Stage instance. - /// - /// - /// If the stage isn't live then this property will be set to . - /// - string Topic { get; } - /// /// Gets the of the current stage. /// diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs index 5973e4a2..5976abe3 100644 --- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs @@ -7,7 +7,7 @@ namespace Discord /// /// Represents a generic voice channel in a guild. /// - public interface IVoiceChannel : IMessageChannel, INestedChannel, IAudioChannel, IMentionable + public interface IVoiceChannel : ITextChannel, IAudioChannel { /// /// Gets the bit-rate that the clients in this voice channel are requested to use. @@ -31,44 +31,6 @@ namespace Discord /// VideoQualityMode VideoQualityMode { get; } - /// - /// Bulk-deletes multiple messages. - /// - /// - /// The following example gets 250 messages from the channel and deletes them. - /// - /// var messages = await voiceChannel.GetMessagesAsync(250).FlattenAsync(); - /// await voiceChannel.DeleteMessagesAsync(messages); - /// - /// - /// - /// This method attempts to remove the messages specified in bulk. - /// - /// Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days! - /// - /// - /// The messages to be bulk-deleted. - /// The options to be used when sending the request. - /// - /// A task that represents the asynchronous bulk-removal operation. - /// - Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null); - /// - /// Bulk-deletes multiple messages. - /// - /// - /// This method attempts to remove the messages specified in bulk. - /// - /// Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days! - /// - /// - /// The snowflake identifier of the messages to be bulk-deleted. - /// The options to be used when sending the request. - /// - /// A task that represents the asynchronous bulk-removal operation. - /// - Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null); - /// /// Modifies this voice channel. /// diff --git a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs index 417e391c..30d692d6 100644 --- a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs @@ -1,26 +1,33 @@ -namespace Discord +using System; + +namespace Discord; + +/// +/// Provides properties that are used to modify an with the specified changes. +/// +public class VoiceChannelProperties : TextChannelProperties { /// - /// Provides properties that are used to modify an with the specified changes. + /// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000. /// - public class VoiceChannelProperties : GuildChannelProperties - { - /// - /// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000. - /// - public Optional Bitrate { get; set; } - /// - /// Gets or sets the maximum number of users that can be present in a channel, or null if none. - /// - public Optional UserLimit { get; set; } - /// - /// Gets or sets the channel voice region id, automatic when set to . - /// - public Optional RTCRegion { get; set; } + public Optional Bitrate { get; set; } + /// + /// Gets or sets the maximum number of users that can be present in a channel, or null if none. + /// + public Optional UserLimit { get; set; } + /// + /// Gets or sets the channel voice region id, automatic when set to . + /// + public Optional RTCRegion { get; set; } - /// - /// Get or sets the video quality mode for this channel. - /// - public Optional VideoQualityMode { get; set; } - } + /// + /// Get or sets the video quality mode for this channel. + /// + public Optional VideoQualityMode { get; set; } + + /// + /// Not supported in voice channels + /// + /// + public new Optional Topic { get; } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs index 2f8cacc6..0f0c6ccf 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; namespace Discord.API.Rest { [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class ModifyVoiceChannelParams : ModifyGuildChannelParams + internal class ModifyVoiceChannelParams : ModifyTextChannelParams { [JsonProperty("bitrate")] public Optional Bitrate { get; set; } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index fbfa0f3d..3e1d0a60 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -91,6 +91,8 @@ namespace Discord.Rest Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() : Optional.Create(), + SlowModeInterval = args.SlowModeInterval, + IsNsfw = args.IsNsfw, }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs index bbb68932..47a19967 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs @@ -13,10 +13,12 @@ namespace Discord.Rest { /// /// - /// This field is always false for stage channels. + /// This field is always true for stage channels. /// + /// + [Obsolete("This property is no longer used because Discord enabled text-in-voice and text-in-stage for all channels.")] public override bool IsTextInVoice - => false; + => true; /// public StagePrivacyLevel? PrivacyLevel { get; private set; } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index df5b187f..eac40538 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -19,7 +19,9 @@ namespace Discord.Rest /// /// Gets whether or not the guild has Text-In-Voice enabled and the voice channel is a TiV channel. /// + [Obsolete("This property is no longer used because Discord enabled text-in-voice for all channels.")] public virtual bool IsTextInVoice => true; + /// public int Bitrate { get; private set; } /// @@ -62,11 +64,6 @@ namespace Discord.Rest Update(model); } - /// - /// Cannot modify text channel properties of a voice channel. - public override Task ModifyAsync(Action func, RequestOptions options = null) - => throw new InvalidOperationException("Cannot modify text channel properties of a voice channel"); - /// /// Cannot create a thread within a voice channel. public override Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) @@ -78,166 +75,6 @@ namespace Discord.Rest #region TextOverrides - /// This function is only supported in Text-In-Voice channels. - public override Task GetMessageAsync(ulong id, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessageAsync(id, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessageAsync(message, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessageAsync(messageId, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessagesAsync(messages, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessagesAsync(messageIds, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IDisposable EnterTypingState(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.EnterTypingState(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(fromMessage, dir, limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(fromMessageId, dir, limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task> GetPinnedMessagesAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetPinnedMessagesAsync(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task GetWebhookAsync(ulong id, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetWebhookAsync(id, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task> GetWebhooksAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetWebhooksAsync(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.CreateWebhookAsync(name, avatar, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.ModifyMessageAsync(messageId, func, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task TriggerTypingAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.TriggerTypingAsync(options); - } - /// Threads are not supported in voice channels public override Task> GetActiveThreadsAsync(RequestOptions options = null) => throw new NotSupportedException("Threads are not supported in voice channels"); diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 1cb9f07e..384be196 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -212,6 +212,8 @@ namespace Discord.Rest public static async Task PinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { + if (msg.Channel is IVoiceChannel) + throw new NotSupportedException("Pinned messages are not supported in text-in-voice channels."); await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs index 4983bc46..c7aea573 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs @@ -16,10 +16,11 @@ namespace Discord.WebSocket { /// /// - /// This field is always false for stage channels. + /// This field is always true for stage channels. /// + [Obsolete("This property is no longer used because Discord enabled text-in-stage for all channels.")] public override bool IsTextInVoice - => false; + => true; /// public StagePrivacyLevel? PrivacyLevel { get; private set; } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index 2993feda..6e3b9a77 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -23,9 +23,10 @@ namespace Discord.WebSocket /// /// /// Discord currently doesn't have a way to disable Text-In-Voice yet so this field is always - /// on s and on + /// on s and on /// s. /// + [Obsolete("This property is no longer used because Discord enabled text-in-voice for all channels.")] public virtual bool IsTextInVoice => true; /// @@ -99,206 +100,10 @@ namespace Discord.WebSocket public override Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) => throw new InvalidOperationException("Voice channels cannot contain threads."); - /// Cannot modify text channel properties for voice channels. - public override Task ModifyAsync(Action func, RequestOptions options = null) - => throw new InvalidOperationException("Cannot modify text channel properties for voice channels."); - #endregion #region TextOverrides - /// This function is only supported in Text-In-Voice channels. - public override Task GetMessageAsync(ulong id, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessageAsync(id, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessageAsync(message, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessageAsync(messageId, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessagesAsync(messages, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.DeleteMessagesAsync(messageIds, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IDisposable EnterTypingState(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.EnterTypingState(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override SocketMessage GetCachedMessage(ulong id) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetCachedMessage(id); - } - - /// This function is only supported in Text-In-Voice channels. - public override IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = 100) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetCachedMessages(fromMessage, dir, limit); - } - - /// This function is only supported in Text-In-Voice channels. - public override IReadOnlyCollection GetCachedMessages(int limit = 100) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetCachedMessages(limit); - } - - /// This function is only supported in Text-In-Voice channels. - public override IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = 100) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetCachedMessages(fromMessageId, dir, limit); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(fromMessage, dir, limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = 100, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetMessagesAsync(fromMessageId, dir, limit, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task> GetPinnedMessagesAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetPinnedMessagesAsync(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task GetWebhookAsync(ulong id, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetWebhookAsync(id, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task> GetWebhooksAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.GetWebhooksAsync(options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.CreateWebhookAsync(name, avatar, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.ModifyMessageAsync(messageId, func, options); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags); - } - - /// This function is only supported in Text-In-Voice channels. - public override Task TriggerTypingAsync(RequestOptions options = null) - { - if (!IsTextInVoice) - throw new NotSupportedException("This function is only supported in Text-In-Voice channels"); - return base.TriggerTypingAsync(options); - } - /// Threads are not supported in voice channels public override Task> GetActiveThreadsAsync(RequestOptions options = null) => throw new NotSupportedException("Threads are not supported in voice channels"); diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs index 3373ec93..30328877 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs @@ -12,9 +12,17 @@ namespace Discord public int Bitrate => throw new NotImplementedException(); public int? UserLimit => throw new NotImplementedException(); + public string Topic { get; } + public int SlowModeInterval { get; } + public ThreadArchiveDuration DefaultArchiveDuration { get; } public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => throw new NotImplementedException(); public Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) => throw new NotImplementedException(); + public Task ModifyAsync(Action func, RequestOptions options = null) => throw new NotImplementedException(); + + public Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) => throw new NotImplementedException(); + + public Task> GetActiveThreadsAsync(RequestOptions options = null) => throw new NotImplementedException(); public ulong? CategoryId => throw new NotImplementedException(); @@ -39,6 +47,7 @@ namespace Discord public ChannelFlags Flags => throw new NotImplementedException(); public VideoQualityMode VideoQualityMode => throw new NotImplementedException(); + public bool IsNsfw { get; } public Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) => throw new NotImplementedException(); public Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) => throw new NotImplementedException(); @@ -78,5 +87,10 @@ namespace Discord public Task TriggerTypingAsync(RequestOptions options = null) => throw new NotImplementedException(); Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => throw new NotImplementedException(); IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => throw new NotImplementedException(); + public Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) => throw new NotImplementedException(); + + public Task GetWebhookAsync(ulong id, RequestOptions options = null) => throw new NotImplementedException(); + + public Task> GetWebhooksAsync(RequestOptions options = null) => throw new NotImplementedException(); } }