* Changed from NotNullOrWhitespace to NotNullOrEmpty * Added NotNullOrEmpty on filename * Added system to interpret from the path * Added a check for if it contains a period * It has been done, how ever it will break stuff * Changed to use ??= how ever still added error check * Added space under check * Changed from with a period to valid file extension * Added checks for SendFileAsync * Removed filename != null &&pull/1923/head
| @@ -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<RestUserMessage> 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<Embed>(); | |||
| if (embed != null) | |||
| embeds = new[] { embed }.Concat(embeds).ToArray(); | |||
| @@ -245,9 +245,9 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc/> | |||
| public override async Task<RestFollowupMessage> 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 | |||
| /// <inheritdoc/> | |||
| public override async Task<RestFollowupMessage> FollowupWithFileAsync( | |||
| string filePath, | |||
| string text = null, | |||
| string filePath = null, | |||
| string fileName = null, | |||
| Embed[] embeds = null, | |||
| bool isTTS = false, | |||
| @@ -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 | |||
| /// <inheritdoc/> | |||
| [Obsolete("Autocomplete interactions cannot have followups!", true)] | |||
| public override Task<RestFollowupMessage> 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<RestFollowupMessage> 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(); | |||
| /// <inheritdoc/> | |||
| [Obsolete("Autocomplete interactions cannot have followups!", true)] | |||
| public override Task<RestFollowupMessage> 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<RestFollowupMessage> 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(); | |||
| /// <inheritdoc/> | |||
| [Obsolete("Autocomplete interactions cannot have normal responses!", true)] | |||
| @@ -159,8 +159,8 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc/> | |||
| public override async Task<RestFollowupMessage> 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 | |||
| /// <inheritdoc/> | |||
| public override async Task<RestFollowupMessage> 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 | |||
| { | |||
| @@ -157,7 +157,7 @@ namespace Discord.WebSocket | |||
| /// <returns> | |||
| /// The sent message. | |||
| /// </returns> | |||
| public abstract Task<RestFollowupMessage> FollowupWithFileAsync(string text = null, Stream fileStream = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||
| public abstract Task<RestFollowupMessage> 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); | |||
| /// <summary> | |||
| @@ -176,13 +176,13 @@ namespace Discord.WebSocket | |||
| /// <returns> | |||
| /// The sent message. | |||
| /// </returns> | |||
| public abstract Task<RestFollowupMessage> FollowupWithFileAsync(string text = null, string filePath = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||
| public abstract Task<RestFollowupMessage> 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); | |||
| /// <summary> | |||
| /// Gets the original response for this interaction. | |||
| /// </summary> | |||
| /// <param name="options">The request options for this async request.</param> | |||
| /// <param name="options">The request options for this <see langword="async"/> request.</param> | |||
| /// <returns>A <see cref="RestInteractionMessage"/> that represents the initial response.</returns> | |||
| public Task<RestInteractionMessage> GetOriginalResponseAsync(RequestOptions options = null) | |||
| => InteractionHelper.GetOriginalResponseAsync(Discord, Channel, this, options); | |||
| @@ -191,7 +191,7 @@ namespace Discord.WebSocket | |||
| /// Edits original response for this interaction. | |||
| /// </summary> | |||
| /// <param name="func">A delegate containing the properties to modify the message with.</param> | |||
| /// <param name="options">The request options for this async request.</param> | |||
| /// <param name="options">The request options for this <see langword="async"/> request.</param> | |||
| /// <returns>A <see cref="RestInteractionMessage"/> that represents the initial response.</returns> | |||
| public async Task<RestInteractionMessage> ModifyOriginalResponseAsync(Action<MessageProperties> func, RequestOptions options = null) | |||
| { | |||
| @@ -203,7 +203,7 @@ namespace Discord.WebSocket | |||
| /// Acknowledges this interaction. | |||
| /// </summary> | |||
| /// <param name="ephemeral"><see langword="true"/> to send this message ephemerally, otherwise <see langword="false"/>.</param> | |||
| /// <param name="options">The request options for this async request.</param> | |||
| /// <param name="options">The request options for this <see langword="async"/> request.</param> | |||
| /// <returns> | |||
| /// A task that represents the asynchronous operation of acknowledging the interaction. | |||
| /// </returns> | |||