fix: don't try to re-send stickers and activity invites

This commit is contained in:
spiral 2022-01-14 23:22:12 -05:00
parent 2639989183
commit a16903037f
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
5 changed files with 45 additions and 1 deletions

View File

@ -8,6 +8,7 @@ public record ExecuteWebhookRequest
public string? Username { get; init; } public string? Username { get; init; }
public string? AvatarUrl { get; init; } public string? AvatarUrl { get; init; }
public Embed[] Embeds { get; init; } public Embed[] Embeds { get; init; }
public Sticker[] Stickers { get; init; }
public Message.Attachment[] Attachments { get; set; } public Message.Attachment[] Attachments { get; set; }
public AllowedMentions? AllowedMentions { get; init; } public AllowedMentions? AllowedMentions { get; init; }
} }

View File

@ -43,6 +43,7 @@ public record Message
public ulong Id { get; init; } public ulong Id { get; init; }
public ulong ChannelId { get; init; } public ulong ChannelId { get; init; }
public ulong? GuildId { get; init; } public ulong? GuildId { get; init; }
public MessageActivity? Activity { get; init; }
public User Author { get; init; } public User Author { get; init; }
public string? Content { get; init; } public string? Content { get; init; }
public string? Timestamp { get; init; } public string? Timestamp { get; init; }
@ -54,6 +55,8 @@ public record Message
public Attachment[] Attachments { get; init; } public Attachment[] Attachments { get; init; }
public Embed[]? Embeds { get; init; } public Embed[]? Embeds { get; init; }
public Sticker[]? StickerItems { get; init; }
public Sticker[]? Stickers { get; init; }
public Reaction[] Reactions { get; init; } public Reaction[] Reactions { get; init; }
public bool Pinned { get; init; } public bool Pinned { get; init; }
public ulong? WebhookId { 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 Reference(ulong? GuildId, ulong? ChannelId, ulong? MessageId);
public record MessageActivity(int Type, string PartyId);
public record Attachment public record Attachment
{ {
public ulong Id { get; init; } public ulong Id { get; init; }

29
Myriad/Types/Sticker.cs Normal file
View File

@ -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; }
}

View File

@ -115,6 +115,12 @@ public class ProxyService
if (isMessageBlank && msg.Attachments.Length == 0) if (isMessageBlank && msg.Attachments.Length == 0)
throw new ProxyChecksFailedException("Message cannot be blank."); 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! // All good!
return true; return true;
} }
@ -158,6 +164,7 @@ public class ProxyService
Attachments = trigger.Attachments, Attachments = trigger.Attachments,
FileSizeLimit = guild.FileSizeLimit(), FileSizeLimit = guild.FileSizeLimit(),
Embeds = embeds.ToArray(), Embeds = embeds.ToArray(),
Stickers = trigger.StickerItems,
AllowEveryone = allowEveryone AllowEveryone = allowEveryone
}); });
await HandleProxyExecutedActions(ctx, trigger, proxyMessage, match); await HandleProxyExecutedActions(ctx, trigger, proxyMessage, match);

View File

@ -37,6 +37,7 @@ public record ProxyRequest
public Message.Attachment[] Attachments { get; init; } public Message.Attachment[] Attachments { get; init; }
public int FileSizeLimit { get; init; } public int FileSizeLimit { get; init; }
public Embed[] Embeds { get; init; } public Embed[] Embeds { get; init; }
public Sticker[] Stickers { get; init; }
public bool AllowEveryone { get; init; } public bool AllowEveryone { get; init; }
} }
@ -115,7 +116,8 @@ public class WebhookExecutorService
Content = content, Content = content,
AllowedMentions = allowedMentions, AllowedMentions = allowedMentions,
AvatarUrl = !string.IsNullOrWhiteSpace(req.AvatarUrl) ? req.AvatarUrl : null, AvatarUrl = !string.IsNullOrWhiteSpace(req.AvatarUrl) ? req.AvatarUrl : null,
Embeds = req.Embeds Embeds = req.Embeds,
Stickers = req.Stickers,
}; };
MultipartFile[] files = null; MultipartFile[] files = null;