diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index c5d264ade..66f0b2539 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -338,6 +338,9 @@ namespace Discord.Rest string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent component, ISticker[] stickers, RequestOptions options, bool isSpoiler, Embed[] embeds) { string filename = Path.GetFileName(filePath); + if (filename == null || !filename.Contains('.')) + throw new ArgumentException("Make sure that the file path has a file name and a valid file extension."); + using (var file = File.OpenRead(filePath)) return await SendFileAsync(channel, client, file, filename, text, isTTS, embed, allowedMentions, messageReference, component, stickers, options, isSpoiler, embeds).ConfigureAwait(false); } @@ -346,6 +349,9 @@ namespace Discord.Rest public static async Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent component, ISticker[] stickers, RequestOptions options, bool isSpoiler, Embed[] embeds) { + if (filename == null || !filename.Contains('.')) + throw new ArgumentException("Make sure that the file path has a file name and a valid file extension."); + embeds ??= Array.Empty(); if (embed != null) embeds = new[] { embed }.Concat(embeds).ToArray(); 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 051a290e6..2e48b6dd9 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs @@ -245,9 +245,9 @@ namespace Discord.WebSocket /// public override async Task FollowupWithFileAsync( + Stream fileStream, + string fileName, string text = null, - Stream fileStream = null, - string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, @@ -287,8 +287,8 @@ namespace Discord.WebSocket /// public override async Task FollowupWithFileAsync( + string filePath, string text = null, - string filePath = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs index 9164bfdd6..fb6aa2a76 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs @@ -34,7 +34,7 @@ namespace Discord.WebSocket internal new static SocketAutocompleteInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) { - var entity = new SocketAutocompleteInteraction(client, model, channel); + var entity = new SocketAutocompleteInteraction(client, model, channel); entity.Update(model); return entity; } @@ -84,11 +84,11 @@ namespace Discord.WebSocket /// [Obsolete("Autocomplete interactions cannot have followups!", true)] - public override Task FollowupWithFileAsync(string text = null, Stream fileStream = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException(); + public override Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException(); /// [Obsolete("Autocomplete interactions cannot have followups!", true)] - public override Task FollowupWithFileAsync(string text = null, string filePath = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException(); + public override Task FollowupWithFileAsync(string filePath, string text = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException(); /// [Obsolete("Autocomplete interactions cannot have normal responses!", true)] diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs index c2a7d5409..189a51e41 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs @@ -159,8 +159,8 @@ namespace Discord.WebSocket /// public override async Task FollowupWithFileAsync( + Stream fileStream, string text = null, - Stream fileStream = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, @@ -181,7 +181,7 @@ namespace Discord.WebSocket Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data"); - Preconditions.NotNullOrWhitespace(fileName, nameof(fileName), "File Name must not be empty or null"); + Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); var args = new API.Rest.CreateWebhookMessageParams { @@ -201,8 +201,8 @@ namespace Discord.WebSocket /// public override async Task FollowupWithFileAsync( + string filePath, string text = null, - string filePath = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, @@ -222,7 +222,12 @@ namespace Discord.WebSocket 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."); Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); - Preconditions.NotNullOrWhitespace(filePath, nameof(filePath), "Path must exist"); + Preconditions.NotNullOrEmpty(filePath, nameof(filePath), "Path must exist"); + + fileName ??= Path.GetFileName(filePath); + + if (fileName == null || !fileName.Contains('.')) + throw new ArgumentException("Make sure that the file path has a file name and a valid file extension."); var args = new API.Rest.CreateWebhookMessageParams { diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs index b4297b4bd..47b0ebcb6 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs @@ -157,7 +157,7 @@ namespace Discord.WebSocket /// /// The sent message. /// - public abstract Task FollowupWithFileAsync(string text = null, Stream fileStream = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + public abstract Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); /// @@ -176,13 +176,13 @@ namespace Discord.WebSocket /// /// The sent message. /// - public abstract Task FollowupWithFileAsync(string text = null, string filePath = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + public abstract Task FollowupWithFileAsync(string filePath, string text = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); /// /// Gets the original response for this interaction. /// - /// The request options for this async request. + /// The request options for this request. /// A that represents the initial response. public Task GetOriginalResponseAsync(RequestOptions options = null) => InteractionHelper.GetOriginalResponseAsync(Discord, Channel, this, options); @@ -191,7 +191,7 @@ namespace Discord.WebSocket /// Edits original response for this interaction. /// /// A delegate containing the properties to modify the message with. - /// The request options for this async request. + /// The request options for this request. /// A that represents the initial response. public async Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null) { @@ -203,7 +203,7 @@ namespace Discord.WebSocket /// Acknowledges this interaction. /// /// to send this message ephemerally, otherwise . - /// The request options for this async request. + /// The request options for this request. /// /// A task that represents the asynchronous operation of acknowledging the interaction. ///