adds the isSpoiler field to uploading files with a webhook, which will only insert "SPOILER_" to the start of the filename. This does not include other fields in the payload, as this is not in the documentation, and was not observed like in the regular clientpull/1255/head
| @@ -22,6 +22,8 @@ namespace Discord.API.Rest | |||||
| public Optional<string> AvatarUrl { get; set; } | public Optional<string> AvatarUrl { get; set; } | ||||
| public Optional<Embed[]> Embeds { get; set; } | public Optional<Embed[]> Embeds { get; set; } | ||||
| public bool IsSpoiler { get; set; } = false; | |||||
| public UploadWebhookFileParams(Stream file) | public UploadWebhookFileParams(Stream file) | ||||
| { | { | ||||
| File = file; | File = file; | ||||
| @@ -30,7 +32,11 @@ namespace Discord.API.Rest | |||||
| public IReadOnlyDictionary<string, object> ToDictionary() | public IReadOnlyDictionary<string, object> ToDictionary() | ||||
| { | { | ||||
| var d = new Dictionary<string, object>(); | var d = new Dictionary<string, object>(); | ||||
| d["file"] = new MultipartFile(File, Filename.GetValueOrDefault("unknown.dat")); | |||||
| var filename = Filename.GetValueOrDefault("unknown.dat"); | |||||
| if (IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) | |||||
| filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); | |||||
| d["file"] = new MultipartFile(File, filename); | |||||
| var payload = new Dictionary<string, object>(); | var payload = new Dictionary<string, object>(); | ||||
| if (Content.IsSpecified) | if (Content.IsSpecified) | ||||
| @@ -71,13 +71,13 @@ namespace Discord.Webhook | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | ||||
| /// <returns> Returns the ID of the created message. </returns> | /// <returns> Returns the ID of the created message. </returns> | ||||
| public Task<ulong> SendFileAsync(string filePath, string text, bool isTTS = false, | public Task<ulong> SendFileAsync(string filePath, string text, bool isTTS = false, | ||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, options); | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null, bool isSpoiler = false) | |||||
| => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, options, isSpoiler); | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | ||||
| /// <returns> Returns the ID of the created message. </returns> | /// <returns> Returns the ID of the created message. </returns> | ||||
| public Task<ulong> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | public Task<ulong> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | ||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, avatarUrl, options); | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null, bool isSpoiler = false) | |||||
| => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler); | |||||
| /// <summary> Modifies the properties of this webhook. </summary> | /// <summary> Modifies the properties of this webhook. </summary> | ||||
| public Task ModifyWebhookAsync(Action<WebhookProperties> func, RequestOptions options = null) | public Task ModifyWebhookAsync(Action<WebhookProperties> func, RequestOptions options = null) | ||||
| @@ -35,16 +35,16 @@ namespace Discord.Webhook | |||||
| return model.Id; | return model.Id; | ||||
| } | } | ||||
| public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, | public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, | ||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options) | |||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler) | |||||
| { | { | ||||
| string filename = Path.GetFileName(filePath); | string filename = Path.GetFileName(filePath); | ||||
| using (var file = File.OpenRead(filePath)) | using (var file = File.OpenRead(filePath)) | ||||
| return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, options).ConfigureAwait(false); | |||||
| return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler).ConfigureAwait(false); | |||||
| } | } | ||||
| public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, | public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, | ||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options) | |||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler) | |||||
| { | { | ||||
| var args = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS }; | |||||
| var args = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, IsSpoiler = isSpoiler }; | |||||
| if (username != null) | if (username != null) | ||||
| args.Username = username; | args.Username = username; | ||||
| if (avatarUrl != null) | if (avatarUrl != null) | ||||