diff --git a/README.md b/README.md index f8e4d2839..4074c1c17 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Discord.Net Labs -[![NuGet](https://img.shields.io/nuget/vpre/Discord.Net.Labs.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net.Labs) +[![NuGet](https://img.shields.io/nuget/vpre/Discord.Net.Labs.svg?maxAge=2592000&logo=nuget)](https://www.nuget.org/packages/Discord.Net.Labs) [![Discord](https://discord.com/api/guilds/848176216011046962/widget.png)](https://discord.gg/dvSfUTet3K) This repo is a custom fork of Discord.Net that introduces the newest features of discord for testing and experimenting. Nothing here is guaranteed to work but you are more than welcome to submit bugs in the issues tabs diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e8d30a365..177f91d33 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,6 +2,7 @@ variables: buildConfiguration: Release buildTag: $[ startsWith(variables['Build.SourceBranch'], 'refs/tags') ] buildNumber: $[ variables['Build.BuildNumber'] ] + suffix: $(Date:yyyyMMdd) trigger: tags: diff --git a/src/Discord.Net.Commands/Discord.Net.Commands.csproj b/src/Discord.Net.Commands/Discord.Net.Commands.csproj index 84bc5b84b..4f6a47c15 100644 --- a/src/Discord.Net.Commands/Discord.Net.Commands.csproj +++ b/src/Discord.Net.Commands/Discord.Net.Commands.csproj @@ -7,7 +7,6 @@ A Discord.Net Labs extension adding support for bot commands. net461;netstandard2.0;netstandard2.1 netstandard2.0;netstandard2.1 - 3.0.1 Discord.Net.Labs.Commands https://github.com/Discord-Net-Labs/Discord.Net-Labs https://github.com/Discord-Net-Labs/Discord.Net-Labs diff --git a/src/Discord.Net.Core/Discord.Net.Core.csproj b/src/Discord.Net.Core/Discord.Net.Core.csproj index b52aba214..036717e8d 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.csproj +++ b/src/Discord.Net.Core/Discord.Net.Core.csproj @@ -8,12 +8,9 @@ net461;netstandard2.0;netstandard2.1 netstandard2.0;netstandard2.1 Discord.Net.Labs.Core - 3.1.1 Discord.Net.Labs.Core https://github.com/Discord-Net-Labs/Discord.Net-Labs Temporary.png - 3.1.1 - 3.1.1 false diff --git a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs index 4abf84eb3..16855b818 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs @@ -50,7 +50,8 @@ namespace Discord } /// - /// A 1-100 length description of this slash command + /// A 1-100 length description of this slash command. + /// The description is not allowed to be null. /// public string Description { @@ -60,6 +61,7 @@ namespace Discord } set { + Preconditions.NotNullOrEmpty(value, nameof(Description)); Preconditions.AtLeast(value.Length, 1, nameof(Description)); Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description)); diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj index fcc005402..725feb766 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj +++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj @@ -9,11 +9,8 @@ netstandard2.0;netstandard2.1 Temporary.png https://github.com/Discord-Net-Labs/Discord.Net-Labs - 3.1.1 Discord.Net.Labs.Rest https://github.com/Discord-Net-Labs/Discord.Net-Labs - 3.1.1 - 3.1.1 ..\Discord.Net.Rest\Discord.Net.Rest.xml diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 461981e28..19fc82fce 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -320,6 +320,7 @@ namespace Discord.API var model = await SendAsync("GET", () => $"channels/{channelId}", ids, options: options).ConfigureAwait(false); if (!model.GuildId.IsSpecified || model.GuildId.Value != guildId) return null; + return model; } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } @@ -338,11 +339,16 @@ namespace Discord.API Preconditions.NotNull(args, nameof(args)); Preconditions.GreaterThan(args.Bitrate, 0, nameof(args.Bitrate)); Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + Preconditions.LessThan(args.Name.Length, 100, nameof(args.Name)); + if (args.Topic.IsSpecified) + Preconditions.LessThan(args.Topic.Value.Length, 1024, nameof(args.Name)); + options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); return await SendJsonAsync("POST", () => $"guilds/{guildId}/channels", args, ids, options: options).ConfigureAwait(false); } + public async Task DeleteChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -366,18 +372,23 @@ namespace Discord.API Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + Preconditions.LessThan(args.Name.Value.Length, 100, nameof(args.Name)); + options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyTextChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + Preconditions.LessThan(args.Name.Value.Length, 100, nameof(args.Name)); + Preconditions.LessThan(args.Topic.Value.Length, 1024, nameof(args.Name)); Preconditions.AtLeast(args.SlowModeInterval, 0, nameof(args.SlowModeInterval)); Preconditions.AtMost(args.SlowModeInterval, 21600, nameof(args.SlowModeInterval)); options = RequestOptions.CreateOrClone(options); @@ -385,6 +396,7 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyVoiceChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -392,12 +404,13 @@ namespace Discord.API Preconditions.AtLeast(args.Bitrate, 8000, nameof(args.Bitrate)); Preconditions.AtLeast(args.UserLimit, 0, nameof(args.UserLimit)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelsAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -441,7 +454,7 @@ namespace Discord.API return await SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/threads", args, bucket, options: options).ConfigureAwait(false); } - + public async Task StartThreadAsync(ulong channelId, StartThreadParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -592,7 +605,7 @@ namespace Discord.API #region Stage public async Task CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) { - + options = RequestOptions.CreateOrClone(options); var bucket = new BucketIds(); @@ -636,7 +649,7 @@ namespace Discord.API { return await SendAsync("POST", () => $"stage-instances/{channelId}", bucket, options: options).ConfigureAwait(false); } - catch(HttpException httpEx) when (httpEx.HttpCode == HttpStatusCode.NotFound) + catch (HttpException httpEx) when (httpEx.HttpCode == HttpStatusCode.NotFound) { return null; } @@ -1137,7 +1150,7 @@ namespace Discord.API { return await SendAsync("GET", () => $"applications/{CurrentUserId}/commands/{id}", new BucketIds(), options: options).ConfigureAwait(false); } - catch(HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } + catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } } public async Task CreateGlobalApplicationCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) @@ -1208,7 +1221,7 @@ namespace Discord.API { return await SendAsync("GET", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", bucket, options: options); } - catch(HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } + catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } } public async Task CreateGuildApplicationCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) @@ -1236,7 +1249,7 @@ namespace Discord.API var bucket = new BucketIds(guildId: guildId); - return await TrySendApplicationCommandAsync(SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options)).ConfigureAwait(false); + return await TrySendApplicationCommandAsync(SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options)).ConfigureAwait(false); } public async Task DeleteGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) { @@ -1260,7 +1273,7 @@ namespace Discord.API #region Interaction Responses public async Task CreateInteractionResponseAsync(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) { - if(response.Data.IsSpecified && response.Data.Value.Content.IsSpecified) + if (response.Data.IsSpecified && response.Data.Value.Content.IsSpecified) Preconditions.AtMost(response.Data.Value.Content.Value?.Length ?? 0, 2000, nameof(response.Data.Value.Content)); options = RequestOptions.CreateOrClone(options); @@ -1309,7 +1322,7 @@ namespace Discord.API Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(id, 0, nameof(id)); - if(args.Content.IsSpecified) + if (args.Content.IsSpecified) if (args.Content.Value.Length > DiscordConfig.MaxMessageSize) throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); @@ -2102,7 +2115,7 @@ namespace Discord.API else return result; } - catch(HttpException x) + catch (HttpException x) { if (x.HttpCode == HttpStatusCode.BadRequest) { diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index 8f9163692..5dbf78f58 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -195,7 +195,7 @@ namespace Discord.Rest if (args.Name.IsSpecified) { Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); - Preconditions.AtLeast(args.Name.Value.Length, 3, nameof(args.Name)); + Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); } var model = new Discord.API.Rest.ModifyApplicationCommandParams() diff --git a/src/Discord.Net.WebSocket/Discord - Backup.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord - Backup.Net.WebSocket.csproj deleted file mode 100644 index e3a5104e7..000000000 --- a/src/Discord.Net.WebSocket/Discord - Backup.Net.WebSocket.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Discord.Net.WebSocket - Discord.WebSocket - A core Discord.Net Labs library containing the WebSocket client and models. - net461;netstandard2.0;netstandard2.1 - netstandard2.0;netstandard2.1 - true - 2.3.1 - https://github.com/Discord-Net-Labs/Discord.Net-Labs - https://github.com/Discord-Net-Labs/Discord.Net-Labs - Temporary.png - Discord.Net.Labs.WebSocket - - - - - - - - True - - - - diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index 4947db946..992c789c5 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -8,7 +8,6 @@ net461;netstandard2.0;netstandard2.1 netstandard2.0;netstandard2.1 true - 3.1.1 https://github.com/Discord-Net-Labs/Discord.Net-Labs https://github.com/Discord-Net-Labs/Discord.Net-Labs Temporary.png @@ -16,8 +15,6 @@ ..\Discord.Net.WebSocket\Discord.Net.WebSocket.xml - 3.1.1 - 3.1.1 TRACE diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs index aa3a915ae..849ce4df8 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs @@ -10,9 +10,9 @@ using System.IO; namespace Discord.WebSocket { -/// -/// Represents a Websocket-based interaction type for Message Components. -/// + /// + /// Represents a Websocket-based interaction type for Message Components. + /// public class SocketMessageComponent : SocketInteraction { /// @@ -84,16 +84,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -150,9 +143,9 @@ namespace Discord.WebSocket if (args.AllowedMentions.IsSpecified) { - var allowedMentions = args.AllowedMentions.Value; - Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 role Ids are allowed."); - Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); + var allowedMentions = args.AllowedMentions.Value; + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); } var embed = args.Embed; @@ -227,16 +220,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -273,16 +259,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -322,16 +301,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs index d0622196a..c2a7d5409 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs @@ -79,16 +79,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -141,16 +134,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -187,16 +173,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); @@ -236,16 +215,9 @@ namespace Discord.WebSocket if (!IsValidToken) throw new InvalidOperationException("Interaction token is no longer valid"); + embeds ??= Array.Empty(); if (embed != null) - { - if (embeds == null) - embeds = new[] { embed }; - else - { - List listEmbeds = embeds.ToList(); - listEmbeds.Insert(0, embed); - } - } + embeds = new[] { embed }.Concat(embeds).ToArray(); Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); diff --git a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj index cf9d10de1..ac654d4a6 100644 --- a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj +++ b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj @@ -6,7 +6,6 @@ Discord.Webhook A core Discord.Net Labs library containing the Webhook client and models. netstandard2.0;netstandard2.1 - 3.0.0 Discord.Net.Labs.Webhook https://github.com/Discord-Net-Labs/Discord.Net-Labs https://github.com/Discord-Net-Labs/Discord.Net-Labs