Updated Db models

I hate working on database stuff
This commit is contained in:
Toastie (DCS Team) 2024-06-14 00:20:21 +12:00
parent 97e81ac0f4
commit 29c0b4acfc
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
32 changed files with 357 additions and 185 deletions

View file

@ -28,7 +28,6 @@ public abstract class EllieContext : DbContext
//logging //logging
public DbSet<LogSetting> LogSettings { get; set; } public DbSet<LogSetting> LogSettings { get; set; }
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
public DbSet<IgnoredLogItem> IgnoredLogChannels { get; set; } public DbSet<IgnoredLogItem> IgnoredLogChannels { get; set; }
public DbSet<RotatingPlayingStatus> RotatingStatus { get; set; } public DbSet<RotatingPlayingStatus> RotatingStatus { get; set; }
@ -86,15 +85,84 @@ public abstract class EllieContext : DbContext
#region GuildConfig #region GuildConfig
var configEntity = modelBuilder.Entity<GuildConfig>(); var configEntity = modelBuilder.Entity<GuildConfig>();
configEntity.HasIndex(c => c.GuildId) configEntity.HasIndex(c => c.GuildId)
.IsUnique(); .IsUnique();
configEntity.Property(x => x.VerboseErrors) configEntity.Property(x => x.VerboseErrors)
.HasDefaultValue(true); .HasDefaultValue(true);
modelBuilder.Entity<AntiSpamSetting>().HasOne(x => x.GuildConfig).WithOne(x => x.AntiSpamSetting); modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.DelMsgOnCmdChannels)
.WithOne()
.HasForeignKey(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AntiRaidSetting>().HasOne(x => x.GuildConfig).WithOne(x => x.AntiRaidSetting); modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FollowedStreams)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.GenerateCurrencyChannelIds)
.WithOne(x => x.GuildConfig)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.Permissions)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.CommandCooldowns)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FilterInvitesChannelIds)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FilterLinksChannelIds)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FilteredWords)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FilterWordsChannelIds)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.MutedUsers)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.AntiRaidSetting)
.WithOne()
.HasForeignKey<AntiRaidSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
// start antispam
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.AntiSpamSetting)
.WithOne()
.HasForeignKey<AntiSpamSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AntiSpamSetting>()
.HasMany(x => x.IgnoredChannels)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
// end antispam
modelBuilder.Entity<GuildConfig>() modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.AntiAltSetting) .HasOne(x => x.AntiAltSetting)
@ -102,6 +170,98 @@ public abstract class EllieContext : DbContext
.HasForeignKey<AntiAltSetting>(x => x.GuildConfigId) .HasForeignKey<AntiAltSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.UnmuteTimers)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.UnbanTimer)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.UnroleTimer)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.VcRoleInfos)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.CommandAliases)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.WarnPunishments)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.SlowmodeIgnoredRoles)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.SlowmodeIgnoredUsers)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
// start shop
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.ShopEntries)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<ShopEntry>()
.HasMany(x => x.Items)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
// end shop
// start streamrole
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.StreamRole)
.WithOne(x => x.GuildConfig)
.HasForeignKey<StreamRoleSettings>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<StreamRoleSettings>()
.HasMany(x => x.Whitelist)
.WithOne(x => x.StreamRoleSettings)
.HasForeignKey(x => x.StreamRoleSettingsId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<StreamRoleSettings>()
.HasMany(x => x.Blacklist)
.WithOne(x => x.StreamRoleSettings)
.HasForeignKey(x => x.StreamRoleSettingsId)
.OnDelete(DeleteBehavior.Cascade);
// end streamrole
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.XpSettings)
.WithOne(x => x.GuildConfig)
.HasForeignKey<XpSettings>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.FeedSubs)
.WithOne(x => x.GuildConfig)
.HasForeignKey(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GuildConfig>()
.HasMany(x => x.SelfAssignableRoleGroupNames)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<FeedSub>() modelBuilder.Entity<FeedSub>()
.HasAlternateKey(x => new .HasAlternateKey(x => new
{ {
@ -117,11 +277,6 @@ public abstract class EllieContext : DbContext
#endregion #endregion
#region streamrole
modelBuilder.Entity<StreamRoleSettings>().HasOne(x => x.GuildConfig).WithOne(x => x.StreamRole);
#endregion
#region Self Assignable Roles #region Self Assignable Roles
@ -217,12 +372,6 @@ public abstract class EllieContext : DbContext
#endregion #endregion
#region XpSettings
modelBuilder.Entity<XpSettings>().HasOne(x => x.GuildConfig).WithOne(x => x.XpSettings);
#endregion
#region XpRoleReward #region XpRoleReward
modelBuilder.Entity<XpRoleReward>() modelBuilder.Entity<XpRoleReward>()
@ -233,6 +382,21 @@ public abstract class EllieContext : DbContext
}) })
.IsUnique(); .IsUnique();
modelBuilder.Entity<XpSettings>()
.HasMany(x => x.RoleRewards)
.WithOne(x => x.XpSettings)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<XpSettings>()
.HasMany(x => x.CurrencyRewards)
.WithOne(x => x.XpSettings)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<XpSettings>()
.HasMany(x => x.ExclusionList)
.WithOne(x => x.XpSettings)
.OnDelete(DeleteBehavior.Cascade);
#endregion #endregion
#region Club #region Club
@ -331,9 +495,9 @@ public abstract class EllieContext : DbContext
modelBuilder.Entity<BanTemplate>().HasIndex(x => x.GuildId).IsUnique(); modelBuilder.Entity<BanTemplate>().HasIndex(x => x.GuildId).IsUnique();
modelBuilder.Entity<BanTemplate>() modelBuilder.Entity<BanTemplate>()
.Property(x => x.PruneDays) .Property(x => x.PruneDays)
.HasDefaultValue(null) .HasDefaultValue(null)
.IsRequired(false); .IsRequired(false);
#endregion #endregion
@ -458,7 +622,7 @@ public abstract class EllieContext : DbContext
model.ItemType, model.ItemType,
model.ItemKey model.ItemKey
}) })
.IsUnique(); .IsUnique();
}); });
#endregion #endregion
@ -466,16 +630,16 @@ public abstract class EllieContext : DbContext
#region AutoPublish #region AutoPublish
modelBuilder.Entity<AutoPublishChannel>(apc => apc modelBuilder.Entity<AutoPublishChannel>(apc => apc
.HasIndex(x => x.GuildId) .HasIndex(x => x.GuildId)
.IsUnique()); .IsUnique());
#endregion #endregion
#region GamblingStats #region GamblingStats
modelBuilder.Entity<GamblingStats>(gs => gs modelBuilder.Entity<GamblingStats>(gs => gs
.HasIndex(x => x.Feature) .HasIndex(x => x.Feature)
.IsUnique()); .IsUnique());
#endregion #endregion
@ -485,7 +649,8 @@ public abstract class EllieContext : DbContext
{ {
x.GuildId, x.GuildId,
x.UserId x.UserId
}).IsUnique()); })
.IsUnique());
#endregion #endregion
@ -493,18 +658,18 @@ public abstract class EllieContext : DbContext
#region Giveaway #region Giveaway
modelBuilder.Entity<GiveawayModel>() modelBuilder.Entity<GiveawayModel>()
.HasMany(x => x.Participants) .HasMany(x => x.Participants)
.WithOne() .WithOne()
.HasForeignKey(x => x.GiveawayId) .HasForeignKey(x => x.GiveawayId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GiveawayUser>(gu => gu modelBuilder.Entity<GiveawayUser>(gu => gu
.HasIndex(x => new .HasIndex(x => new
{ {
x.GiveawayId, x.GiveawayId,
x.UserId x.UserId
}) })
.IsUnique()); .IsUnique());
#endregion #endregion
@ -514,14 +679,14 @@ public abstract class EllieContext : DbContext
.HasKey(x => x.Id); .HasKey(x => x.Id);
modelBuilder.Entity<TodoModel>() modelBuilder.Entity<TodoModel>()
.HasIndex(x => x.UserId) .HasIndex(x => x.UserId)
.IsUnique(false); .IsUnique(false);
modelBuilder.Entity<ArchivedTodoListModel>() modelBuilder.Entity<ArchivedTodoListModel>()
.HasMany(x => x.Items) .HasMany(x => x.Items)
.WithOne() .WithOne()
.HasForeignKey(x => x.ArchiveId) .HasForeignKey(x => x.ArchiveId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
#endregion #endregion
} }

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using EllieBot.Db.Models; using EllieBot.Db.Models;

