From a16903037f41ac6a7b583244b03c7ae554fe49f4 Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 14 Jan 2022 23:22:12 -0500 Subject: [PATCH] fix: don't try to re-send stickers and activity invites --- .../Types/Requests/ExecuteWebhookRequest.cs | 1 + Myriad/Types/Message.cs | 5 ++++ Myriad/Types/Sticker.cs | 29 +++++++++++++++++++ PluralKit.Bot/Proxy/ProxyService.cs | 7 +++++ .../Services/WebhookExecutorService.cs | 4 ++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Myriad/Types/Sticker.cs diff --git a/Myriad/Rest/Types/Requests/ExecuteWebhookRequest.cs b/Myriad/Rest/Types/Requests/ExecuteWebhookRequest.cs index 6980b696..011ff652 100644 --- a/Myriad/Rest/Types/Requests/ExecuteWebhookRequest.cs +++ b/Myriad/Rest/Types/Requests/ExecuteWebhookRequest.cs @@ -8,6 +8,7 @@ public record ExecuteWebhookRequest public string? Username { get; init; } public string? AvatarUrl { get; init; } public Embed[] Embeds { get; init; } + public Sticker[] Stickers { get; init; } public Message.Attachment[] Attachments { get; set; } public AllowedMentions? AllowedMentions { get; init; } } \ No newline at end of file diff --git a/Myriad/Types/Message.cs b/Myriad/Types/Message.cs index f052e433..55928de9 100644 --- a/Myriad/Types/Message.cs +++ b/Myriad/Types/Message.cs @@ -43,6 +43,7 @@ public record Message public ulong Id { get; init; } public ulong ChannelId { get; init; } public ulong? GuildId { get; init; } + public MessageActivity? Activity { get; init; } public User Author { get; init; } public string? Content { get; init; } public string? Timestamp { get; init; } @@ -54,6 +55,8 @@ public record Message public Attachment[] Attachments { get; init; } public Embed[]? Embeds { get; init; } + public Sticker[]? StickerItems { get; init; } + public Sticker[]? Stickers { get; init; } public Reaction[] Reactions { get; init; } public bool Pinned { get; init; } public ulong? WebhookId { get; init; } @@ -69,6 +72,8 @@ public record Message public record Reference(ulong? GuildId, ulong? ChannelId, ulong? MessageId); + public record MessageActivity(int Type, string PartyId); + public record Attachment { public ulong Id { get; init; } diff --git a/Myriad/Types/Sticker.cs b/Myriad/Types/Sticker.cs new file mode 100644 index 00000000..c79c5c23 --- /dev/null +++ b/Myriad/Types/Sticker.cs @@ -0,0 +1,29 @@ +namespace Myriad.Types; + +public record Sticker +{ + public enum StickerType + { + STANDARD = 1, + GUILD = 2, + } + + public enum StickerFormatType + { + PNG = 1, + APNG = 2, + LOTTIE = 3, + } + + public ulong Id { get; init; } + public StickerType Type { get; init; } + public ulong? PackId { get; init; } + public string Name { get; init; } + public string? Description { get; init; } + public string Tags { get; init; } + public string Asset { get; init; } + public bool Available { get; init; } + public ulong? GuildId { get; init; } + public User? User { get; init; } + public int? SortValue { get; init; } +} \ No newline at end of file diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 185af0c6..69aa6932 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -115,6 +115,12 @@ public class ProxyService if (isMessageBlank && msg.Attachments.Length == 0) throw new ProxyChecksFailedException("Message cannot be blank."); + if (msg.Activity != null) + throw new ProxyChecksFailedException("Message contains an invite to an activity, which cannot be re-sent by PluralKit."); + + if (msg.StickerItems != null) // && msg.StickerItems.Any(s => s.Type == Sticker.StickerType.GUILD && s.GuildId != msg.GuildId)) + throw new ProxyChecksFailedException("Message contains stickers, which cannot be re-sent by PluralKit."); + // All good! return true; } @@ -158,6 +164,7 @@ public class ProxyService Attachments = trigger.Attachments, FileSizeLimit = guild.FileSizeLimit(), Embeds = embeds.ToArray(), + Stickers = trigger.StickerItems, AllowEveryone = allowEveryone }); await HandleProxyExecutedActions(ctx, trigger, proxyMessage, match); diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 1e548942..db1b4539 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -37,6 +37,7 @@ public record ProxyRequest public Message.Attachment[] Attachments { get; init; } public int FileSizeLimit { get; init; } public Embed[] Embeds { get; init; } + public Sticker[] Stickers { get; init; } public bool AllowEveryone { get; init; } } @@ -115,7 +116,8 @@ public class WebhookExecutorService Content = content, AllowedMentions = allowedMentions, AvatarUrl = !string.IsNullOrWhiteSpace(req.AvatarUrl) ? req.AvatarUrl : null, - Embeds = req.Embeds + Embeds = req.Embeds, + Stickers = req.Stickers, }; MultipartFile[] files = null;