feat: respect guild boost file size limit when re-sending attachments
This commit is contained in:
		| @@ -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; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; } | ||||
|   | ||||
| @@ -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, | ||||
|             }); | ||||
|   | ||||
| @@ -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", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user