Don't ping by reaction if sender doesn't have permissions
This commit is contained in:
parent
e49f2850c6
commit
35b0659d05
@ -273,15 +273,23 @@ namespace PluralKit.Bot
|
|||||||
ISocketMessageChannel channel, ulong userWhoReacted,
|
ISocketMessageChannel channel, ulong userWhoReacted,
|
||||||
IEmote reactedEmote)
|
IEmote reactedEmote)
|
||||||
{
|
{
|
||||||
|
// Bail in DMs
|
||||||
|
if (!(channel is SocketGuildChannel gc)) return;
|
||||||
|
|
||||||
// Find the message in the DB
|
// Find the message in the DB
|
||||||
var msg = await _data.GetMessage(message.Id);
|
var msg = await _data.GetMessage(message.Id);
|
||||||
if (msg == null) return;
|
if (msg == null) return;
|
||||||
|
|
||||||
var realMessage = await message.GetOrDownloadAsync();
|
// Check if the pinger has permission to ping in this channel
|
||||||
var embed = new EmbedBuilder()
|
var guildUser = await _client.Rest.GetGuildUserAsync(gc.Guild.Id, userWhoReacted);
|
||||||
.WithDescription($"[Jump to pinged message]({realMessage.GetJumpUrl()})");
|
var permissions = guildUser.GetPermissions(gc);
|
||||||
|
|
||||||
|
var realMessage = await message.GetOrDownloadAsync();
|
||||||
|
|
||||||
|
// If they don't have Send Messages permission, bail (since PK shouldn't send anything on their behalf)
|
||||||
|
if (!permissions.SendMessages || !permissions.ViewChannel) return;
|
||||||
|
|
||||||
|
var embed = new EmbedBuilder().WithDescription($"[Jump to pinged message]({realMessage.GetJumpUrl()})");
|
||||||
await channel.SendMessageAsync($"Psst, **{msg.Member.DisplayName ?? msg.Member.Name}** (<@{msg.Message.Sender}>), you have been pinged by <@{userWhoReacted}>.", embed: embed.Build());
|
await channel.SendMessageAsync($"Psst, **{msg.Member.DisplayName ?? msg.Member.Name}** (<@{msg.Message.Sender}>), you have been pinged by <@{userWhoReacted}>.", embed: embed.Build());
|
||||||
|
|
||||||
// Finally remove the original reaction (if we can)
|
// Finally remove the original reaction (if we can)
|
||||||
|
Loading…
Reference in New Issue
Block a user