feat: ignore entity commands, actually ignore events when the entity is ignored

This commit is contained in:
sam 2024-11-18 21:26:47 +01:00
parent 4eb5c16451
commit 223f808151
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
4 changed files with 348 additions and 3 deletions

View file

@ -295,8 +295,8 @@ public class WebhookExecutorService(
if (isMessageLog)
return GetMessageLogChannel(guild, logChannelType, channelId, userId);
if (isChannelLog && guild.IgnoredChannels.Contains(channelId!.Value.Value))
return null;
if (isChannelLog)
return GetChannelLogChannel(guild, logChannelType, channelId!.Value);
if (isRoleLog && guild.IgnoredRoles.Contains(roleId!.Value.Value))
return null;
@ -309,6 +309,45 @@ public class WebhookExecutorService(
return GetDefaultLogChannel(guild, logChannelType);
}
private ulong? GetChannelLogChannel(
Guild guild,
LogChannelType logChannelType,
Snowflake channelId
)
{
if (!channelCache.TryGet(channelId, out var channel))
return GetDefaultLogChannel(guild, logChannelType);
Snowflake? categoryId;
if (
channel.Type
is ChannelType.AnnouncementThread
or ChannelType.PrivateThread
or ChannelType.PublicThread
)
{
// parent_id should always have a value for threads
channelId = channel.ParentID.Value!.Value;
if (!channelCache.TryGet(channelId, out var parentChannel))
return GetDefaultLogChannel(guild, logChannelType);
categoryId = parentChannel.ParentID.Value;
}
else
{
channelId = channel.ID;
categoryId = channel.ParentID.Value;
}
// Check if the channel or its category is ignored
if (
guild.IgnoredChannels.Contains(channelId.Value)
|| (categoryId != null && guild.IgnoredChannels.Contains(categoryId.Value.Value))
)
return null;
return GetDefaultLogChannel(guild, logChannelType);
}
private ulong? GetMessageLogChannel(
Guild guild,
LogChannelType logChannelType,