View file

@ -20,48 +20,48 @@ public static class DiscordUserExtensions
string discrim, string discrim,
string avatarId) string avatarId)
=> ctx.GetTable<DiscordUser>() => ctx.GetTable<DiscordUser>()
.InsertOrUpdate( .InsertOrUpdate(
() => new() () => new()
{ {
UserId = userId, UserId = userId,
Username = username, Username = username,
Discriminator = discrim, Discriminator = discrim,
AvatarId = avatarId, AvatarId = avatarId,
TotalXp = 0, TotalXp = 0,
CurrencyAmount = 0 CurrencyAmount = 0
}, },
old => new() old => new()
{ {
Username = username, Username = username,
Discriminator = discrim, Discriminator = discrim,
AvatarId = avatarId AvatarId = avatarId
}, },
() => new() () => new()
{ {
UserId = userId UserId = userId
}); });
public static Task EnsureUserCreatedAsync( public static Task EnsureUserCreatedAsync(
this DbContext ctx, this DbContext ctx,
ulong userId) ulong userId)
=> ctx.GetTable<DiscordUser>() => ctx.GetTable<DiscordUser>()
.InsertOrUpdateAsync( .InsertOrUpdateAsync(
() => new() () => new()
{ {
UserId = userId, UserId = userId,
Username = "Unknown", Username = "Unknown",
Discriminator = "????", Discriminator = "????",
AvatarId = string.Empty, AvatarId = string.Empty,
TotalXp = 0, TotalXp = 0,
CurrencyAmount = 0 CurrencyAmount = 0
}, },
old => new() old => new()
{ {
}, },
() => new() () => new()
{ {
UserId = userId UserId = userId
}); });
//temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown //temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown
public static DiscordUser GetOrCreateUser( public static DiscordUser GetOrCreateUser(
@ -83,25 +83,29 @@ public static class DiscordUserExtensions
public static int GetUserGlobalRank(this DbSet<DiscordUser> users, ulong id) public static int GetUserGlobalRank(this DbSet<DiscordUser> users, ulong id)
=> users.AsQueryable() => users.AsQueryable()
.Where(x => x.TotalXp .Where(x => x.TotalXp
> users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault()) > users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault())
.Count() .Count()
+ 1; + 1;
public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page, int perPage) public static async Task<IReadOnlyCollection<DiscordUser>> GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page, int perPage)
=> users.AsQueryable().OrderByDescending(x => x.TotalXp).Skip(page * perPage).Take(perPage).AsEnumerable() => await users.ToLinqToDBTable()
.ToArray(); .OrderByDescending(x => x.TotalXp)
.Skip(page * perPage)
.Take(perPage)
.ToArrayAsyncLinqToDB();
public static Task<List<DiscordUser>> GetTopRichest( public static Task<List<DiscordUser>> GetTopRichest(
this DbSet<DiscordUser> users, this DbSet<DiscordUser> users,
ulong botId, ulong botId,
int page = 0, int perPage = 9) int page = 0,
int perPage = 9)
=> users.AsQueryable() => users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId) .Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount) .OrderByDescending(c => c.CurrencyAmount)
.Skip(page * perPage) .Skip(page * perPage)
.Take(perPage) .Take(perPage)
.ToListAsyncLinqToDB(); .ToListAsyncLinqToDB();
public static async Task<long> GetUserCurrencyAsync(this DbSet<DiscordUser> users, ulong userId) public static async Task<long> GetUserCurrencyAsync(this DbSet<DiscordUser> users, ulong userId)
=> (await users.FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId))?.CurrencyAmount ?? 0; => (await users.FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId))?.CurrencyAmount ?? 0;
@ -118,8 +122,8 @@ public static class DiscordUserExtensions
public static decimal GetTopOnePercentCurrency(this DbSet<DiscordUser> users, ulong botId) public static decimal GetTopOnePercentCurrency(this DbSet<DiscordUser> users, ulong botId)
=> users.AsQueryable() => users.AsQueryable()
.Where(x => x.UserId != botId) .Where(x => x.UserId != botId)
.OrderByDescending(x => x.CurrencyAmount) .OrderByDescending(x => x.CurrencyAmount)
.Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100) .Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100)
.Sum(x => x.CurrencyAmount); .Sum(x => x.CurrencyAmount);
} }

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using EllieBot.Db.Models; using EllieBot.Db.Models;
@ -7,19 +7,20 @@ namespace EllieBot.Db;
public static class GuildConfigExtensions public static class GuildConfigExtensions
{ {
private static List<WarningPunishment> DefaultWarnPunishments private static List<WarningPunishment> DefaultWarnPunishments
=> new() =>
{ [
new() new()
{ {
Count = 3, Count = 3,
Punishment = PunishmentAction.Kick Punishment = PunishmentAction.Kick
}, },
new() new()
{ {
Count = 5, Count = 5,
Punishment = PunishmentAction.Ban Punishment = PunishmentAction.Ban
} }
}; ];
/// <summary> /// <summary>
/// Gets full stream role settings for the guild with the specified id. /// Gets full stream role settings for the guild with the specified id.

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using EllieBot.Db.Models; using EllieBot.Db.Models;

View file

@ -26,33 +26,33 @@ public static class UserXpExtensions
return usr; return usr;
} }
public static List<UserXpStats> GetUsersFor(this DbSet<UserXpStats> xps, ulong guildId, int page) public static async Task<IReadOnlyCollection<UserXpStats>> GetUsersFor(
=> xps.AsQueryable() this DbSet<UserXpStats> xps,
.AsNoTracking() ulong guildId,
.Where(x => x.GuildId == guildId) int page)
.OrderByDescending(x => x.Xp + x.AwardedXp) => await xps.ToLinqToDBTable()
.Skip(page * 9) .Where(x => x.GuildId == guildId)
.Take(9) .OrderByDescending(x => x.Xp + x.AwardedXp)
.ToList(); .Skip(page * 9)
.Take(9)
.ToArrayAsyncLinqToDB();
public static List<UserXpStats> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count) public static async Task<List<UserXpStats>> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
=> xps.AsQueryable() => await xps.ToLinqToDBTable()
.AsNoTracking() .Where(x => x.GuildId == guildId)
.Where(x => x.GuildId == guildId) .OrderByDescending(x => x.Xp + x.AwardedXp)
.OrderByDescending(x => x.Xp + x.AwardedXp) .Take(count)
.Take(count) .ToListAsyncLinqToDB();
.ToList();
public static int GetUserGuildRanking(this DbSet<UserXpStats> xps, ulong userId, ulong guildId) public static async Task<int> GetUserGuildRanking(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
=> xps.AsQueryable() => await xps.ToLinqToDBTable()
.AsNoTracking() .Where(x => x.GuildId == guildId
.Where(x => x.GuildId == guildId && x.Xp + x.AwardedXp
&& x.Xp + x.AwardedXp > xps.AsQueryable()
> xps.AsQueryable() .Where(y => y.UserId == userId && y.GuildId == guildId)
.Where(y => y.UserId == userId && y.GuildId == guildId) .Select(y => y.Xp + y.AwardedXp)
.Select(y => y.Xp + y.AwardedXp) .FirstOrDefault())
.FirstOrDefault()) .CountAsyncLinqToDB()
.Count()
+ 1; + 1;
public static void ResetGuildUserXp(this DbSet<UserXpStats> xps, ulong userId, ulong guildId) public static void ResetGuildUserXp(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
@ -62,10 +62,9 @@ public static class UserXpExtensions
=> xps.Delete(x => x.GuildId == guildId); => xps.Delete(x => x.GuildId == guildId);
public static async Task<LevelStats> GetLevelDataFor(this ITable<UserXpStats> userXp, ulong guildId, ulong userId) public static async Task<LevelStats> GetLevelDataFor(this ITable<UserXpStats> userXp, ulong guildId, ulong userId)
=> await userXp => await userXp
.Where(x => x.GuildId == guildId && x.UserId == userId) .Where(x => x.GuildId == guildId && x.UserId == userId)
.FirstOrDefaultAsyncLinqToDB() is UserXpStats uxs .FirstOrDefaultAsyncLinqToDB() is UserXpStats uxs
? new(uxs.Xp + uxs.AwardedXp) ? new(uxs.Xp + uxs.AwardedXp)
: new(0); : new(0);
} }

