feat: split ignores into 'ignore messages' and 'ignore entities'

This commit is contained in:
sam 2024-11-18 00:47:27 +01:00
parent d48ab7e16e
commit 0cac964aa6
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
32 changed files with 730 additions and 488 deletions

View file

@ -24,18 +24,28 @@ public class Guild
public required ulong Id { get; init; }
public ChannelConfig Channels { get; init; } = new();
public MessageConfig Messages { get; init; } = new();
public string[] BannedSystems { get; set; } = [];
public ulong[] KeyRoles { get; set; } = [];
// These channels and roles are ignored for channel/role update/delete events.
public ulong[] IgnoredChannels { get; set; } = [];
public ulong[] IgnoredRoles { get; set; } = [];
public bool IsSystemBanned(PluralkitApiService.PkSystem system) =>
BannedSystems.Contains(system.Id) || BannedSystems.Contains(system.Uuid.ToString());
public bool IsMessageIgnored(Snowflake channelId, Snowflake? userId)
public bool IsMessageIgnored(
Snowflake channelId,
Snowflake? userId,
IReadOnlyList<Snowflake>? roleIds
)
{
if (
Channels is { MessageDelete: 0, MessageUpdate: 0, MessageDeleteBulk: 0 }
|| Channels.IgnoredChannels.Contains(channelId.ToUlong())
|| (userId != null && Channels.IgnoredUsers.Contains(userId.Value.ToUlong()))
|| Messages.IgnoredChannels.Contains(channelId.ToUlong())
|| (userId != null && Messages.IgnoredUsers.Contains(userId.Value.ToUlong()))
|| (roleIds != null && roleIds.Any(r => Messages.IgnoredRoles.Any(id => r.Value == id)))
)
return true;
@ -43,7 +53,7 @@ public class Guild
return false;
if (
Channels.IgnoredUsersPerChannel.TryGetValue(
Messages.IgnoredUsersPerChannel.TryGetValue(
channelId.ToUlong(),
out var thisChannelIgnoredUsers
)
@ -53,11 +63,16 @@ public class Guild
return false;
}
public class ChannelConfig
public class MessageConfig
{
public List<ulong> IgnoredChannels { get; set; } = [];
public List<ulong> IgnoredRoles { get; set; } = [];
public List<ulong> IgnoredUsers { get; init; } = [];
public Dictionary<ulong, List<ulong>> IgnoredUsersPerChannel { get; init; } = [];
}
public class ChannelConfig
{
public Dictionary<ulong, ulong> Redirects { get; init; } = [];
public ulong GuildUpdate { get; set; }