Merge branch 'main' into feat/ap

This commit is contained in:
Astrid
2020-12-08 12:25:01 +01:00
committed by GitHub
24 changed files with 413 additions and 145 deletions

View File

@@ -55,7 +55,9 @@ namespace PluralKit.Bot
// Permission check after proxy match so we don't get spammed when not actually proxying
if (!await CheckBotPermissionsOrError(message.Channel)) return false;
if (!CheckProxyNameBoundsOrError(match.Member.ProxyName(ctx))) return false;
// this method throws, so no need to wrap it in an if statement
CheckProxyNameBoundsOrError(match.Member.ProxyName(ctx));
// Check if the sender account can mention everyone/here + embed links
// we need to "mirror" these permissions when proxying to prevent exploits
@@ -74,7 +76,7 @@ namespace PluralKit.Bot
if (ctx.SystemId == null) return false;
// Make sure channel is a guild text channel and this is a normal message
if (msg.Channel.Type != ChannelType.Text || msg.MessageType != MessageType.Default) return false;
if ((msg.Channel.Type != ChannelType.Text && msg.Channel.Type != ChannelType.News) || msg.MessageType != MessageType.Default) return false;
// Make sure author is a normal user
if (msg.Author.IsSystem == true || msg.Author.IsBot || msg.WebhookMessage) return false;
@@ -96,7 +98,7 @@ namespace PluralKit.Bot
// Send the webhook
var content = match.ProxyContent;
if (!allowEmbeds) content = content.BreakLinkEmbeds();
var proxyMessage = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName(ctx),
var proxyMessage = await _webhookExecutor.ExecuteWebhook(trigger.Channel, FixSingleCharacterName(match.Member.ProxyName(ctx)),
match.Member.ProxyAvatar(ctx),
content, trigger.Attachments, allowEveryone);
@@ -185,13 +187,15 @@ namespace PluralKit.Bot
return true;
}
private bool CheckProxyNameBoundsOrError(string proxyName)
private string FixSingleCharacterName(string proxyName)
{
if (proxyName.Length < 2) throw Errors.ProxyNameTooShort(proxyName);
if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName);
if (proxyName.Length == 1) return proxyName += "\u17b5";
else return proxyName;
}
// TODO: this never returns false as it throws instead, should this happen?
return true;
private void CheckProxyNameBoundsOrError(string proxyName)
{
if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName);
}
}
}