From 5ff32ea6b4e4b5e04dabb2c92a7adda9d9ff4d62 Mon Sep 17 00:00:00 2001 From: Ske Date: Mon, 23 Dec 2019 13:55:43 +0100 Subject: [PATCH] Re-enable proxy attachments --- PluralKit.Bot/Bot.cs | 3 +-- PluralKit.Bot/Services/ProxyService.cs | 2 +- .../Services/WebhookExecutorService.cs | 19 +++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index b69981f0..63db07a7 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -201,8 +201,7 @@ namespace PluralKit.Bot private async Task UpdatePeriodic() { // Change bot status - // await _client.SetGameAsync($"pk;help | in {_client.Guilds.Count} servers"); - await _client.SetGameAsync($"Attachments disabled for tonight, sorry | in {_client.Guilds.Count} servers"); + await _client.SetGameAsync($"pk;help | in {_client.Guilds.Count} servers"); await _collector.CollectStats(); diff --git a/PluralKit.Bot/Services/ProxyService.cs b/PluralKit.Bot/Services/ProxyService.cs index 5573f24b..98e5baad 100644 --- a/PluralKit.Bot/Services/ProxyService.cs +++ b/PluralKit.Bot/Services/ProxyService.cs @@ -95,7 +95,7 @@ namespace PluralKit.Bot if (!await EnsureBotPermissions(channel)) return; // Can't proxy a message with no content and no attachment - if (match.InnerText.Trim().Length == 0/* && message.Attachments.Count == 0*/) // TODO: undo when adding attachments back + if (match.InnerText.Trim().Length == 0 && message.Attachments.Count == 0) return; // Get variables in order and all diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 86294fe7..fc838c2d 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -60,13 +60,12 @@ namespace PluralKit.Bot }; if (avatarUrl != null) mfd.Add(new StringContent(avatarUrl), "avatar_url"); - /*var attachmentChunks = ChunkAttachmentsOrThrow(attachments, 8 * 1024 * 1024); + var attachmentChunks = ChunkAttachmentsOrThrow(attachments, 8 * 1024 * 1024); if (attachmentChunks.Count > 0) { _logger.Information("Invoking webhook with {AttachmentCount} attachments totalling {AttachmentSize} MiB in {AttachmentChunks} chunks", attachments.Count, attachments.Select(a => a.Size).Sum() / 1024 / 1024, attachmentChunks.Count); await AddAttachmentsToMultipart(mfd, attachmentChunks.First()); - }*/ - + } var timerCtx = _metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime); using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd); @@ -93,21 +92,21 @@ namespace PluralKit.Bot } // If we have any leftover attachment chunks, send those - /*if (attachmentChunks.Count > 1) + if (attachmentChunks.Count > 1) { // Deliberately not adding a content, just the remaining files foreach (var chunk in attachmentChunks.Skip(1)) { - mfd = new MultipartFormDataContent(); - mfd.Add(new StringContent(FixClyde(name).Truncate(80)), "username"); - if (avatarUrl != null) mfd.Add(new StringContent(avatarUrl), "avatar_url"); - await AddAttachmentsToMultipart(mfd, chunk); + using var mfd2 = new MultipartFormDataContent(); + mfd2.Add(new StringContent(FixClyde(name).Truncate(80)), "username"); + if (avatarUrl != null) mfd2.Add(new StringContent(avatarUrl), "avatar_url"); + await AddAttachmentsToMultipart(mfd2, chunk); // Don't bother with ?wait, we're just kinda firehosing this stuff // also don't error check, the real message itself is already sent - await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}", mfd); + await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}", mfd2); } - }*/ + } // At this point we're sure we have a 2xx status code, so just assume success // TODO: can we do this without a round-trip to a string?