View file

@ -22,8 +22,7 @@ public static class WarningExtensions
string mod, string mod,
int index) int index)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
throw new ArgumentOutOfRangeException(nameof(index));
var warn = warnings.AsQueryable() var warn = warnings.AsQueryable()
.Where(x => x.GuildId == guildId && x.UserId == userId) .Where(x => x.GuildId == guildId && x.UserId == userId)

View file

@ -1,4 +1,4 @@
namespace EllieBot.Db; namespace EllieBot.Db;
public enum DbActivityType public enum DbActivityType
{ {

View file

@ -1,4 +1,4 @@
namespace EllieBot.Db; namespace EllieBot.Db;
[Flags] [Flags]
public enum GuildPerm : ulong public enum GuildPerm : ulong
@ -44,4 +44,4 @@ public enum GuildPerm : ulong
SendMessagesInThreads = 274877906944, // 0x0000004000000000 SendMessagesInThreads = 274877906944, // 0x0000004000000000
StartEmbeddedActivities = 549755813888, // 0x0000008000000000 StartEmbeddedActivities = 549755813888, // 0x0000008000000000
ModerateMembers = 1099511627776, // 0x0000010000000000 ModerateMembers = 1099511627776, // 0x0000010000000000
} }

View file

@ -1,10 +1,10 @@
#nullable disable #nullable disable
namespace EllieBot.Db; namespace EllieBot.Db;
public readonly struct LevelStats public readonly struct LevelStats
{ {
public const int XP_REQUIRED_LVL_1 = 36; public const int XP_REQUIRED_LVL_1 = 36;
public long Level { get; } public long Level { get; }
public long LevelXp { get; } public long LevelXp { get; }
public long RequiredXp { get; } public long RequiredXp { get; }

View file

@ -3,6 +3,8 @@ namespace EllieBot.Db.Models;
public class DelMsgOnCmdChannel : DbEntity public class DelMsgOnCmdChannel : DbEntity
{ {
public int GuildConfigId { get; set; }
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
public bool State { get; set; } public bool State { get; set; }

View file

@ -29,7 +29,7 @@ public class DiscordUser : DbEntity
{ {
if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000") if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000")
return Username; return Username;
return Username + "#" + Discriminator; return Username + "#" + Discriminator;
} }
} }

View file

@ -8,7 +8,7 @@ public class FeedSub : DbEntity
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
public string Url { get; set; } public string Url { get; set; }
public string Message { get; set; } public string Message { get; set; }
public override int GetHashCode() public override int GetHashCode()

View file

@ -29,5 +29,5 @@ public class FollowedStream : DbEntity
public override bool Equals(object obj) public override bool Equals(object obj)
=> obj is FollowedStream fs && Equals(fs); => obj is FollowedStream fs && Equals(fs);
} }

