I broke the Db I guess?

This commit is contained in:
Toastie 2024-04-14 23:36:32 +12:00
parent b8df0d8b06
commit 1ee97675b0
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
59 changed files with 149 additions and 93 deletions

View file

@ -11,7 +11,7 @@ namespace EllieBot.Services.Database;
public abstract class EllieContext : DbContext
{
public DbSet<GuildConfig> GuildConfigs { get; set; }
public DbSet<Quote> Quotes { get; set; }
public DbSet<Reminder> Reminders { get; set; }
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
@ -60,8 +60,8 @@ public abstract class EllieContext : DbContext
public DbSet<PatronQuota> PatronQuotas { get; set; }
public DbSet<StreamOnlineMessage> StreamOnlineMessages { get; set; }
#region Mandatory Provider-Specific Values
protected abstract string CurrencyTransactionOtherIdDefaultValue { get; }

View file

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

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using EllieBot.Services.Database.Models;
@ -12,9 +12,9 @@ public static class CurrencyTransactionExtensions
ulong userId,
int page)
=> set.ToLinqToDBTable()
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(15 * page)
.Take(15)
.ToListAsyncLinqToDB();
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(15 * page)
.Take(15)
.ToListAsyncLinqToDB();
}

View file

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

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

View file

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

View file

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

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Microsoft.EntityFrameworkCore;
using EllieBot.Services.Database.Models;
@ -8,7 +8,7 @@ public static class MusicPlaylistExtensions
{
public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num)
{
if (num < 0)
if (num < 1)
throw new ArgumentOutOfRangeException(nameof(num));
return playlists.AsQueryable().Skip((num - 1) * 20).Take(20).Include(pl => pl.Songs).ToList();

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Microsoft.EntityFrameworkCore;
using EllieBot.Services.Database;
using EllieBot.Services.Database.Models;
@ -20,9 +20,15 @@ public static class PollExtensions
if (p.Votes is not null)
{
ctx.RemoveRange(p.Votes);
p.Votes.Clear();
}
if (p.Answers is not null)
{
ctx.RemoveRange(p.Answers);
p.Answers.Clear();
}
ctx.Poll.Remove(p);
}
}

View file

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

View file

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

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using LinqToDB;
using Microsoft.EntityFrameworkCore;
using EllieBot.Services.Database;

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

