Catalogger.NET/Catalogger.Backend/Database/Models/Guild.cs

88 lines
3.4 KiB
C#
Raw Normal View History

// 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 <https://www.gnu.org/licenses/>.
2024-08-13 13:08:50 +02:00
using Catalogger.Backend.Extensions;
using Catalogger.Backend.Services;
2024-08-13 13:08:50 +02:00
using Remora.Rest.Core;
namespace Catalogger.Backend.Database.Models;
public class Guild
{
public required ulong Id { get; init; }
2024-10-09 17:35:11 +02:00
public ChannelConfig Channels { get; init; } = new();
public string[] BannedSystems { get; set; } = [];
public ulong[] KeyRoles { get; set; } = [];
2024-08-13 13:08:50 +02:00
public bool IsSystemBanned(PluralkitApiService.PkSystem system) =>
BannedSystems.Contains(system.Id) || BannedSystems.Contains(system.Uuid.ToString());
public bool IsMessageIgnored(Snowflake channelId, Snowflake? userId)
2024-08-13 13:08:50 +02:00
{
2024-10-09 17:35:11 +02:00
if (
Channels is { MessageDelete: 0, MessageUpdate: 0, MessageDeleteBulk: 0 }
|| Channels.IgnoredChannels.Contains(channelId.ToUlong())
|| (userId != null && Channels.IgnoredUsers.Contains(userId.Value.ToUlong()))
2024-10-09 17:35:11 +02:00
)
return true;
2024-08-13 13:08:50 +02:00
if (userId == null)
return false;
2024-10-09 17:35:11 +02:00
if (
Channels.IgnoredUsersPerChannel.TryGetValue(
channelId.ToUlong(),
out var thisChannelIgnoredUsers
)
)
return thisChannelIgnoredUsers.Contains(userId.Value.ToUlong());
2024-08-13 13:08:50 +02:00
return false;
}
public class ChannelConfig
{
2024-10-19 23:27:57 +02:00
public List<ulong> IgnoredChannels { get; set; } = [];
2024-08-13 13:08:50 +02:00
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; }
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
}