View file

@ -3,6 +3,7 @@ namespace EllieBot.Db.Models;
public class GuildConfig : DbEntity public class GuildConfig : DbEntity
{ {
// public bool Keep { get; set; }
public ulong GuildId { get; set; } public ulong GuildId { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View file

@ -1,8 +0,0 @@
#nullable disable
namespace EllieBot.Db.Models;
public class IgnoredVoicePresenceChannel : DbEntity
{
public LogSetting LogSetting { get; set; }
public ulong ChannelId { get; set; }
}

View file

@ -4,7 +4,7 @@ namespace EllieBot.Db.Models;
public class LogSetting : DbEntity public class LogSetting : DbEntity
{ {
public List<IgnoredLogItem> LogIgnores { get; set; } = new(); public List<IgnoredLogItem> LogIgnores { get; set; } = new();
public ulong GuildId { get; set; } public ulong GuildId { get; set; }
public ulong? LogOtherId { get; set; } public ulong? LogOtherId { get; set; }
public ulong? MessageUpdatedId { get; set; } public ulong? MessageUpdatedId { get; set; }
@ -19,8 +19,8 @@ public class LogSetting : DbEntity
public ulong? ChannelCreatedId { get; set; } public ulong? ChannelCreatedId { get; set; }
public ulong? ChannelDestroyedId { get; set; } public ulong? ChannelDestroyedId { get; set; }
public ulong? ChannelUpdatedId { get; set; } public ulong? ChannelUpdatedId { get; set; }
public ulong? ThreadDeletedId { get; set; } public ulong? ThreadDeletedId { get; set; }
public ulong? ThreadCreatedId { get; set; } public ulong? ThreadCreatedId { get; set; }
@ -32,7 +32,7 @@ public class LogSetting : DbEntity
//voicepresence //voicepresence
public ulong? LogVoicePresenceId { get; set; } public ulong? LogVoicePresenceId { get; set; }
public ulong? LogVoicePresenceTTSId { get; set; } public ulong? LogVoicePresenceTTSId { get; set; }
public ulong? LogWarnsId { get; set; } public ulong? LogWarnsId { get; set; }
} }

View file

@ -33,10 +33,7 @@ public class Permissionv2 : DbEntity, IIndexed
}; };
public static List<Permissionv2> GetDefaultPermlist public static List<Permissionv2> GetDefaultPermlist
=> new() => [AllowAllPerm];
{
AllowAllPerm
};
} }
public enum PrimaryPermissionType public enum PrimaryPermissionType

