Filter everyone/here pings if the proxy sender doesn't have permission
This commit is contained in:
parent
2217b87afe
commit
59dbc5368b
@ -88,6 +88,9 @@ namespace PluralKit.Bot
|
||||
|
||||
public async Task HandleMessageAsync(IMessage message)
|
||||
{
|
||||
// Bail early if this isn't in a guild channel
|
||||
if (!(message.Channel is IGuildChannel)) return;
|
||||
|
||||
IEnumerable<ProxyDatabaseResult> results;
|
||||
using (var conn = await _conn.Obtain())
|
||||
{
|
||||
@ -108,11 +111,14 @@ namespace PluralKit.Bot
|
||||
// Can't proxy a message with no content and no attachment
|
||||
if (match.InnerText.Trim().Length == 0 && message.Attachments.Count == 0)
|
||||
return;
|
||||
|
||||
|
||||
// Sanitize @everyone, but only if the original user wouldn't have permission to
|
||||
var messageContents = SanitizeEveryoneMaybe(message, match.InnerText);
|
||||
|
||||
// Fetch a webhook for this channel, and send the proxied message
|
||||
var webhook = await _webhookCache.GetWebhook(message.Channel as ITextChannel);
|
||||
var avatarUrl = match.Member.AvatarUrl ?? match.System.AvatarUrl;
|
||||
var hookMessageId = await ExecuteWebhook(webhook, match.InnerText, match.ProxyName, avatarUrl, message.Attachments.FirstOrDefault());
|
||||
var hookMessageId = await ExecuteWebhook(webhook, messageContents, match.ProxyName, avatarUrl, message.Attachments.FirstOrDefault());
|
||||
|
||||
// Store the message in the database, and log it in the log channel (if applicable)
|
||||
await _messageStorage.Store(message.Author.Id, hookMessageId, message.Channel.Id, message.Id, match.Member);
|
||||
@ -127,6 +133,13 @@ namespace PluralKit.Bot
|
||||
} catch (HttpException) {} // If it's already deleted, we just swallow the exception
|
||||
}
|
||||
|
||||
private static string SanitizeEveryoneMaybe(IMessage message, string messageContents)
|
||||
{
|
||||
var senderPermissions = ((IGuildUser) message.Author).GetPermissions(message.Channel as IGuildChannel);
|
||||
if (!senderPermissions.MentionEveryone) return messageContents.SanitizeEveryone();
|
||||
return messageContents;
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureBotPermissions(ITextChannel channel)
|
||||
{
|
||||
var guildUser = await channel.Guild.GetCurrentUserAsync();
|
||||
|
@ -82,6 +82,9 @@ namespace PluralKit.Bot
|
||||
|
||||
public static string Sanitize(this string input) =>
|
||||
Regex.Replace(Regex.Replace(input, "<@[!&]?(\\d{17,19})>", "<\\@$1>"), "@(everyone|here)", "@\u200B$1");
|
||||
|
||||
public static string SanitizeEveryone(this string input) =>
|
||||
Regex.Replace(input, "@(everyone|here)", "@\u200B$1");
|
||||
|
||||
public static async Task<ChannelPermissions> PermissionsIn(this IChannel channel)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user