// Copyright (C) 2021-present sam (starshines.gay)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
using System.ComponentModel.DataAnnotations.Schema;
using Catalogger.Backend.Extensions;
using Catalogger.Backend.Services;
using Remora.Rest.Core;
namespace Catalogger.Backend.Database.Models;
public class Guild
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public required ulong Id { get; init; }
[Column(TypeName = "jsonb")]
public ChannelConfig Channels { get; init; } = new();
public List BannedSystems { get; init; } = [];
public List KeyRoles { get; init; } = [];
public bool IsSystemBanned(PluralkitApiService.PkSystem system) =>
BannedSystems.Contains(system.Id) || BannedSystems.Contains(system.Uuid.ToString());
public bool IsMessageIgnored(Snowflake channelId, Snowflake? userId)
{
if (
Channels is { MessageDelete: 0, MessageUpdate: 0, MessageDeleteBulk: 0 }
|| Channels.IgnoredChannels.Contains(channelId.ToUlong())
|| (userId != null && Channels.IgnoredUsers.Contains(userId.Value.ToUlong()))
)
return true;
if (userId == null)
return false;
if (
Channels.IgnoredUsersPerChannel.TryGetValue(
channelId.ToUlong(),
out var thisChannelIgnoredUsers
)
)
return thisChannelIgnoredUsers.Contains(userId.Value.ToUlong());
return false;
}
public class ChannelConfig
{
public List IgnoredChannels { get; init; } = [];
public List IgnoredUsers { get; init; } = [];
public Dictionary> IgnoredUsersPerChannel { get; init; } = [];
public Dictionary Redirects { get; init; } = [];
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; }
public ulong GuildMemberTimeout { get; set; }
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; }
}
}