fix(bot): make reproxy change reply embed color

This commit is contained in:
Iris System 2022-07-05 12:22:35 +00:00
parent 94809fcf19
commit 07e86c4cd5

View File

@ -228,6 +228,9 @@ public class ProxyService
if (!senderPermissions.HasFlag(PermissionSet.SendMessages)) if (!senderPermissions.HasFlag(PermissionSet.SendMessages))
throw new PKError("You don't have permission to send messages in the channel that message is in."); throw new PKError("You don't have permission to send messages in the channel that message is in.");
// Mangle embeds (for reply embed color changing)
var mangledEmbeds = originalMsg.Embeds!.Select(embed => MangleReproxyEmbed(embed, member)).ToArray();
// Send the reproxied webhook // Send the reproxied webhook
var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest
{ {
@ -239,7 +242,7 @@ public class ProxyService
Content = match.ProxyContent!, Content = match.ProxyContent!,
Attachments = originalMsg.Attachments!, Attachments = originalMsg.Attachments!,
FileSizeLimit = guild.FileSizeLimit(), FileSizeLimit = guild.FileSizeLimit(),
Embeds = originalMsg.Embeds!.ToArray(), Embeds = mangledEmbeds,
Stickers = originalMsg.StickerItems!, Stickers = originalMsg.StickerItems!,
AllowEveryone = allowEveryone AllowEveryone = allowEveryone
}); });
@ -268,6 +271,28 @@ public class ProxyService
} }
} }
private Embed MangleReproxyEmbed(Embed embed, ProxyMember member)
{
// XXX: This is a naïve implementation of detecting reply embeds: looking for the same Unicode
// characters as used in the reply embed generation, since we don't _really_ have a good way
// to detect whether an embed is a PluralKit reply embed right now, whether a message is in
// reply to another message isn't currently stored anywhere in the database.
//
// unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation]
if (embed.Author != null && embed.Author!.Name.EndsWith("\u2004\u21a9\ufe0f"))
{
return new Embed
{
Type = "rich",
Author = embed.Author!,
Description = embed.Description!,
Color = member.Color?.ToDiscordColor()
};
}
return embed;
}
private Embed CreateReplyEmbed(ProxyMatch match, Message trigger, Message repliedTo, string? nickname, private Embed CreateReplyEmbed(ProxyMatch match, Message trigger, Message repliedTo, string? nickname,
string? avatar) string? avatar)
{ {