View file

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

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class AntiRaidSetting : DbEntity
@ -11,10 +11,10 @@ public class AntiRaidSetting : DbEntity
public PunishmentAction Action { get; set; }
/// <summary>
/// Duration of the punishment, in minutes. This works only in supported Actions, like:
/// Mute, ChatMute, VoiceMute, etc...
/// Duration of the punishment, in minutes. This works only for supported Actions, like:
/// Mute, Chatmute, Voicemute, etc...
/// </summary>
public int PunishmentDuration { get; set; }
public int PunishDuration { get; set; }
}
public class AntiSpamSetting : DbEntity
@ -57,9 +57,9 @@ public class AntiSpamIgnore : DbEntity
{
public ulong ChannelId { get; set; }
public override int GetHashCode()
public override int GetHashCode()
=> ChannelId.GetHashCode();
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is AntiSpamIgnore inst ? inst.ChannelId == ChannelId : false;
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class AutoCommand : DbEntity

View file

@ -1,4 +1,4 @@
using EllieBot.Services.Database.Models;
using EllieBot.Services.Database.Models;
namespace EllieBot.Db.Models;

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class AutoTranslateChannel : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class AutoTranslateUser : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class BanTemplate : DbEntity

View file

@ -1,3 +1,4 @@
#nullable disable
namespace EllieBot.Services.Database.Models;
public class BlacklistEntry : DbEntity

View file

@ -9,8 +9,8 @@ public class ClubInfo : DbEntity
[MaxLength(20)]
public string Name { get; set; }
public string Description { get; set; }
public string ImageUrl { 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; }
@ -27,7 +27,7 @@ public class ClubApplicants
{
public int ClubId { get; set; }
public ClubInfo Club { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
}
@ -36,7 +36,7 @@ public class ClubBans
{
public int ClubId { get; set; }
public ClubInfo Club { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class CommandAlias : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class CommandCooldown : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class DelMsgOnCmdChannel : DbEntity
@ -9,6 +9,6 @@ public class DelMsgOnCmdChannel : DbEntity
public override int GetHashCode()
=> ChannelId.GetHashCode();
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is DelMsgOnCmdChannel x && x.ChannelId == ChannelId;
}

View file

@ -10,20 +10,20 @@ public class DiscordUser : DbEntity
public string Username { get; set; }
public string Discriminator { get; set; }
public string AvatarId { get; set; }
public int? ClubId { get; set; }
public ClubInfo Club { get; set; }
public bool IsClubAdmin { get; set; }
public long TotalXp { get; set; }
public XpNotificationLocation NotifyOnLevelUp { get; set; }
public long CurrencyAmount { get; set; }
public override bool Equals(object obj)
=> obj is DiscordUser du ? du.UserId == UserId : false;
public override int GetHashCode()
public override int GetHashCode()
=> UserId.GetHashCode();
public override string ToString()

View file

@ -6,14 +6,15 @@ public class EllieExpression : DbEntity
public ulong? GuildId { get; set; }
public string Response { get; set; }
public string Trigger { get; set; }
public bool AutoDeleteTrigger { get; set; }
public bool DmResponse { get; set; }
public bool ContainsAnywhere { get; set; }
public bool AllowTarget { get; set; }
public string Reactions { get; set; }
public string[] GetReactions()
=> string.IsNullOrWhiteSpace(Reaactions) ? Array.Empty<string>() : Reaactions.Split("@@@");
=> string.IsNullOrWhiteSpace(Reactions) ? Array.Empty<string>() : Reactions.Split("@@@");
public bool IsGlobal()
=> GuildId is null or 0;

View file

@ -0,0 +1,49 @@
#nullable disable
namespace EllieBot.Services.Database.Models;
public class CurrencyEvent
{
public enum Type
{
Reaction,
GameStatus
//NotRaid,
}
public ulong ServerId { get; set; }
public ulong ChannelId { get; set; }
public ulong MessageId { get; set; }
public Type EventType { get; set; }
/// <summary>
/// Amount of currency that the user will be rewarded.
/// </summary>
public long Amount { get; set; }
/// <summary>
/// Maximum amount of currency that can be handed out.
/// </summary>
public long PotSize { get; set; }
public List<AwardedUser> AwardedUsers { get; set; }
/// <summary>
/// Used as extra data storage for events which need it.
/// </summary>
public ulong ExtraId { get; set; }
/// <summary>
/// May be used for some future event.
/// </summary>
public ulong ExtraId2 { get; set; }
/// <summary>
/// May be used for some future event.
/// </summary>
public string ExtraString { get; set; }
}
public class AwardedUser
{
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class FeedSub : DbEntity
@ -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()

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class FilterChannelId : DbEntity
@ -11,7 +11,7 @@ public class FilterChannelId : DbEntity
public override bool Equals(object obj)
=> obj is FilterChannelId fci && Equals(fci);
public override int GetHashCode()
public override int GetHashCode()
=> ChannelId.GetHashCode();
}
@ -22,7 +22,7 @@ public class FilterWordsChannelId : DbEntity
public bool Equals(FilterWordsChannelId other)
=> ChannelId == other.ChannelId;
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is FilterWordsChannelId fci && Equals(fci);
public override int GetHashCode()

View file

@ -1,13 +1,13 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class FilterLinksChannelId : DbEntity
{
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is FilterLinksChannelId f && f.ChannelId == ChannelId;
public override int GetHashCode()
public override int GetHashCode()
=> ChannelId.GetHashCode();
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class FilteredWord : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using EllieBot.Modules.Searches.Common;
using EllieBot.Services.Database.Models;

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class GCChannelId : DbEntity
@ -6,9 +6,9 @@ public class GCChannelId : DbEntity
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is GCChannelId gc && gc.ChannelId == ChannelId;
public override int GetHashCode()
public override int GetHashCode()
=> ChannelId.GetHashCode();
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class GroupName : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using EllieBot.Db.Models;
namespace EllieBot.Services.Database.Models;

View file

@ -26,10 +26,10 @@ public class LogSetting : DbEntity
public ulong? UserMutedId { get; set; }
// userpresence
//userpresence
public ulong? LogUserPresenceId { get; set; }
// voicepresence
//voicepresence
public ulong? LogVoicePresenceId { get; set; }
public ulong? LogVoicePresenceTTSId { get; set; }

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class MutedUserId : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Db.Models;
/// <summary>

View file

@ -1,10 +1,9 @@
#nullable disable
#nullable disable
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace EllieBot.Services.Database.Models;
[DebuggerDisplay("{PrimaryTarget}{SecondaryTarget} {SecondaryTargetName} {State} {PrimaryTargetId}")]
public class Permissionv2 : DbEntity, IIndexed
{

View file

@ -5,7 +5,7 @@ public class SelfAssignedRole : DbEntity
{
public ulong GuildId { get; set; }
public ulong RoleId { get; set; }
public int Group { get; set; }
public int LevelRequirement { get; set; }
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public enum ShopEntryType

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class SlowmodeIgnoredRole : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class SlowmodeIgnoredUser : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using EllieBot.Services.Database.Models;
namespace EllieBot.Db.Models;

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class StreamRoleSettings : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class UnbanTimer : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class UnmuteTimer : DbEntity
@ -9,6 +9,6 @@ public class UnmuteTimer : DbEntity
public override int GetHashCode()
=> UserId.GetHashCode();
public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is UnmuteTimer ut ? ut.UserId == UserId : false;
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class UnroleTimer : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class VcRoleInfo : DbEntity

View file

@ -1,10 +1,10 @@
#nullable disable
namespace EllieBot.Services.Database.Models;
public class WaifuItem
public class WaifuItem : DbEntity
{
public WaifuInfo WaifuInfo { get; set; }
public int? WaifuInfoId { get; set; }
public string ItemEmoji { get; set; }
public string Name { get; set; }
}
}

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public enum WarnExpireAction

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class WarningPunishment : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace EllieBot.Services.Database.Models;
public class XpSettings : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable
#nullable disable warnings
using EllieBot.Services.Database.Models;
namespace EllieBot.Db.Models;

View file

@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using EllieBot.Db.Models;
namespace EllieBot.Services.Database;
@ -8,7 +8,7 @@ public sealed class MysqlContext : EllieContext
private readonly string _connStr;
private readonly string _version;
protected override string CurrencyTransactionOtherIdDefaultValue
protected override string CurrencyTransactionOtherIdDefaultValue
=> "NULL";
public MysqlContext(string connStr = "Server=localhost", string version = "8.0")

View file

@ -1,12 +1,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace EllieBot.Services.Database;
public class PostgreSqlContext : EllieContext
public sealed class PostgreSqlContext : EllieContext
{
private readonly string _connStr;
protected override string CurrencyTransactionOtherIdDefaultValue
protected override string CurrencyTransactionOtherIdDefaultValue
=> "NULL";
public PostgreSqlContext(string connStr = "Host=localhost")

View file

@ -1,4 +1,4 @@
using Microsoft.Data.Sqlite;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace EllieBot.Services.Database;
@ -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)