View file

@ -25,7 +25,7 @@ public class ShopEntry : DbEntity, IIndexed
//list //list
public HashSet<ShopEntryItem> Items { get; set; } = new(); public HashSet<ShopEntryItem> Items { get; set; } = new();
public ulong? RoleRequirement { get; set; } public ulong? RoleRequirement { get; set; }
// command // command
public string Command { get; set; } public string Command { get; set; }
} }

View file

@ -40,6 +40,9 @@ public class StreamRoleSettings : DbEntity
public class StreamRoleBlacklistedUser : DbEntity public class StreamRoleBlacklistedUser : DbEntity
{ {
public int StreamRoleSettingsId { get; set; }
public StreamRoleSettings StreamRoleSettings { get; set; }
public ulong UserId { get; set; } public ulong UserId { get; set; }
public string Username { get; set; } public string Username { get; set; }
@ -57,6 +60,9 @@ public class StreamRoleBlacklistedUser : DbEntity
public class StreamRoleWhitelistedUser : DbEntity public class StreamRoleWhitelistedUser : DbEntity
{ {
public int StreamRoleSettingsId { get; set; }
public StreamRoleSettings StreamRoleSettings { get; set; }
public ulong UserId { get; set; } public ulong UserId { get; set; }
public string Username { get; set; } public string Username { get; set; }

View file

@ -1,13 +1,13 @@
#nullable disable #nullable disable
using EllieBot.Db.Models; using EllieBot.Db.Models;
namespace EllieBot.Services.Database.Models; namespace NadekoBot.Services.Database.Models;
public class WaifuInfo : DbEntity public class WaifuInfo : DbEntity
{ {
public int WaifuId { get; set; } public int WaifuId { get; set; }
public DiscordUser Waifu { get; set; } public DiscordUser Waifu { get; set; }
public int? ClaimerId { get; set; } public int? ClaimerId { get; set; }
public DiscordUser Claimer { get; set; } public DiscordUser Claimer { get; set; }

View file

@ -2,8 +2,9 @@
public class AntiAltSetting public class AntiAltSetting
{ {
public int Id { get; set; }
public int GuildConfigId { get; set; } public int GuildConfigId { get; set; }
public int Id { get; set; }
public TimeSpan MinAge { get; set; } public TimeSpan MinAge { get; set; }
public PunishmentAction Action { get; set; } public PunishmentAction Action { get; set; }
public int ActionDurationMinutes { get; set; } public int ActionDurationMinutes { get; set; }

View file

@ -1,12 +1,13 @@
#nullable disable #nullable disable
using System.ComponentModel.DataAnnotations.Schema;
namespace EllieBot.Db.Models; namespace EllieBot.Db.Models;
public class AntiRaidSetting : DbEntity public class AntiRaidSetting : DbEntity
{ {
public int GuildConfigId { get; set; } public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public int UserThreshold { get; set; } public int UserThreshold { get; set; }
public int Seconds { get; set; } public int Seconds { get; set; }
public PunishmentAction Action { get; set; } public PunishmentAction Action { get; set; }

View file

@ -4,8 +4,7 @@
public class AntiSpamSetting : DbEntity public class AntiSpamSetting : DbEntity
{ {
public int GuildConfigId { get; set; } public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public PunishmentAction Action { get; set; } public PunishmentAction Action { get; set; }
public int MessageThreshold { get; set; } = 3; public int MessageThreshold { get; set; } = 3;
public int MuteTime { get; set; } public int MuteTime { get; set; }

View file

@ -9,7 +9,7 @@ public class ClubInfo : DbEntity
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string ImageUrl { get; set; } = string.Empty; public string ImageUrl { get; set; } = string.Empty;
public int Xp { get; set; } = 0; public int Xp { get; set; } = 0;
public int? OwnerId { get; set; } public int? OwnerId { get; set; }
public DiscordUser Owner { get; set; } public DiscordUser Owner { get; set; }

View file

@ -14,17 +14,3 @@ public class FilterChannelId : DbEntity
public override int GetHashCode() public override int GetHashCode()
=> ChannelId.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();
}

View file

@ -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();
}

View file

@ -30,12 +30,12 @@ public class PatronUser
public string UniquePlatformUserId { get; set; } public string UniquePlatformUserId { get; set; }
public ulong UserId { get; set; } public ulong UserId { get; set; }
public int AmountCents { get; set; } public int AmountCents { get; set; }
public DateTime LastCharge { get; set; } public DateTime LastCharge { get; set; }
// Date Only component // Date Only component
public DateTime ValidThru { get; set; } public DateTime ValidThru { get; set; }
public PatronUser Clone() public PatronUser Clone()
=> new PatronUser() => new PatronUser()
{ {

View file

@ -51,6 +51,8 @@ public class XpCurrencyReward : DbEntity
public class ExcludedItem : DbEntity public class ExcludedItem : DbEntity
{ {
public XpSettings XpSettings { get; set; }
public ulong ItemId { get; set; } public ulong ItemId { get; set; }
public ExcludedItemType ItemType { get; set; } public ExcludedItemType ItemType { get; set; }

View file

@ -28,7 +28,7 @@ public sealed class MysqlContext : EllieContext
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
// mysql is case insensitive by default // mysql is case insensitive by default
// we can set binary collation to change that // we can set binary collation to change that
modelBuilder.Entity<ClubInfo>() modelBuilder.Entity<ClubInfo>()

View file

@ -6,7 +6,7 @@ public sealed class PostgreSqlContext : EllieContext
{ {
private readonly string _connStr; private readonly string _connStr;
protected override string CurrencyTransactionOtherIdDefaultValue protected override string CurrencyTransactionOtherIdDefaultValue
=> "NULL"; => "NULL";
public PostgreSqlContext(string connStr = "Host=localhost") public PostgreSqlContext(string connStr = "Host=localhost")
@ -17,7 +17,7 @@ public sealed class PostgreSqlContext : EllieContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
optionsBuilder optionsBuilder
.UseLowerCaseNamingConvention() .UseLowerCaseNamingConvention()

View file

@ -7,7 +7,7 @@ public sealed class SqliteContext : EllieContext
{ {
private readonly string _connectionString; private readonly string _connectionString;
protected override string CurrencyTransactionOtherIdDefaultValue protected override string CurrencyTransactionOtherIdDefaultValue
=> "NULL"; => "NULL";
public SqliteContext(string connectionString = "Data Source=data/EllieBot.db", int commandTimeout = 60) public SqliteContext(string connectionString = "Data Source=data/EllieBot.db", int commandTimeout = 60)