From 38cbca1b34283c8447275744f2b9c31a46c73e2f Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 4 Nov 2021 14:13:43 -0400 Subject: [PATCH] feat: respect guild boost file size limit when re-sending attachments --- Myriad/Extensions/GuildExtensions.cs | 17 ++++++++++++++++- Myriad/Types/Guild.cs | 9 +++++++++ PluralKit.Bot/Proxy/ProxyService.cs | 2 ++ .../Services/WebhookExecutorService.cs | 3 ++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Myriad/Extensions/GuildExtensions.cs b/Myriad/Extensions/GuildExtensions.cs index 2f97aa56..3e9cc674 100644 --- a/Myriad/Extensions/GuildExtensions.cs +++ b/Myriad/Extensions/GuildExtensions.cs @@ -1,7 +1,22 @@ +using Myriad.Types; + namespace Myriad.Extensions { public static class GuildExtensions { - + public static int FileSizeLimit(this Guild guild) + { + switch (guild.PremiumTier) + { + default: + case PremiumTier.NONE: + case PremiumTier.TIER_1: + return 8; + case PremiumTier.TIER_2: + return 50; + case PremiumTier.TIER_3: + return 100; + } + } } } \ No newline at end of file diff --git a/Myriad/Types/Guild.cs b/Myriad/Types/Guild.cs index fe39d0ff..75764b8e 100644 --- a/Myriad/Types/Guild.cs +++ b/Myriad/Types/Guild.cs @@ -1,5 +1,13 @@ namespace Myriad.Types { + public enum PremiumTier + { + NONE, + TIER_1, + TIER_2, + TIER_3, + } + public record Guild { public ulong Id { get; init; } @@ -15,6 +23,7 @@ namespace Myriad.Types public bool? WidgetEnabled { get; init; } public ulong? WidgetChannelId { get; init; } public int VerificationLevel { get; init; } + public PremiumTier PremiumTier { get; init; } public Role[] Roles { get; init; } public string[] Features { get; init; } diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index fa59578c..978a8455 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -146,6 +146,7 @@ namespace PluralKit.Bot var messageChannel = _cache.GetChannel(trigger.ChannelId); var rootChannel = _cache.GetRootChannel(trigger.ChannelId); var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null; + var guild = _cache.GetGuild(trigger.GuildId.Value); var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest { @@ -156,6 +157,7 @@ namespace PluralKit.Bot AvatarUrl = AvatarUtils.TryRewriteCdnUrl(match.Member.ProxyAvatar(ctx)), Content = content, Attachments = trigger.Attachments, + FileSizeLimit = guild.FileSizeLimit(), Embeds = embeds.ToArray(), AllowEveryone = allowEveryone, }); diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index d66be6c4..da5ebe23 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -40,6 +40,7 @@ namespace PluralKit.Bot public string? AvatarUrl { get; init; } public string? Content { get; init; } public Message.Attachment[] Attachments { get; init; } + public int FileSizeLimit { get; init; } public Embed[] Embeds { get; init; } public bool AllowEveryone { get; init; } } @@ -122,7 +123,7 @@ namespace PluralKit.Bot }; MultipartFile[] files = null; - var attachmentChunks = ChunkAttachmentsOrThrow(req.Attachments, 8 * 1024 * 1024); + var attachmentChunks = ChunkAttachmentsOrThrow(req.Attachments, req.FileSizeLimit * 1024 * 1024); if (attachmentChunks.Count > 0) { _logger.Information("Invoking webhook with {AttachmentCount} attachments totalling {AttachmentSize} MiB in {AttachmentChunks} chunks",