fix(bot): filter out non-rich Discord embeds in reproxy (#476)

This commit is contained in:
the iris system 2022-07-20 12:34:43 +12:00 committed by GitHub
parent 62a57bc818
commit fcd1ec486e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,7 +229,7 @@ public class ProxyService
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();
var mangledEmbeds = originalMsg.Embeds!.Select(embed => MangleReproxyEmbed(embed, member)).Where(embed => embed != null).ToArray();
// Send the reproxied webhook
var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest
@ -271,7 +271,7 @@ public class ProxyService
}
}
private Embed MangleReproxyEmbed(Embed embed, ProxyMember member)
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
@ -290,6 +290,12 @@ public class ProxyService
};
}
// XXX: remove non-rich embeds as including them breaks link embeds completely
else if (embed.Type != "rich")
{
return null;
}
return embed;
}