From 29c0b4acfc1cfdf986e5bf79d1af475673976373 Mon Sep 17 00:00:00 2001 From: Toastie Date: Fri, 14 Jun 2024 00:20:21 +1200 Subject: [PATCH] Updated Db models I hate working on database stuff --- src/EllieBot/Db/EllieContext.cs | 243 +++++++++++++++--- src/EllieBot/Db/Extensions/ClubExtensions.cs | 2 +- .../Db/Extensions/DiscordUserExtensions.cs | 110 ++++---- .../Db/Extensions/GuildConfigExtensions.cs | 9 +- src/EllieBot/Db/Extensions/QuoteExtensions.cs | 2 +- .../Db/Extensions/UserXpExtensions.cs | 61 +++-- .../Db/Extensions/WarningExtensions.cs | 3 +- src/EllieBot/Db/Helpers/ActivityType.cs | 2 +- src/EllieBot/Db/Helpers/GuildPerm.cs | 4 +- src/EllieBot/Db/LevelStats.cs | 4 +- src/EllieBot/Db/Models/DelMsgOnCmdChannel.cs | 2 + src/EllieBot/Db/Models/DiscordUser.cs | 2 +- src/EllieBot/Db/Models/FeedSub.cs | 2 +- src/EllieBot/Db/Models/FollowedStream.cs | 2 +- src/EllieBot/Db/Models/GuildConfig.cs | 1 + .../Db/Models/IgnoredVoicePresenceChannel.cs | 8 - src/EllieBot/Db/Models/LogSetting.cs | 8 +- src/EllieBot/Db/Models/Permission.cs | 5 +- src/EllieBot/Db/Models/ShopEntry.cs | 2 +- src/EllieBot/Db/Models/StreamRoleSettings.cs | 6 + src/EllieBot/Db/Models/Waifu.cs | 4 +- src/EllieBot/Db/Models/anti/AntiAltSetting.cs | 3 +- .../Db/Models/anti/AntiRaidSetting.cs | 5 +- .../Db/Models/anti/AntiSpamSetting.cs | 3 +- src/EllieBot/Db/Models/club/ClubInfo.cs | 2 +- .../Db/Models/filter/FilterChannelId.cs | 14 - .../Db/Models/filter/FilterWordsChannelId.cs | 17 ++ src/EllieBot/Db/Models/support/PatronQuota.cs | 6 +- src/EllieBot/Db/Models/xp/XpSettings.cs | 2 + src/EllieBot/Db/MysqlContext.cs | 2 +- src/EllieBot/Db/PostgreSqlContext.cs | 4 +- src/EllieBot/Db/SqliteContext.cs | 2 +- 32 files changed, 357 insertions(+), 185 deletions(-) delete mode 100644 src/EllieBot/Db/Models/IgnoredVoicePresenceChannel.cs create mode 100644 src/EllieBot/Db/Models/filter/FilterWordsChannelId.cs diff --git a/src/EllieBot/Db/EllieContext.cs b/src/EllieBot/Db/EllieContext.cs index d61d2f7..263963b 100644 --- a/src/EllieBot/Db/EllieContext.cs +++ b/src/EllieBot/Db/EllieContext.cs @@ -28,7 +28,6 @@ public abstract class EllieContext : DbContext //logging public DbSet LogSettings { get; set; } - public DbSet IgnoredVoicePresenceCHannels { get; set; } public DbSet IgnoredLogChannels { get; set; } public DbSet RotatingStatus { get; set; } @@ -86,15 +85,84 @@ public abstract class EllieContext : DbContext #region GuildConfig var configEntity = modelBuilder.Entity(); + configEntity.HasIndex(c => c.GuildId) .IsUnique(); configEntity.Property(x => x.VerboseErrors) .HasDefaultValue(true); - modelBuilder.Entity().HasOne(x => x.GuildConfig).WithOne(x => x.AntiSpamSetting); + modelBuilder.Entity() + .HasMany(x => x.DelMsgOnCmdChannels) + .WithOne() + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); - modelBuilder.Entity().HasOne(x => x.GuildConfig).WithOne(x => x.AntiRaidSetting); + modelBuilder.Entity() + .HasMany(x => x.FollowedStreams) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.GenerateCurrencyChannelIds) + .WithOne(x => x.GuildConfig) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.Permissions) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.CommandCooldowns) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.FilterInvitesChannelIds) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.FilterLinksChannelIds) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.FilteredWords) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.FilterWordsChannelIds) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.MutedUsers) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasOne(x => x.AntiRaidSetting) + .WithOne() + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); + + // start antispam + + modelBuilder.Entity() + .HasOne(x => x.AntiSpamSetting) + .WithOne() + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.IgnoredChannels) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + // end antispam modelBuilder.Entity() .HasOne(x => x.AntiAltSetting) @@ -102,6 +170,98 @@ public abstract class EllieContext : DbContext .HasForeignKey(x => x.GuildConfigId) .OnDelete(DeleteBehavior.Cascade); + modelBuilder.Entity() + .HasMany(x => x.UnmuteTimers) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.UnbanTimer) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.UnroleTimer) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.VcRoleInfos) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.CommandAliases) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.WarnPunishments) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.SlowmodeIgnoredRoles) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.SlowmodeIgnoredUsers) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + // start shop + modelBuilder.Entity() + .HasMany(x => x.ShopEntries) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.Items) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + // end shop + + // start streamrole + + modelBuilder.Entity() + .HasOne(x => x.StreamRole) + .WithOne(x => x.GuildConfig) + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.Whitelist) + .WithOne(x => x.StreamRoleSettings) + .HasForeignKey(x => x.StreamRoleSettingsId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.Blacklist) + .WithOne(x => x.StreamRoleSettings) + .HasForeignKey(x => x.StreamRoleSettingsId) + .OnDelete(DeleteBehavior.Cascade); + + // end streamrole + + modelBuilder.Entity() + .HasOne(x => x.XpSettings) + .WithOne(x => x.GuildConfig) + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.FeedSubs) + .WithOne(x => x.GuildConfig) + .HasForeignKey(x => x.GuildConfigId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.SelfAssignableRoleGroupNames) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + modelBuilder.Entity() .HasAlternateKey(x => new { @@ -117,11 +277,6 @@ public abstract class EllieContext : DbContext #endregion - #region streamrole - - modelBuilder.Entity().HasOne(x => x.GuildConfig).WithOne(x => x.StreamRole); - - #endregion #region Self Assignable Roles @@ -217,12 +372,6 @@ public abstract class EllieContext : DbContext #endregion - #region XpSettings - - modelBuilder.Entity().HasOne(x => x.GuildConfig).WithOne(x => x.XpSettings); - - #endregion - #region XpRoleReward modelBuilder.Entity() @@ -233,6 +382,21 @@ public abstract class EllieContext : DbContext }) .IsUnique(); + modelBuilder.Entity() + .HasMany(x => x.RoleRewards) + .WithOne(x => x.XpSettings) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.CurrencyRewards) + .WithOne(x => x.XpSettings) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(x => x.ExclusionList) + .WithOne(x => x.XpSettings) + .OnDelete(DeleteBehavior.Cascade); + #endregion #region Club @@ -331,9 +495,9 @@ public abstract class EllieContext : DbContext modelBuilder.Entity().HasIndex(x => x.GuildId).IsUnique(); modelBuilder.Entity() - .Property(x => x.PruneDays) - .HasDefaultValue(null) - .IsRequired(false); + .Property(x => x.PruneDays) + .HasDefaultValue(null) + .IsRequired(false); #endregion @@ -458,7 +622,7 @@ public abstract class EllieContext : DbContext model.ItemType, model.ItemKey }) - .IsUnique(); + .IsUnique(); }); #endregion @@ -466,16 +630,16 @@ public abstract class EllieContext : DbContext #region AutoPublish modelBuilder.Entity(apc => apc - .HasIndex(x => x.GuildId) - .IsUnique()); + .HasIndex(x => x.GuildId) + .IsUnique()); #endregion #region GamblingStats modelBuilder.Entity(gs => gs - .HasIndex(x => x.Feature) - .IsUnique()); + .HasIndex(x => x.Feature) + .IsUnique()); #endregion @@ -485,7 +649,8 @@ public abstract class EllieContext : DbContext { x.GuildId, x.UserId - }).IsUnique()); + }) + .IsUnique()); #endregion @@ -493,18 +658,18 @@ public abstract class EllieContext : DbContext #region Giveaway modelBuilder.Entity() - .HasMany(x => x.Participants) - .WithOne() - .HasForeignKey(x => x.GiveawayId) - .OnDelete(DeleteBehavior.Cascade); + .HasMany(x => x.Participants) + .WithOne() + .HasForeignKey(x => x.GiveawayId) + .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity(gu => gu - .HasIndex(x => new - { - x.GiveawayId, - x.UserId - }) - .IsUnique()); + .HasIndex(x => new + { + x.GiveawayId, + x.UserId + }) + .IsUnique()); #endregion @@ -514,14 +679,14 @@ public abstract class EllieContext : DbContext .HasKey(x => x.Id); modelBuilder.Entity() - .HasIndex(x => x.UserId) - .IsUnique(false); + .HasIndex(x => x.UserId) + .IsUnique(false); modelBuilder.Entity() - .HasMany(x => x.Items) - .WithOne() - .HasForeignKey(x => x.ArchiveId) - .OnDelete(DeleteBehavior.Cascade); + .HasMany(x => x.Items) + .WithOne() + .HasForeignKey(x => x.ArchiveId) + .OnDelete(DeleteBehavior.Cascade); #endregion } diff --git a/src/EllieBot/Db/Extensions/ClubExtensions.cs b/src/EllieBot/Db/Extensions/ClubExtensions.cs index d8183fc..88a851b 100644 --- a/src/EllieBot/Db/Extensions/ClubExtensions.cs +++ b/src/EllieBot/Db/Extensions/ClubExtensions.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using Microsoft.EntityFrameworkCore; using EllieBot.Db.Models; diff --git a/src/EllieBot/Db/Extensions/DiscordUserExtensions.cs b/src/EllieBot/Db/Extensions/DiscordUserExtensions.cs index 6d74316..bdf3c05 100644 --- a/src/EllieBot/Db/Extensions/DiscordUserExtensions.cs +++ b/src/EllieBot/Db/Extensions/DiscordUserExtensions.cs @@ -20,48 +20,48 @@ public static class DiscordUserExtensions string discrim, string avatarId) => ctx.GetTable() - .InsertOrUpdate( - () => new() - { - UserId = userId, - Username = username, - Discriminator = discrim, - AvatarId = avatarId, - TotalXp = 0, - CurrencyAmount = 0 - }, - old => new() - { - Username = username, - Discriminator = discrim, - AvatarId = avatarId - }, - () => new() - { - UserId = userId - }); + .InsertOrUpdate( + () => new() + { + UserId = userId, + Username = username, + Discriminator = discrim, + AvatarId = avatarId, + TotalXp = 0, + CurrencyAmount = 0 + }, + old => new() + { + Username = username, + Discriminator = discrim, + AvatarId = avatarId + }, + () => new() + { + UserId = userId + }); public static Task EnsureUserCreatedAsync( this DbContext ctx, ulong userId) => ctx.GetTable() - .InsertOrUpdateAsync( - () => new() - { - UserId = userId, - Username = "Unknown", - Discriminator = "????", - AvatarId = string.Empty, - TotalXp = 0, - CurrencyAmount = 0 - }, - old => new() - { - }, - () => new() - { - UserId = userId - }); + .InsertOrUpdateAsync( + () => new() + { + UserId = userId, + Username = "Unknown", + Discriminator = "????", + AvatarId = string.Empty, + TotalXp = 0, + CurrencyAmount = 0 + }, + old => new() + { + }, + () => new() + { + UserId = userId + }); //temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown public static DiscordUser GetOrCreateUser( @@ -83,25 +83,29 @@ public static class DiscordUserExtensions public static int GetUserGlobalRank(this DbSet users, ulong id) => users.AsQueryable() - .Where(x => x.TotalXp - > users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault()) - .Count() + .Where(x => x.TotalXp + > users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault()) + .Count() + 1; - public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet users, int page, int perPage) - => users.AsQueryable().OrderByDescending(x => x.TotalXp).Skip(page * perPage).Take(perPage).AsEnumerable() - .ToArray(); + public static async Task> GetUsersXpLeaderboardFor(this DbSet users, int page, int perPage) + => await users.ToLinqToDBTable() + .OrderByDescending(x => x.TotalXp) + .Skip(page * perPage) + .Take(perPage) + .ToArrayAsyncLinqToDB(); public static Task> GetTopRichest( this DbSet users, ulong botId, - int page = 0, int perPage = 9) + int page = 0, + int perPage = 9) => users.AsQueryable() - .Where(c => c.CurrencyAmount > 0 && botId != c.UserId) - .OrderByDescending(c => c.CurrencyAmount) - .Skip(page * perPage) - .Take(perPage) - .ToListAsyncLinqToDB(); + .Where(c => c.CurrencyAmount > 0 && botId != c.UserId) + .OrderByDescending(c => c.CurrencyAmount) + .Skip(page * perPage) + .Take(perPage) + .ToListAsyncLinqToDB(); public static async Task GetUserCurrencyAsync(this DbSet users, ulong userId) => (await users.FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId))?.CurrencyAmount ?? 0; @@ -118,8 +122,8 @@ public static class DiscordUserExtensions public static decimal GetTopOnePercentCurrency(this DbSet users, ulong botId) => users.AsQueryable() - .Where(x => x.UserId != botId) - .OrderByDescending(x => x.CurrencyAmount) - .Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100) - .Sum(x => x.CurrencyAmount); + .Where(x => x.UserId != botId) + .OrderByDescending(x => x.CurrencyAmount) + .Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100) + .Sum(x => x.CurrencyAmount); } \ No newline at end of file diff --git a/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs b/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs index bffa943..7d16127 100644 --- a/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using Microsoft.EntityFrameworkCore; using EllieBot.Db.Models; @@ -7,19 +7,20 @@ namespace EllieBot.Db; public static class GuildConfigExtensions { private static List DefaultWarnPunishments - => new() - { + => + [ new() { Count = 3, Punishment = PunishmentAction.Kick }, + new() { Count = 5, Punishment = PunishmentAction.Ban } - }; + ]; /// /// Gets full stream role settings for the guild with the specified id. diff --git a/src/EllieBot/Db/Extensions/QuoteExtensions.cs b/src/EllieBot/Db/Extensions/QuoteExtensions.cs index 67698e9..a213e6d 100644 --- a/src/EllieBot/Db/Extensions/QuoteExtensions.cs +++ b/src/EllieBot/Db/Extensions/QuoteExtensions.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using Microsoft.EntityFrameworkCore; using EllieBot.Db.Models; diff --git a/src/EllieBot/Db/Extensions/UserXpExtensions.cs b/src/EllieBot/Db/Extensions/UserXpExtensions.cs index c7e0f8c..ab3e8bb 100644 --- a/src/EllieBot/Db/Extensions/UserXpExtensions.cs +++ b/src/EllieBot/Db/Extensions/UserXpExtensions.cs @@ -26,33 +26,33 @@ public static class UserXpExtensions return usr; } - public static List GetUsersFor(this DbSet xps, ulong guildId, int page) - => xps.AsQueryable() - .AsNoTracking() - .Where(x => x.GuildId == guildId) - .OrderByDescending(x => x.Xp + x.AwardedXp) - .Skip(page * 9) - .Take(9) - .ToList(); + public static async Task> GetUsersFor( + this DbSet xps, + ulong guildId, + int page) + => await xps.ToLinqToDBTable() + .Where(x => x.GuildId == guildId) + .OrderByDescending(x => x.Xp + x.AwardedXp) + .Skip(page * 9) + .Take(9) + .ToArrayAsyncLinqToDB(); - public static List GetTopUserXps(this DbSet xps, ulong guildId, int count) - => xps.AsQueryable() - .AsNoTracking() - .Where(x => x.GuildId == guildId) - .OrderByDescending(x => x.Xp + x.AwardedXp) - .Take(count) - .ToList(); + public static async Task> GetTopUserXps(this DbSet xps, ulong guildId, int count) + => await xps.ToLinqToDBTable() + .Where(x => x.GuildId == guildId) + .OrderByDescending(x => x.Xp + x.AwardedXp) + .Take(count) + .ToListAsyncLinqToDB(); - public static int GetUserGuildRanking(this DbSet xps, ulong userId, ulong guildId) - => xps.AsQueryable() - .AsNoTracking() - .Where(x => x.GuildId == guildId - && x.Xp + x.AwardedXp - > xps.AsQueryable() - .Where(y => y.UserId == userId && y.GuildId == guildId) - .Select(y => y.Xp + y.AwardedXp) - .FirstOrDefault()) - .Count() + public static async Task GetUserGuildRanking(this DbSet xps, ulong userId, ulong guildId) + => await xps.ToLinqToDBTable() + .Where(x => x.GuildId == guildId + && x.Xp + x.AwardedXp + > xps.AsQueryable() + .Where(y => y.UserId == userId && y.GuildId == guildId) + .Select(y => y.Xp + y.AwardedXp) + .FirstOrDefault()) + .CountAsyncLinqToDB() + 1; public static void ResetGuildUserXp(this DbSet xps, ulong userId, ulong guildId) @@ -62,10 +62,9 @@ public static class UserXpExtensions => xps.Delete(x => x.GuildId == guildId); public static async Task GetLevelDataFor(this ITable userXp, ulong guildId, ulong userId) - => await userXp - .Where(x => x.GuildId == guildId && x.UserId == userId) - .FirstOrDefaultAsyncLinqToDB() is UserXpStats uxs - ? new(uxs.Xp + uxs.AwardedXp) - : new(0); - + => await userXp + .Where(x => x.GuildId == guildId && x.UserId == userId) + .FirstOrDefaultAsyncLinqToDB() is UserXpStats uxs + ? new(uxs.Xp + uxs.AwardedXp) + : new(0); } \ No newline at end of file diff --git a/src/EllieBot/Db/Extensions/WarningExtensions.cs b/src/EllieBot/Db/Extensions/WarningExtensions.cs index c223f7d..15f1039 100644 --- a/src/EllieBot/Db/Extensions/WarningExtensions.cs +++ b/src/EllieBot/Db/Extensions/WarningExtensions.cs @@ -22,8 +22,7 @@ public static class WarningExtensions string mod, int index) { - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + ArgumentOutOfRangeException.ThrowIfNegative(index); var warn = warnings.AsQueryable() .Where(x => x.GuildId == guildId && x.UserId == userId) diff --git a/src/EllieBot/Db/Helpers/ActivityType.cs b/src/EllieBot/Db/Helpers/ActivityType.cs index 64bdd73..9c71e4b 100644 --- a/src/EllieBot/Db/Helpers/ActivityType.cs +++ b/src/EllieBot/Db/Helpers/ActivityType.cs @@ -1,4 +1,4 @@ -namespace EllieBot.Db; +namespace EllieBot.Db; public enum DbActivityType { diff --git a/src/EllieBot/Db/Helpers/GuildPerm.cs b/src/EllieBot/Db/Helpers/GuildPerm.cs index 4713afa..60c4cde 100644 --- a/src/EllieBot/Db/Helpers/GuildPerm.cs +++ b/src/EllieBot/Db/Helpers/GuildPerm.cs @@ -1,4 +1,4 @@ -namespace EllieBot.Db; +namespace EllieBot.Db; [Flags] public enum GuildPerm : ulong @@ -44,4 +44,4 @@ public enum GuildPerm : ulong SendMessagesInThreads = 274877906944, // 0x0000004000000000 StartEmbeddedActivities = 549755813888, // 0x0000008000000000 ModerateMembers = 1099511627776, // 0x0000010000000000 -} +} \ No newline at end of file diff --git a/src/EllieBot/Db/LevelStats.cs b/src/EllieBot/Db/LevelStats.cs index fbb2e47..0f3e02c 100644 --- a/src/EllieBot/Db/LevelStats.cs +++ b/src/EllieBot/Db/LevelStats.cs @@ -1,10 +1,10 @@ -#nullable disable +#nullable disable namespace EllieBot.Db; public readonly struct LevelStats { public const int XP_REQUIRED_LVL_1 = 36; - + public long Level { get; } public long LevelXp { get; } public long RequiredXp { get; } diff --git a/src/EllieBot/Db/Models/DelMsgOnCmdChannel.cs b/src/EllieBot/Db/Models/DelMsgOnCmdChannel.cs index 6cbe756..dd70ed6 100644 --- a/src/EllieBot/Db/Models/DelMsgOnCmdChannel.cs +++ b/src/EllieBot/Db/Models/DelMsgOnCmdChannel.cs @@ -3,6 +3,8 @@ namespace EllieBot.Db.Models; public class DelMsgOnCmdChannel : DbEntity { + public int GuildConfigId { get; set; } + public ulong ChannelId { get; set; } public bool State { get; set; } diff --git a/src/EllieBot/Db/Models/DiscordUser.cs b/src/EllieBot/Db/Models/DiscordUser.cs index 83bda60..69eecb6 100644 --- a/src/EllieBot/Db/Models/DiscordUser.cs +++ b/src/EllieBot/Db/Models/DiscordUser.cs @@ -29,7 +29,7 @@ public class DiscordUser : DbEntity { if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000") return Username; - + return Username + "#" + Discriminator; } } \ No newline at end of file diff --git a/src/EllieBot/Db/Models/FeedSub.cs b/src/EllieBot/Db/Models/FeedSub.cs index 66fc6f1..f257f96 100644 --- a/src/EllieBot/Db/Models/FeedSub.cs +++ b/src/EllieBot/Db/Models/FeedSub.cs @@ -8,7 +8,7 @@ public class FeedSub : DbEntity public ulong ChannelId { get; set; } public string Url { get; set; } - + public string Message { get; set; } public override int GetHashCode() diff --git a/src/EllieBot/Db/Models/FollowedStream.cs b/src/EllieBot/Db/Models/FollowedStream.cs index c880a8d..183e0ab 100644 --- a/src/EllieBot/Db/Models/FollowedStream.cs +++ b/src/EllieBot/Db/Models/FollowedStream.cs @@ -29,5 +29,5 @@ public class FollowedStream : DbEntity public override bool Equals(object obj) => obj is FollowedStream fs && Equals(fs); - + } \ No newline at end of file diff --git a/src/EllieBot/Db/Models/GuildConfig.cs b/src/EllieBot/Db/Models/GuildConfig.cs index a7b5ac5..a88d3c0 100644 --- a/src/EllieBot/Db/Models/GuildConfig.cs +++ b/src/EllieBot/Db/Models/GuildConfig.cs @@ -3,6 +3,7 @@ namespace EllieBot.Db.Models; public class GuildConfig : DbEntity { + // public bool Keep { get; set; } public ulong GuildId { get; set; } public string Prefix { get; set; } diff --git a/src/EllieBot/Db/Models/IgnoredVoicePresenceChannel.cs b/src/EllieBot/Db/Models/IgnoredVoicePresenceChannel.cs deleted file mode 100644 index cbbda9e..0000000 --- a/src/EllieBot/Db/Models/IgnoredVoicePresenceChannel.cs +++ /dev/null @@ -1,8 +0,0 @@ -#nullable disable -namespace EllieBot.Db.Models; - -public class IgnoredVoicePresenceChannel : DbEntity -{ - public LogSetting LogSetting { get; set; } - public ulong ChannelId { get; set; } -} \ No newline at end of file diff --git a/src/EllieBot/Db/Models/LogSetting.cs b/src/EllieBot/Db/Models/LogSetting.cs index 677a128..916b1b8 100644 --- a/src/EllieBot/Db/Models/LogSetting.cs +++ b/src/EllieBot/Db/Models/LogSetting.cs @@ -4,7 +4,7 @@ namespace EllieBot.Db.Models; public class LogSetting : DbEntity { public List LogIgnores { get; set; } = new(); - + public ulong GuildId { get; set; } public ulong? LogOtherId { get; set; } public ulong? MessageUpdatedId { get; set; } @@ -19,8 +19,8 @@ public class LogSetting : DbEntity public ulong? ChannelCreatedId { get; set; } public ulong? ChannelDestroyedId { get; set; } public ulong? ChannelUpdatedId { get; set; } - - + + public ulong? ThreadDeletedId { get; set; } public ulong? ThreadCreatedId { get; set; } @@ -32,7 +32,7 @@ public class LogSetting : DbEntity //voicepresence public ulong? LogVoicePresenceId { get; set; } - + public ulong? LogVoicePresenceTTSId { get; set; } public ulong? LogWarnsId { get; set; } } \ No newline at end of file diff --git a/src/EllieBot/Db/Models/Permission.cs b/src/EllieBot/Db/Models/Permission.cs index 5670dd8..b926f92 100644 --- a/src/EllieBot/Db/Models/Permission.cs +++ b/src/EllieBot/Db/Models/Permission.cs @@ -33,10 +33,7 @@ public class Permissionv2 : DbEntity, IIndexed }; public static List GetDefaultPermlist - => new() - { - AllowAllPerm - }; + => [AllowAllPerm]; } public enum PrimaryPermissionType diff --git a/src/EllieBot/Db/Models/ShopEntry.cs b/src/EllieBot/Db/Models/ShopEntry.cs index 34cc8fe..a21c7e6 100644 --- a/src/EllieBot/Db/Models/ShopEntry.cs +++ b/src/EllieBot/Db/Models/ShopEntry.cs @@ -25,7 +25,7 @@ public class ShopEntry : DbEntity, IIndexed //list public HashSet Items { get; set; } = new(); public ulong? RoleRequirement { get; set; } - + // command public string Command { get; set; } } diff --git a/src/EllieBot/Db/Models/StreamRoleSettings.cs b/src/EllieBot/Db/Models/StreamRoleSettings.cs index 02674d5..bd36b4c 100644 --- a/src/EllieBot/Db/Models/StreamRoleSettings.cs +++ b/src/EllieBot/Db/Models/StreamRoleSettings.cs @@ -40,6 +40,9 @@ public class StreamRoleSettings : DbEntity public class StreamRoleBlacklistedUser : DbEntity { + public int StreamRoleSettingsId { get; set; } + public StreamRoleSettings StreamRoleSettings { get; set; } + public ulong UserId { get; set; } public string Username { get; set; } @@ -57,6 +60,9 @@ public class StreamRoleBlacklistedUser : DbEntity public class StreamRoleWhitelistedUser : DbEntity { + public int StreamRoleSettingsId { get; set; } + public StreamRoleSettings StreamRoleSettings { get; set; } + public ulong UserId { get; set; } public string Username { get; set; } diff --git a/src/EllieBot/Db/Models/Waifu.cs b/src/EllieBot/Db/Models/Waifu.cs index 78ca0b3..d9f36d9 100644 --- a/src/EllieBot/Db/Models/Waifu.cs +++ b/src/EllieBot/Db/Models/Waifu.cs @@ -1,13 +1,13 @@ #nullable disable using EllieBot.Db.Models; -namespace EllieBot.Services.Database.Models; +namespace NadekoBot.Services.Database.Models; public class WaifuInfo : DbEntity { public int WaifuId { get; set; } public DiscordUser Waifu { get; set; } - + public int? ClaimerId { get; set; } public DiscordUser Claimer { get; set; } diff --git a/src/EllieBot/Db/Models/anti/AntiAltSetting.cs b/src/EllieBot/Db/Models/anti/AntiAltSetting.cs index b9f9e58..cb0da3c 100644 --- a/src/EllieBot/Db/Models/anti/AntiAltSetting.cs +++ b/src/EllieBot/Db/Models/anti/AntiAltSetting.cs @@ -2,8 +2,9 @@ public class AntiAltSetting { - public int Id { get; set; } public int GuildConfigId { get; set; } + + public int Id { get; set; } public TimeSpan MinAge { get; set; } public PunishmentAction Action { get; set; } public int ActionDurationMinutes { get; set; } diff --git a/src/EllieBot/Db/Models/anti/AntiRaidSetting.cs b/src/EllieBot/Db/Models/anti/AntiRaidSetting.cs index aef2658..b5e5f67 100644 --- a/src/EllieBot/Db/Models/anti/AntiRaidSetting.cs +++ b/src/EllieBot/Db/Models/anti/AntiRaidSetting.cs @@ -1,12 +1,13 @@ #nullable disable +using System.ComponentModel.DataAnnotations.Schema; + namespace EllieBot.Db.Models; public class AntiRaidSetting : DbEntity { public int GuildConfigId { get; set; } - public GuildConfig GuildConfig { get; set; } - + public int UserThreshold { get; set; } public int Seconds { get; set; } public PunishmentAction Action { get; set; } diff --git a/src/EllieBot/Db/Models/anti/AntiSpamSetting.cs b/src/EllieBot/Db/Models/anti/AntiSpamSetting.cs index 42c2183..7e19253 100644 --- a/src/EllieBot/Db/Models/anti/AntiSpamSetting.cs +++ b/src/EllieBot/Db/Models/anti/AntiSpamSetting.cs @@ -4,8 +4,7 @@ public class AntiSpamSetting : DbEntity { public int GuildConfigId { get; set; } - public GuildConfig GuildConfig { get; set; } - + public PunishmentAction Action { get; set; } public int MessageThreshold { get; set; } = 3; public int MuteTime { get; set; } diff --git a/src/EllieBot/Db/Models/club/ClubInfo.cs b/src/EllieBot/Db/Models/club/ClubInfo.cs index e5b7407..a7bc16f 100644 --- a/src/EllieBot/Db/Models/club/ClubInfo.cs +++ b/src/EllieBot/Db/Models/club/ClubInfo.cs @@ -9,7 +9,7 @@ public class ClubInfo : DbEntity public string Name { get; set; } public string Description { get; set; } public string ImageUrl { get; set; } = string.Empty; - + public int Xp { get; set; } = 0; public int? OwnerId { get; set; } public DiscordUser Owner { get; set; } diff --git a/src/EllieBot/Db/Models/filter/FilterChannelId.cs b/src/EllieBot/Db/Models/filter/FilterChannelId.cs index fe3b97b..eb1d965 100644 --- a/src/EllieBot/Db/Models/filter/FilterChannelId.cs +++ b/src/EllieBot/Db/Models/filter/FilterChannelId.cs @@ -14,17 +14,3 @@ public class FilterChannelId : DbEntity public override int GetHashCode() => ChannelId.GetHashCode(); } - -public class FilterWordsChannelId : DbEntity -{ - public ulong ChannelId { get; set; } - - public bool Equals(FilterWordsChannelId other) - => ChannelId == other.ChannelId; - - public override bool Equals(object obj) - => obj is FilterWordsChannelId fci && Equals(fci); - - public override int GetHashCode() - => ChannelId.GetHashCode(); -} \ No newline at end of file diff --git a/src/EllieBot/Db/Models/filter/FilterWordsChannelId.cs b/src/EllieBot/Db/Models/filter/FilterWordsChannelId.cs new file mode 100644 index 0000000..6921032 --- /dev/null +++ b/src/EllieBot/Db/Models/filter/FilterWordsChannelId.cs @@ -0,0 +1,17 @@ +#nullable disable +namespace EllieBot.Db.Models; + +public class FilterWordsChannelId : DbEntity +{ + public int? GuildConfigId { get; set; } + public ulong ChannelId { get; set; } + + public bool Equals(FilterWordsChannelId other) + => ChannelId == other.ChannelId; + + public override bool Equals(object obj) + => obj is FilterWordsChannelId fci && Equals(fci); + + public override int GetHashCode() + => ChannelId.GetHashCode(); +} \ No newline at end of file diff --git a/src/EllieBot/Db/Models/support/PatronQuota.cs b/src/EllieBot/Db/Models/support/PatronQuota.cs index b87dcbc..1ebd2fd 100644 --- a/src/EllieBot/Db/Models/support/PatronQuota.cs +++ b/src/EllieBot/Db/Models/support/PatronQuota.cs @@ -30,12 +30,12 @@ public class PatronUser public string UniquePlatformUserId { get; set; } public ulong UserId { get; set; } public int AmountCents { get; set; } - + public DateTime LastCharge { get; set; } - + // Date Only component public DateTime ValidThru { get; set; } - + public PatronUser Clone() => new PatronUser() { diff --git a/src/EllieBot/Db/Models/xp/XpSettings.cs b/src/EllieBot/Db/Models/xp/XpSettings.cs index 694b289..50fd5be 100644 --- a/src/EllieBot/Db/Models/xp/XpSettings.cs +++ b/src/EllieBot/Db/Models/xp/XpSettings.cs @@ -51,6 +51,8 @@ public class XpCurrencyReward : DbEntity public class ExcludedItem : DbEntity { + public XpSettings XpSettings { get; set; } + public ulong ItemId { get; set; } public ExcludedItemType ItemType { get; set; } diff --git a/src/EllieBot/Db/MysqlContext.cs b/src/EllieBot/Db/MysqlContext.cs index e8f4eba..7563640 100644 --- a/src/EllieBot/Db/MysqlContext.cs +++ b/src/EllieBot/Db/MysqlContext.cs @@ -28,7 +28,7 @@ public sealed class MysqlContext : EllieContext protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - + // mysql is case insensitive by default // we can set binary collation to change that modelBuilder.Entity() diff --git a/src/EllieBot/Db/PostgreSqlContext.cs b/src/EllieBot/Db/PostgreSqlContext.cs index aea3e7c..2305d19 100644 --- a/src/EllieBot/Db/PostgreSqlContext.cs +++ b/src/EllieBot/Db/PostgreSqlContext.cs @@ -6,7 +6,7 @@ public sealed class PostgreSqlContext : EllieContext { private readonly string _connStr; - protected override string CurrencyTransactionOtherIdDefaultValue + protected override string CurrencyTransactionOtherIdDefaultValue => "NULL"; public PostgreSqlContext(string connStr = "Host=localhost") @@ -17,7 +17,7 @@ public sealed class PostgreSqlContext : EllieContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - + base.OnConfiguring(optionsBuilder); optionsBuilder .UseLowerCaseNamingConvention() diff --git a/src/EllieBot/Db/SqliteContext.cs b/src/EllieBot/Db/SqliteContext.cs index e284968..516d445 100644 --- a/src/EllieBot/Db/SqliteContext.cs +++ b/src/EllieBot/Db/SqliteContext.cs @@ -7,7 +7,7 @@ public sealed class SqliteContext : EllieContext { private readonly string _connectionString; - protected override string CurrencyTransactionOtherIdDefaultValue + protected override string CurrencyTransactionOtherIdDefaultValue => "NULL"; public SqliteContext(string connectionString = "Data Source=data/EllieBot.db", int commandTimeout = 60)