2024-08-13 13:08:50 +02:00
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using Catalogger.Backend.Extensions;
|
2024-10-13 14:58:44 +02:00
|
|
|
using Catalogger.Backend.Services;
|
2024-08-13 13:08:50 +02:00
|
|
|
using Remora.Rest.Core;
|
|
|
|
|
|
|
|
|
|
namespace Catalogger.Backend.Database.Models;
|
|
|
|
|
|
|
|
|
|
public class Guild
|
|
|
|
|
{
|
|
|
|
|
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
|
|
|
|
public required ulong Id { get; init; }
|
|
|
|
|
|
2024-10-09 17:35:11 +02:00
|
|
|
[Column(TypeName = "jsonb")]
|
|
|
|
|
public ChannelConfig Channels { get; init; } = new();
|
2024-08-13 13:08:50 +02:00
|
|
|
public List<string> BannedSystems { get; init; } = [];
|
|
|
|
|
public List<ulong> KeyRoles { get; init; } = [];
|
|
|
|
|
|
2024-10-13 14:58:44 +02:00
|
|
|
public bool IsSystemBanned(PluralkitApiService.PkSystem system) =>
|
|
|
|
|
BannedSystems.Contains(system.Id) || BannedSystems.Contains(system.Uuid.ToString());
|
|
|
|
|
|
2024-08-13 13:08:50 +02:00
|
|
|
public bool IsMessageIgnored(Snowflake channelId, Snowflake userId)
|
|
|
|
|
{
|
2024-10-09 17:35:11 +02:00
|
|
|
if (
|
|
|
|
|
Channels is { MessageDelete: 0, MessageUpdate: 0, MessageDeleteBulk: 0 }
|
|
|
|
|
|| Channels.IgnoredChannels.Contains(channelId.ToUlong())
|
|
|
|
|
|| Channels.IgnoredUsers.Contains(userId.ToUlong())
|
|
|
|
|
)
|
|
|
|
|
return true;
|
2024-08-13 13:08:50 +02:00
|
|
|
|
2024-10-09 17:35:11 +02:00
|
|
|
if (
|
|
|
|
|
Channels.IgnoredUsersPerChannel.TryGetValue(
|
|
|
|
|
channelId.ToUlong(),
|
|
|
|
|
out var thisChannelIgnoredUsers
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-08-13 13:08:50 +02:00
|
|
|
return thisChannelIgnoredUsers.Contains(userId.ToUlong());
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ChannelConfig
|
|
|
|
|
{
|
|
|
|
|
public List<ulong> IgnoredChannels { get; init; } = [];
|
|
|
|
|
public List<ulong> IgnoredUsers { get; init; } = [];
|
|
|
|
|
public Dictionary<ulong, List<ulong>> IgnoredUsersPerChannel { get; init; } = [];
|
|
|
|
|
public Dictionary<ulong, ulong> Redirects { get; init; } = [];
|
|
|
|
|
|
2024-08-14 16:05:43 +02:00
|
|
|
public ulong GuildUpdate { get; set; }
|
|
|
|
|
public ulong GuildEmojisUpdate { get; set; }
|
|
|
|
|
public ulong GuildRoleCreate { get; set; }
|
|
|
|
|
public ulong GuildRoleUpdate { get; set; }
|
|
|
|
|
public ulong GuildRoleDelete { get; set; }
|
|
|
|
|
public ulong ChannelCreate { get; set; }
|
|
|
|
|
public ulong ChannelUpdate { get; set; }
|
|
|
|
|
public ulong ChannelDelete { get; set; }
|
|
|
|
|
public ulong GuildMemberAdd { get; set; }
|
|
|
|
|
public ulong GuildMemberUpdate { get; set; }
|
|
|
|
|
public ulong GuildKeyRoleUpdate { get; set; }
|
|
|
|
|
public ulong GuildMemberNickUpdate { get; set; }
|
|
|
|
|
public ulong GuildMemberAvatarUpdate { get; set; }
|
2024-10-11 20:38:53 +02:00
|
|
|
public ulong GuildMemberTimeout { get; set; }
|
2024-08-14 16:05:43 +02:00
|
|
|
public ulong GuildMemberRemove { get; set; }
|
|
|
|
|
public ulong GuildMemberKick { get; set; }
|
|
|
|
|
public ulong GuildBanAdd { get; set; }
|
|
|
|
|
public ulong GuildBanRemove { get; set; }
|
|
|
|
|
public ulong InviteCreate { get; set; }
|
|
|
|
|
public ulong InviteDelete { get; set; }
|
|
|
|
|
public ulong MessageUpdate { get; set; }
|
|
|
|
|
public ulong MessageDelete { get; set; }
|
|
|
|
|
public ulong MessageDeleteBulk { get; set; }
|
2024-08-13 13:08:50 +02:00
|
|
|
}
|
2024-10-09 17:35:11 +02:00
|
|
|
}
|