Global usings and file scoped namespaces

This commit is contained in:
Kwoth
2021-12-19 05:14:11 +01:00
parent bc31dae965
commit ee33313519
548 changed files with 47528 additions and 49115 deletions

View File

@@ -1,48 +1,45 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class ClubExtensions
{
public static class ClubExtensions
{
private static IQueryable<ClubInfo> Include(this DbSet<ClubInfo> clubs)
=> clubs.Include(x => x.Owner)
.Include(x => x.Applicants)
.ThenInclude(x => x.User)
.Include(x => x.Bans)
.ThenInclude(x => x.User)
.Include(x => x.Users)
.AsQueryable();
public static ClubInfo GetByOwner(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Owner.UserId == userId);
private static IQueryable<ClubInfo> Include(this DbSet<ClubInfo> clubs)
=> clubs.Include(x => x.Owner)
.Include(x => x.Applicants)
.ThenInclude(x => x.User)
.Include(x => x.Bans)
.ThenInclude(x => x.User)
.Include(x => x.Users)
.AsQueryable();
public static ClubInfo GetByOwner(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Owner.UserId == userId);
public static ClubInfo GetByOwnerOrAdmin(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Owner.UserId == userId
|| c.Users.Any(u => u.UserId == userId && u.IsClubAdmin));
public static ClubInfo GetByOwnerOrAdmin(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Owner.UserId == userId
|| c.Users.Any(u => u.UserId == userId && u.IsClubAdmin));
public static ClubInfo GetByMember(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Users.Any(u => u.UserId == userId));
public static ClubInfo GetByMember(this DbSet<ClubInfo> clubs, ulong userId)
=> Include(clubs).FirstOrDefault(c => c.Users.Any(u => u.UserId == userId));
public static ClubInfo GetByName(this DbSet<ClubInfo> clubs, string name, int discrim)
=> Include(clubs).FirstOrDefault(c => c.Name.ToUpper() == name.ToUpper() && c.Discrim == discrim);
public static ClubInfo GetByName(this DbSet<ClubInfo> clubs, string name, int discrim)
=> Include(clubs).FirstOrDefault(c => c.Name.ToUpper() == name.ToUpper() && c.Discrim == discrim);
public static int GetNextDiscrim(this DbSet<ClubInfo> clubs, string name)
=> Include(clubs)
.Where(x => x.Name.ToUpper() == name.ToUpper())
.Select(x => x.Discrim)
.DefaultIfEmpty()
.Max() + 1;
public static int GetNextDiscrim(this DbSet<ClubInfo> clubs, string name)
=> Include(clubs)
.Where(x => x.Name.ToUpper() == name.ToUpper())
.Select(x => x.Discrim)
.DefaultIfEmpty()
.Max() + 1;
public static List<ClubInfo> GetClubLeaderboardPage(this DbSet<ClubInfo> clubs, int page)
{
return clubs
.AsNoTracking()
.OrderByDescending(x => x.Xp)
.Skip(page * 9)
.Take(9)
.ToList();
}
public static List<ClubInfo> GetClubLeaderboardPage(this DbSet<ClubInfo> clubs, int page)
{
return clubs
.AsNoTracking()
.OrderByDescending(x => x.Xp)
.Skip(page * 9)
.Take(9)
.ToList();
}
}

View File

@@ -1,21 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class CurrencyTransactionExtensions
{
public static class CurrencyTransactionExtensions
public static List<CurrencyTransaction> GetPageFor(this DbSet<CurrencyTransaction> set, ulong userId, int page)
{
public static List<CurrencyTransaction> GetPageFor(this DbSet<CurrencyTransaction> set, ulong userId, int page)
{
return set.AsQueryable()
.AsNoTracking()
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(15 * page)
.Take(15)
.ToList();
}
return set.AsQueryable()
.AsNoTracking()
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(15 * page)
.Take(15)
.ToList();
}
}

View File

@@ -1,30 +1,27 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using LinqToDB;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class CustomReactionsExtensions
{
public static class CustomReactionsExtensions
public static int ClearFromGuild(this DbSet<CustomReaction> crs, ulong guildId)
{
public static int ClearFromGuild(this DbSet<CustomReaction> crs, ulong guildId)
{
return crs.Delete(x => x.GuildId == guildId);
}
public static IEnumerable<CustomReaction> ForId(this DbSet<CustomReaction> crs, ulong id)
{
return crs
.AsNoTracking()
.AsQueryable()
.Where(x => x.GuildId == id)
.ToArray();
}
public static CustomReaction GetByGuildIdAndInput(this DbSet<CustomReaction> crs, ulong? guildId, string input)
{
return crs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
}
return crs.Delete(x => x.GuildId == guildId);
}
}
public static IEnumerable<CustomReaction> ForId(this DbSet<CustomReaction> crs, ulong id)
{
return crs
.AsNoTracking()
.AsQueryable()
.Where(x => x.GuildId == id)
.ToArray();
}
public static CustomReaction GetByGuildIdAndInput(this DbSet<CustomReaction> crs, ulong? guildId, string input)
{
return crs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
}
}

View File

@@ -1,12 +1,10 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class DbExtensions
{
public static class DbExtensions
{
public static T GetById<T>(this DbSet<T> set, int id) where T: DbEntity
=> set.FirstOrDefault(x => x.Id == id);
}
public static T GetById<T>(this DbSet<T> set, int id) where T: DbEntity
=> set.FirstOrDefault(x => x.Id == id);
}

View File

@@ -1,145 +1,142 @@
using System;
using NadekoBot.Db.Models;
using System.Linq;
using NadekoBot.Db.Models;
using Microsoft.EntityFrameworkCore;
using Discord;
using System.Collections.Generic;
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using NadekoBot.Services.Database;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class DiscordUserExtensions
{
public static class DiscordUserExtensions
public static void EnsureUserCreated(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId)
{
public static void EnsureUserCreated(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId)
ctx.DiscordUser
.ToLinqToDBTable()
.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
});
}
//temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown
public static DiscordUser GetOrCreateUser(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId)
{
ctx.EnsureUserCreated(userId, username, discrim, avatarId);
return ctx.DiscordUser
.Include(x => x.Club)
.First(u => u.UserId == userId);
}
public static DiscordUser GetOrCreateUser(this NadekoContext ctx, IUser original)
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId);
public static int GetUserGlobalRank(this DbSet<DiscordUser> users, ulong id)
{
return users.AsQueryable()
.Where(x => x.TotalXp > (users
.AsQueryable()
.Where(y => y.UserId == id)
.Select(y => y.TotalXp)
.FirstOrDefault()))
.Count() + 1;
}
public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page)
{
return users.AsQueryable()
.OrderByDescending(x => x.TotalXp)
.Skip(page * 9)
.Take(9)
.AsEnumerable()
.ToArray();
}
public static List<DiscordUser> GetTopRichest(this DbSet<DiscordUser> users, ulong botId, int count, int page = 0)
{
return users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Skip(page * 9)
.Take(count)
.ToList();
}
public static List<DiscordUser> GetTopRichest(this DbSet<DiscordUser> users, ulong botId, int count)
{
return users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Take(count)
.ToList();
}
public static long GetUserCurrency(this DbSet<DiscordUser> users, ulong userId) =>
users.AsNoTracking()
.FirstOrDefault(x => x.UserId == userId)
?.CurrencyAmount ?? 0;
public static void RemoveFromMany(this DbSet<DiscordUser> users, IEnumerable<ulong> ids)
{
var items = users.AsQueryable().Where(x => ids.Contains(x.UserId));
foreach (var item in items)
{
ctx.DiscordUser
.ToLinqToDBTable()
.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
});
item.CurrencyAmount = 0;
}
}
//temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown
public static DiscordUser GetOrCreateUser(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId)
public static bool TryUpdateCurrencyState(this NadekoContext ctx, ulong userId, string name, string discrim, string avatarId, long amount, bool allowNegative = false)
{
if (amount == 0)
return true;
// if remove - try to remove if he has more or equal than the amount
// and return number of rows > 0 (was there a change)
if (amount < 0 && !allowNegative)
{
ctx.EnsureUserCreated(userId, username, discrim, avatarId);
return ctx.DiscordUser
.Include(x => x.Club)
.First(u => u.UserId == userId);
}
public static DiscordUser GetOrCreateUser(this NadekoContext ctx, IUser original)
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId);
public static int GetUserGlobalRank(this DbSet<DiscordUser> users, ulong id)
{
return users.AsQueryable()
.Where(x => x.TotalXp > (users
.AsQueryable()
.Where(y => y.UserId == id)
.Select(y => y.TotalXp)
.FirstOrDefault()))
.Count() + 1;
}
public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page)
{
return users.AsQueryable()
.OrderByDescending(x => x.TotalXp)
.Skip(page * 9)
.Take(9)
.AsEnumerable()
.ToArray();
}
public static List<DiscordUser> GetTopRichest(this DbSet<DiscordUser> users, ulong botId, int count, int page = 0)
{
return users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Skip(page * 9)
.Take(count)
.ToList();
}
public static List<DiscordUser> GetTopRichest(this DbSet<DiscordUser> users, ulong botId, int count)
{
return users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Take(count)
.ToList();
}
public static long GetUserCurrency(this DbSet<DiscordUser> users, ulong userId) =>
users.AsNoTracking()
.FirstOrDefault(x => x.UserId == userId)
?.CurrencyAmount ?? 0;
public static void RemoveFromMany(this DbSet<DiscordUser> users, IEnumerable<ulong> ids)
{
var items = users.AsQueryable().Where(x => ids.Contains(x.UserId));
foreach (var item in items)
{
item.CurrencyAmount = 0;
}
}
public static bool TryUpdateCurrencyState(this NadekoContext ctx, ulong userId, string name, string discrim, string avatarId, long amount, bool allowNegative = false)
{
if (amount == 0)
return true;
// if remove - try to remove if he has more or equal than the amount
// and return number of rows > 0 (was there a change)
if (amount < 0 && !allowNegative)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
var rows = ctx.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
WHERE UserId={userId} AND CurrencyAmount>={-amount};");
return rows > 0;
}
return rows > 0;
}
// if remove and negative is allowed, just remove without any condition
if (amount < 0 && allowNegative)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
// if remove and negative is allowed, just remove without any condition
if (amount < 0 && allowNegative)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
WHERE UserId={userId};");
return rows > 0;
}
return rows > 0;
}
// if add - create a new user with default values if it doesn't exist
// if it exists, sum current amount with the new one, if it doesn't
// he just has the new amount
var updatedUserData = !string.IsNullOrWhiteSpace(name);
name = name ?? "Unknown";
discrim = discrim ?? "????";
avatarId = avatarId ?? "";
// if add - create a new user with default values if it doesn't exist
// if it exists, sum current amount with the new one, if it doesn't
// he just has the new amount
var updatedUserData = !string.IsNullOrWhiteSpace(name);
name = name ?? "Unknown";
discrim = discrim ?? "????";
avatarId = avatarId ?? "";
// just update the amount, there is no new user data
if (!updatedUserData)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
// just update the amount, there is no new user data
if (!updatedUserData)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
UPDATE OR IGNORE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
WHERE UserId={userId};
@@ -148,10 +145,10 @@ INSERT OR IGNORE INTO DiscordUser (UserId, Username, Discriminator, AvatarId, Cu
VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}, 0);
");
}
else
{
ctx.Database.ExecuteSqlInterpolated($@"
}
else
{
ctx.Database.ExecuteSqlInterpolated($@"
UPDATE OR IGNORE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount},
Username={name},
@@ -162,23 +159,22 @@ WHERE UserId={userId};
INSERT OR IGNORE INTO DiscordUser (UserId, Username, Discriminator, AvatarId, CurrencyAmount, TotalXp)
VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}, 0);
");
}
return true;
}
public static decimal GetTotalCurrency(this DbSet<DiscordUser> users)
{
return users
.Sum((Func<DiscordUser, decimal>)(x => x.CurrencyAmount));
}
public static decimal GetTopOnePercentCurrency(this DbSet<DiscordUser> users, ulong botId)
{
return users.AsQueryable()
.Where(x => x.UserId != botId)
.OrderByDescending(x => x.CurrencyAmount)
.Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100)
.Sum(x => x.CurrencyAmount);
}
return true;
}
}
public static decimal GetTotalCurrency(this DbSet<DiscordUser> users)
{
return users
.Sum((Func<DiscordUser, decimal>)(x => x.CurrencyAmount));
}
public static decimal GetTopOnePercentCurrency(this DbSet<DiscordUser> users, ulong botId)
{
return users.AsQueryable()
.Where(x => x.UserId != botId)
.OrderByDescending(x => x.CurrencyAmount)
.Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100)
.Sum(x => x.CurrencyAmount);
}
}

View File

@@ -1,231 +1,227 @@
using NadekoBot.Services.Database.Models;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System;
using NadekoBot.Services.Database;
using NadekoBot.Db.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class GuildConfigExtensions
{
public static class GuildConfigExtensions
public class GeneratingChannel
{
public class GeneratingChannel
{
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
}
/// <summary>
/// Gets full stream role settings for the guild with the specified id.
/// </summary>
/// <param name="ctx">Db Context</param>
/// <param name="guildId">Id of the guild to get stream role settings for.</param>
/// <returns>Guild'p stream role settings</returns>
public static StreamRoleSettings GetStreamRoleSettings(this NadekoContext ctx, ulong guildId)
{
var conf = ctx.GuildConfigsForId(guildId, set => set.Include(y => y.StreamRole)
.Include(y => y.StreamRole.Whitelist)
.Include(y => y.StreamRole.Blacklist));
if (conf.StreamRole is null)
conf.StreamRole = new StreamRoleSettings();
return conf.StreamRole;
}
private static List<WarningPunishment> DefaultWarnPunishments =>
new List<WarningPunishment>() {
new WarningPunishment() {
Count = 3,
Punishment = PunishmentAction.Kick
},
new WarningPunishment() {
Count = 5,
Punishment = PunishmentAction.Ban
}
};
private static IQueryable<GuildConfig> IncludeEverything(this DbSet<GuildConfig> configs)
{
// todo split query
return configs
.AsQueryable()
.Include(gc => gc.CommandCooldowns)
.Include(gc => gc.FollowedStreams)
.Include(gc => gc.StreamRole)
.Include(gc => gc.XpSettings)
.ThenInclude(x => x.ExclusionList)
.Include(gc => gc.DelMsgOnCmdChannels)
.Include(gc => gc.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles)
;
}
public static IEnumerable<GuildConfig> GetAllGuildConfigs(this DbSet<GuildConfig> configs, List<ulong> availableGuilds)
=> configs
.IncludeEverything()
.AsNoTracking()
.Where(x => availableGuilds.Contains(x.GuildId))
.ToList();
/// <summary>
/// Gets and creates if it doesn't exist a config for a guild.
/// </summary>
/// <param name="guildId">For which guild</param>
/// <param name="includes">Use to manipulate the set however you want</param>
/// <returns>Config for the guild</returns>
public static GuildConfig GuildConfigsForId(this NadekoContext ctx, ulong guildId, Func<DbSet<GuildConfig>, IQueryable<GuildConfig>> includes = null)
{
GuildConfig config;
if (includes is null)
{
config = ctx
.GuildConfigs
.IncludeEverything()
.FirstOrDefault(c => c.GuildId == guildId);
}
else
{
var set = includes(ctx.GuildConfigs);
config = set.FirstOrDefault(c => c.GuildId == guildId);
}
if (config is null)
{
ctx.GuildConfigs.Add((config = new GuildConfig
{
GuildId = guildId,
Permissions = Permissionv2.GetDefaultPermlist,
WarningsInitialized = true,
WarnPunishments = DefaultWarnPunishments,
}));
ctx.SaveChanges();
}
if (!config.WarningsInitialized)
{
config.WarningsInitialized = true;
config.WarnPunishments = DefaultWarnPunishments;
}
return config;
}
public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId)
{
var logSetting = ctx.LogSettings
.AsQueryable()
.Include(x => x.LogIgnores)
.Where(x => x.GuildId == guildId)
.FirstOrDefault();
if (logSetting is null)
{
ctx.LogSettings.Add(logSetting = new ()
{
GuildId = guildId
});
ctx.SaveChanges();
}
return logSetting;
}
public static IEnumerable<GuildConfig> Permissionsv2ForAll(this DbSet<GuildConfig> configs, List<ulong> include)
{
var query = configs.AsQueryable()
.Where(x => include.Contains(x.GuildId))
.Include(gc => gc.Permissions);
return query.ToList();
}
public static GuildConfig GcWithPermissionsv2For(this NadekoContext ctx, ulong guildId)
{
var config = ctx
.GuildConfigs
.AsQueryable()
.Where(gc => gc.GuildId == guildId)
.Include(gc => gc.Permissions)
.FirstOrDefault();
if (config is null) // if there is no guildconfig, create new one
{
ctx.GuildConfigs.Add((config = new GuildConfig
{
GuildId = guildId,
Permissions = Permissionv2.GetDefaultPermlist
}));
ctx.SaveChanges();
}
else if (config.Permissions is null || !config.Permissions.Any()) // if no perms, add default ones
{
config.Permissions = Permissionv2.GetDefaultPermlist;
ctx.SaveChanges();
}
return config;
}
public static IEnumerable<FollowedStream> GetFollowedStreams(this DbSet<GuildConfig> configs)
{
return configs
.AsQueryable()
.Include(x => x.FollowedStreams)
.SelectMany(gc => gc.FollowedStreams)
.ToArray();
}
public static IEnumerable<FollowedStream> GetFollowedStreams(this DbSet<GuildConfig> configs, List<ulong> included)
{
return configs.AsQueryable()
.Where(gc => included.Contains(gc.GuildId))
.Include(gc => gc.FollowedStreams)
.SelectMany(gc => gc.FollowedStreams)
.ToList();
}
public static void SetCleverbotEnabled(this DbSet<GuildConfig> configs, ulong id, bool cleverbotEnabled)
{
var conf = configs.FirstOrDefault(gc => gc.GuildId == id);
if (conf is null)
return;
conf.CleverbotEnabled = cleverbotEnabled;
}
public static XpSettings XpSettingsFor(this NadekoContext ctx, ulong guildId)
{
var gc = ctx.GuildConfigsForId(guildId,
set => set.Include(x => x.XpSettings)
.ThenInclude(x => x.RoleRewards)
.Include(x => x.XpSettings)
.ThenInclude(x => x.CurrencyRewards)
.Include(x => x.XpSettings)
.ThenInclude(x => x.ExclusionList));
if (gc.XpSettings is null)
gc.XpSettings = new XpSettings();
return gc.XpSettings;
}
public static IEnumerable<GeneratingChannel> GetGeneratingChannels(this DbSet<GuildConfig> configs)
{
return configs
.AsQueryable()
.Include(x => x.GenerateCurrencyChannelIds)
.Where(x => x.GenerateCurrencyChannelIds.Any())
.SelectMany(x => x.GenerateCurrencyChannelIds)
.Select(x => new GeneratingChannel()
{
ChannelId = x.ChannelId,
GuildId = x.GuildConfig.GuildId
})
.ToArray();
}
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
}
}
/// <summary>
/// Gets full stream role settings for the guild with the specified id.
/// </summary>
/// <param name="ctx">Db Context</param>
/// <param name="guildId">Id of the guild to get stream role settings for.</param>
/// <returns>Guild'p stream role settings</returns>
public static StreamRoleSettings GetStreamRoleSettings(this NadekoContext ctx, ulong guildId)
{
var conf = ctx.GuildConfigsForId(guildId, set => set.Include(y => y.StreamRole)
.Include(y => y.StreamRole.Whitelist)
.Include(y => y.StreamRole.Blacklist));
if (conf.StreamRole is null)
conf.StreamRole = new StreamRoleSettings();
return conf.StreamRole;
}
private static List<WarningPunishment> DefaultWarnPunishments =>
new List<WarningPunishment>() {
new WarningPunishment() {
Count = 3,
Punishment = PunishmentAction.Kick
},
new WarningPunishment() {
Count = 5,
Punishment = PunishmentAction.Ban
}
};
private static IQueryable<GuildConfig> IncludeEverything(this DbSet<GuildConfig> configs)
{
// todo split query
return configs
.AsQueryable()
.Include(gc => gc.CommandCooldowns)
.Include(gc => gc.FollowedStreams)
.Include(gc => gc.StreamRole)
.Include(gc => gc.XpSettings)
.ThenInclude(x => x.ExclusionList)
.Include(gc => gc.DelMsgOnCmdChannels)
.Include(gc => gc.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles)
;
}
public static IEnumerable<GuildConfig> GetAllGuildConfigs(this DbSet<GuildConfig> configs, List<ulong> availableGuilds)
=> configs
.IncludeEverything()
.AsNoTracking()
.Where(x => availableGuilds.Contains(x.GuildId))
.ToList();
/// <summary>
/// Gets and creates if it doesn't exist a config for a guild.
/// </summary>
/// <param name="guildId">For which guild</param>
/// <param name="includes">Use to manipulate the set however you want</param>
/// <returns>Config for the guild</returns>
public static GuildConfig GuildConfigsForId(this NadekoContext ctx, ulong guildId, Func<DbSet<GuildConfig>, IQueryable<GuildConfig>> includes = null)
{
GuildConfig config;
if (includes is null)
{
config = ctx
.GuildConfigs
.IncludeEverything()
.FirstOrDefault(c => c.GuildId == guildId);
}
else
{
var set = includes(ctx.GuildConfigs);
config = set.FirstOrDefault(c => c.GuildId == guildId);
}
if (config is null)
{
ctx.GuildConfigs.Add((config = new GuildConfig
{
GuildId = guildId,
Permissions = Permissionv2.GetDefaultPermlist,
WarningsInitialized = true,
WarnPunishments = DefaultWarnPunishments,
}));
ctx.SaveChanges();
}
if (!config.WarningsInitialized)
{
config.WarningsInitialized = true;
config.WarnPunishments = DefaultWarnPunishments;
}
return config;
}
public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId)
{
var logSetting = ctx.LogSettings
.AsQueryable()
.Include(x => x.LogIgnores)
.Where(x => x.GuildId == guildId)
.FirstOrDefault();
if (logSetting is null)
{
ctx.LogSettings.Add(logSetting = new ()
{
GuildId = guildId
});
ctx.SaveChanges();
}
return logSetting;
}
public static IEnumerable<GuildConfig> Permissionsv2ForAll(this DbSet<GuildConfig> configs, List<ulong> include)
{
var query = configs.AsQueryable()
.Where(x => include.Contains(x.GuildId))
.Include(gc => gc.Permissions);
return query.ToList();
}
public static GuildConfig GcWithPermissionsv2For(this NadekoContext ctx, ulong guildId)
{
var config = ctx
.GuildConfigs
.AsQueryable()
.Where(gc => gc.GuildId == guildId)
.Include(gc => gc.Permissions)
.FirstOrDefault();
if (config is null) // if there is no guildconfig, create new one
{
ctx.GuildConfigs.Add((config = new GuildConfig
{
GuildId = guildId,
Permissions = Permissionv2.GetDefaultPermlist
}));
ctx.SaveChanges();
}
else if (config.Permissions is null || !config.Permissions.Any()) // if no perms, add default ones
{
config.Permissions = Permissionv2.GetDefaultPermlist;
ctx.SaveChanges();
}
return config;
}
public static IEnumerable<FollowedStream> GetFollowedStreams(this DbSet<GuildConfig> configs)
{
return configs
.AsQueryable()
.Include(x => x.FollowedStreams)
.SelectMany(gc => gc.FollowedStreams)
.ToArray();
}
public static IEnumerable<FollowedStream> GetFollowedStreams(this DbSet<GuildConfig> configs, List<ulong> included)
{
return configs.AsQueryable()
.Where(gc => included.Contains(gc.GuildId))
.Include(gc => gc.FollowedStreams)
.SelectMany(gc => gc.FollowedStreams)
.ToList();
}
public static void SetCleverbotEnabled(this DbSet<GuildConfig> configs, ulong id, bool cleverbotEnabled)
{
var conf = configs.FirstOrDefault(gc => gc.GuildId == id);
if (conf is null)
return;
conf.CleverbotEnabled = cleverbotEnabled;
}
public static XpSettings XpSettingsFor(this NadekoContext ctx, ulong guildId)
{
var gc = ctx.GuildConfigsForId(guildId,
set => set.Include(x => x.XpSettings)
.ThenInclude(x => x.RoleRewards)
.Include(x => x.XpSettings)
.ThenInclude(x => x.CurrencyRewards)
.Include(x => x.XpSettings)
.ThenInclude(x => x.ExclusionList));
if (gc.XpSettings is null)
gc.XpSettings = new XpSettings();
return gc.XpSettings;
}
public static IEnumerable<GeneratingChannel> GetGeneratingChannels(this DbSet<GuildConfig> configs)
{
return configs
.AsQueryable()
.Include(x => x.GenerateCurrencyChannelIds)
.Where(x => x.GenerateCurrencyChannelIds.Any())
.SelectMany(x => x.GenerateCurrencyChannelIds)
.Select(x => new GeneratingChannel()
{
ChannelId = x.ChannelId,
GuildId = x.GuildConfig.GuildId
})
.ToArray();
}
}

View File

@@ -2,29 +2,28 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class MusicPlayerSettingsExtensions
{
public static class MusicPlayerSettingsExtensions
public static async Task<MusicPlayerSettings> ForGuildAsync(this DbSet<MusicPlayerSettings> settings, ulong guildId)
{
public static async Task<MusicPlayerSettings> ForGuildAsync(this DbSet<MusicPlayerSettings> settings, ulong guildId)
var toReturn = await settings
.AsQueryable()
.FirstOrDefaultAsync(x => x.GuildId == guildId);
if (toReturn is null)
{
var toReturn = await settings
.AsQueryable()
.FirstOrDefaultAsync(x => x.GuildId == guildId);
if (toReturn is null)
var newSettings = new MusicPlayerSettings()
{
var newSettings = new MusicPlayerSettings()
{
GuildId = guildId,
PlayerRepeat = PlayerRepeatType.Queue
};
GuildId = guildId,
PlayerRepeat = PlayerRepeatType.Queue
};
await settings.AddAsync(newSettings);
return newSettings;
}
return toReturn;
await settings.AddAsync(newSettings);
return newSettings;
}
return toReturn;
}
}

View File

@@ -1,29 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class MusicPlaylistExtensions
{
public static class MusicPlaylistExtensions
public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num)
{
public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num)
{
if (num < 1)
throw new IndexOutOfRangeException();
if (num < 1)
throw new IndexOutOfRangeException();
return playlists
.AsQueryable()
.Skip((num - 1) * 20)
.Take(20)
.Include(pl => pl.Songs)
.ToList();
}
public static MusicPlaylist GetWithSongs(this DbSet<MusicPlaylist> playlists, int id) =>
playlists
.Include(mpl => mpl.Songs)
.FirstOrDefault(mpl => mpl.Id == id);
return playlists
.AsQueryable()
.Skip((num - 1) * 20)
.Take(20)
.Include(pl => pl.Songs)
.ToList();
}
}
public static MusicPlaylist GetWithSongs(this DbSet<MusicPlaylist> playlists, int id) =>
playlists
.Include(mpl => mpl.Songs)
.FirstOrDefault(mpl => mpl.Id == id);
}

View File

@@ -1,46 +1,41 @@
using NadekoBot.Db.Models;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class PollExtensions
{
public static class PollExtensions
public static IEnumerable<Poll> GetAllPolls(this DbSet<Poll> polls)
{
public static IEnumerable<Poll> GetAllPolls(this DbSet<Poll> polls)
{
return polls.Include(x => x.Answers)
.Include(x => x.Votes)
.ToArray();
}
public static void RemovePoll(this NadekoContext ctx, int id)
{
var p = ctx
.Poll
.Include(x => x.Answers)
.Include(x => x.Votes)
.FirstOrDefault(x => x.Id == id);
if (p is null)
return;
if (p.Votes != null)
{
ctx.RemoveRange(p.Votes);
p.Votes.Clear();
}
if (p.Answers != null)
{
ctx.RemoveRange(p.Answers);
p.Answers.Clear();
}
ctx.Poll.Remove(p);
}
return polls.Include(x => x.Answers)
.Include(x => x.Votes)
.ToArray();
}
}
public static void RemovePoll(this NadekoContext ctx, int id)
{
var p = ctx
.Poll
.Include(x => x.Answers)
.Include(x => x.Votes)
.FirstOrDefault(x => x.Id == id);
if (p is null)
return;
if (p.Votes != null)
{
ctx.RemoveRange(p.Votes);
p.Votes.Clear();
}
if (p.Answers != null)
{
ctx.RemoveRange(p.Answers);
p.Answers.Clear();
}
ctx.Poll.Remove(p);
}
}

View File

@@ -1,58 +1,55 @@
using NadekoBot.Services.Database.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class QuoteExtensions
{
public static class QuoteExtensions
public static IEnumerable<Quote> GetForGuild(this DbSet<Quote> quotes, ulong guildId)
{
public static IEnumerable<Quote> GetForGuild(this DbSet<Quote> quotes, ulong guildId)
{
return quotes.AsQueryable().Where(x => x.GuildId == guildId);
}
return quotes.AsQueryable().Where(x => x.GuildId == guildId);
}
public static IEnumerable<Quote> GetGroup(this DbSet<Quote> quotes, ulong guildId, int page, OrderType order)
{
var q = quotes.AsQueryable().Where(x => x.GuildId == guildId);
if (order == OrderType.Keyword)
q = q.OrderBy(x => x.Keyword);
else
q = q.OrderBy(x => x.Id);
public static IEnumerable<Quote> GetGroup(this DbSet<Quote> quotes, ulong guildId, int page, OrderType order)
{
var q = quotes.AsQueryable().Where(x => x.GuildId == guildId);
if (order == OrderType.Keyword)
q = q.OrderBy(x => x.Keyword);
else
q = q.OrderBy(x => x.Id);
return q.Skip(15 * page).Take(15).ToArray();
}
return q.Skip(15 * page).Take(15).ToArray();
}
public static async Task<Quote> GetRandomQuoteByKeywordAsync(this DbSet<Quote> quotes, ulong guildId, string keyword)
{
var rng = new NadekoRandom();
return (await quotes.AsQueryable()
public static async Task<Quote> GetRandomQuoteByKeywordAsync(this DbSet<Quote> quotes, ulong guildId, string keyword)
{
var rng = new NadekoRandom();
return (await quotes.AsQueryable()
.Where(q => q.GuildId == guildId && q.Keyword == keyword)
.ToListAsync())
.OrderBy(q => rng.Next())
.FirstOrDefault();
}
.OrderBy(q => rng.Next())
.FirstOrDefault();
}
public static async Task<Quote> SearchQuoteKeywordTextAsync(this DbSet<Quote> quotes, ulong guildId, string keyword, string text)
{
var rngk = new NadekoRandom();
return (await quotes.AsQueryable()
public static async Task<Quote> SearchQuoteKeywordTextAsync(this DbSet<Quote> quotes, ulong guildId, string keyword, string text)
{
var rngk = new NadekoRandom();
return (await quotes.AsQueryable()
.Where(q => q.GuildId == guildId
&& q.Keyword == keyword
&& EF.Functions.Like(q.Text.ToUpper(), $"%{text.ToUpper()}%")
// && q.Text.Contains(text, StringComparison.OrdinalIgnoreCase)
)
// && q.Text.Contains(text, StringComparison.OrdinalIgnoreCase)
)
.ToListAsync())
.OrderBy(q => rngk.Next())
.FirstOrDefault();
}
public static void RemoveAllByKeyword(this DbSet<Quote> quotes, ulong guildId, string keyword)
{
quotes.RemoveRange(quotes.AsQueryable().Where(x => x.GuildId == guildId && x.Keyword.ToUpper() == keyword));
}
.OrderBy(q => rngk.Next())
.FirstOrDefault();
}
}
public static void RemoveAllByKeyword(this DbSet<Quote> quotes, ulong guildId, string keyword)
{
quotes.RemoveRange(quotes.AsQueryable().Where(x => x.GuildId == guildId && x.Keyword.ToUpper() == keyword));
}
}

View File

@@ -1,29 +1,26 @@
using NadekoBot.Services.Database.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class ReminderExtensions
{
public static class ReminderExtensions
{
public static IEnumerable<Reminder> GetIncludedReminders(this DbSet<Reminder> reminders, IEnumerable<ulong> guildIds)
=> reminders.AsQueryable()
.Where(x => guildIds.Contains(x.ServerId) || x.ServerId == 0)
.ToList();
public static IEnumerable<Reminder> GetIncludedReminders(this DbSet<Reminder> reminders, IEnumerable<ulong> guildIds)
=> reminders.AsQueryable()
.Where(x => guildIds.Contains(x.ServerId) || x.ServerId == 0)
.ToList();
public static IEnumerable<Reminder> RemindersFor(this DbSet<Reminder> reminders, ulong userId, int page)
=> reminders.AsQueryable()
.Where(x => x.UserId == userId)
.OrderBy(x => x.DateAdded)
.Skip(page * 10)
.Take(10);
public static IEnumerable<Reminder> RemindersFor(this DbSet<Reminder> reminders, ulong userId, int page)
=> reminders.AsQueryable()
.Where(x => x.UserId == userId)
.OrderBy(x => x.DateAdded)
.Skip(page * 10)
.Take(10);
public static IEnumerable<Reminder> RemindersForServer(this DbSet<Reminder> reminders, ulong serverId, int page)
=> reminders.AsQueryable()
.Where(x => x.ServerId == serverId)
.OrderBy(x => x.DateAdded)
.Skip(page * 10)
.Take(10);
}
}
public static IEnumerable<Reminder> RemindersForServer(this DbSet<Reminder> reminders, ulong serverId, int page)
=> reminders.AsQueryable()
.Where(x => x.ServerId == serverId)
.OrderBy(x => x.DateAdded)
.Skip(page * 10)
.Take(10);
}

View File

@@ -1,26 +1,23 @@
using NadekoBot.Services.Database.Models;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class SelfAssignableRolesExtensions
{
public static class SelfAssignableRolesExtensions
public static bool DeleteByGuildAndRoleId(this DbSet<SelfAssignedRole> roles, ulong guildId, ulong roleId)
{
public static bool DeleteByGuildAndRoleId(this DbSet<SelfAssignedRole> roles, ulong guildId, ulong roleId)
{
var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId);
var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId);
if (role is null)
return false;
if (role is null)
return false;
roles.Remove(role);
return true;
}
public static IEnumerable<SelfAssignedRole> GetFromGuild(this DbSet<SelfAssignedRole> roles, ulong guildId)
=> roles.AsQueryable()
.Where(s => s.GuildId == guildId)
.ToArray();
roles.Remove(role);
return true;
}
}
public static IEnumerable<SelfAssignedRole> GetFromGuild(this DbSet<SelfAssignedRole> roles, ulong guildId)
=> roles.AsQueryable()
.Where(s => s.GuildId == guildId)
.ToArray();
}

View File

@@ -1,84 +1,81 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using LinqToDB;
using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class UserXpExtensions
{
public static class UserXpExtensions
public static UserXpStats GetOrCreateUserXpStats(this NadekoContext ctx, ulong guildId, ulong userId)
{
public static UserXpStats GetOrCreateUserXpStats(this NadekoContext ctx, ulong guildId, ulong userId)
{
var usr = ctx.UserXpStats.FirstOrDefault(x => x.UserId == userId && x.GuildId == guildId);
var usr = ctx.UserXpStats.FirstOrDefault(x => x.UserId == userId && x.GuildId == guildId);
if (usr is null)
if (usr is null)
{
ctx.Add(usr = new UserXpStats()
{
ctx.Add(usr = new UserXpStats()
{
Xp = 0,
UserId = userId,
NotifyOnLevelUp = XpNotificationLocation.None,
GuildId = guildId,
});
}
return usr;
Xp = 0,
UserId = userId,
NotifyOnLevelUp = XpNotificationLocation.None,
GuildId = guildId,
});
}
public static List<UserXpStats> GetUsersFor(this DbSet<UserXpStats> xps, ulong guildId, int page)
{
return xps
.AsQueryable()
.AsNoTracking()
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9)
.Take(9)
.ToList();
}
public static List<UserXpStats> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
{
return xps
.AsQueryable()
.AsNoTracking()
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Take(count)
.ToList();
}
public static int GetUserGuildRanking(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
{
// @"SELECT COUNT(*) + 1
//FROM UserXpStats
//WHERE GuildId = @p1 AND ((Xp + AwardedXp) > (SELECT Xp + AwardedXp
// FROM UserXpStats
// WHERE UserId = @p2 AND GuildId = @p1
// LIMIT 1));";
return 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() + 1;
}
public static void ResetGuildUserXp(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
{
xps.Delete(x => x.UserId == userId && x.GuildId == guildId);
}
public static void ResetGuildXp(this DbSet<UserXpStats> xps, ulong guildId)
{
xps.Delete(x => x.GuildId == guildId);
}
return usr;
}
}
public static List<UserXpStats> GetUsersFor(this DbSet<UserXpStats> xps, ulong guildId, int page)
{
return xps
.AsQueryable()
.AsNoTracking()
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9)
.Take(9)
.ToList();
}
public static List<UserXpStats> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
{
return xps
.AsQueryable()
.AsNoTracking()
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Take(count)
.ToList();
}
public static int GetUserGuildRanking(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
{
// @"SELECT COUNT(*) + 1
//FROM UserXpStats
//WHERE GuildId = @p1 AND ((Xp + AwardedXp) > (SELECT Xp + AwardedXp
// FROM UserXpStats
// WHERE UserId = @p2 AND GuildId = @p1
// LIMIT 1));";
return 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() + 1;
}
public static void ResetGuildUserXp(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
{
xps.Delete(x => x.UserId == userId && x.GuildId == guildId);
}
public static void ResetGuildXp(this DbSet<UserXpStats> xps, ulong guildId)
{
xps.Delete(x => x.GuildId == guildId);
}
}

View File

@@ -1,164 +1,160 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Db
{
public class WaifuInfoStats
{
public string FullName { get; set; }
public int Price { get; set; }
public string ClaimerName { get; set; }
public string AffinityName { get; set; }
public int AffinityCount { get; set; }
public int DivorceCount { get; set; }
public int ClaimCount { get; set; }
public List<WaifuItem> Items { get; set; }
public List<string> Claims { get; set; }
public List<string> Fans { get; set; }
}
public static class WaifuExtensions
{
public static WaifuInfo ByWaifuUserId(this DbSet<WaifuInfo> waifus, ulong userId, Func<DbSet<WaifuInfo>, IQueryable<WaifuInfo>> includes = null)
{
if (includes is null)
{
return waifus.Include(wi => wi.Waifu)
.Include(wi => wi.Affinity)
.Include(wi => wi.Claimer)
.Include(wi => wi.Items)
.FirstOrDefault(wi => wi.Waifu.UserId == userId);
}
namespace NadekoBot.Db;
return includes(waifus)
.AsQueryable()
public class WaifuInfoStats
{
public string FullName { get; set; }
public int Price { get; set; }
public string ClaimerName { get; set; }
public string AffinityName { get; set; }
public int AffinityCount { get; set; }
public int DivorceCount { get; set; }
public int ClaimCount { get; set; }
public List<WaifuItem> Items { get; set; }
public List<string> Claims { get; set; }
public List<string> Fans { get; set; }
}
public static class WaifuExtensions
{
public static WaifuInfo ByWaifuUserId(this DbSet<WaifuInfo> waifus, ulong userId, Func<DbSet<WaifuInfo>, IQueryable<WaifuInfo>> includes = null)
{
if (includes is null)
{
return waifus.Include(wi => wi.Waifu)
.Include(wi => wi.Affinity)
.Include(wi => wi.Claimer)
.Include(wi => wi.Items)
.FirstOrDefault(wi => wi.Waifu.UserId == userId);
}
public static IEnumerable<WaifuLbResult> GetTop(this DbSet<WaifuInfo> waifus, int count, int skip = 0)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (count == 0)
return new List<WaifuLbResult>();
return includes(waifus)
.AsQueryable()
.FirstOrDefault(wi => wi.Waifu.UserId == userId);
}
return waifus.Include(wi => wi.Waifu)
.Include(wi => wi.Affinity)
.Include(wi => wi.Claimer)
.OrderByDescending(wi => wi.Price)
.Skip(skip)
.Take(count)
.Select(x => new WaifuLbResult
{
Affinity = x.Affinity == null ? null : x.Affinity.Username,
AffinityDiscrim = x.Affinity == null ? null : x.Affinity.Discriminator,
Claimer = x.Claimer == null ? null : x.Claimer.Username,
ClaimerDiscrim = x.Claimer == null ? null : x.Claimer.Discriminator,
Username = x.Waifu.Username,
Discrim = x.Waifu.Discriminator,
Price = x.Price,
})
.ToList();
public static IEnumerable<WaifuLbResult> GetTop(this DbSet<WaifuInfo> waifus, int count, int skip = 0)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (count == 0)
return new List<WaifuLbResult>();
}
return waifus.Include(wi => wi.Waifu)
.Include(wi => wi.Affinity)
.Include(wi => wi.Claimer)
.OrderByDescending(wi => wi.Price)
.Skip(skip)
.Take(count)
.Select(x => new WaifuLbResult
{
Affinity = x.Affinity == null ? null : x.Affinity.Username,
AffinityDiscrim = x.Affinity == null ? null : x.Affinity.Discriminator,
Claimer = x.Claimer == null ? null : x.Claimer.Username,
ClaimerDiscrim = x.Claimer == null ? null : x.Claimer.Discriminator,
Username = x.Waifu.Username,
Discrim = x.Waifu.Discriminator,
Price = x.Price,
})
.ToList();
public static decimal GetTotalValue(this DbSet<WaifuInfo> waifus)
{
return waifus
.AsQueryable()
.Where(x => x.ClaimerId != null)
.Sum(x => x.Price);
}
}
public static ulong GetWaifuUserId(this DbSet<WaifuInfo> waifus, ulong ownerId, string name)
{
return waifus
.AsQueryable()
.AsNoTracking()
.Where(x => x.Claimer.UserId == ownerId
&& x.Waifu.Username + "#" + x.Waifu.Discriminator == name)
.Select(x => x.Waifu.UserId)
.FirstOrDefault();
}
public static decimal GetTotalValue(this DbSet<WaifuInfo> waifus)
{
return waifus
.AsQueryable()
.Where(x => x.ClaimerId != null)
.Sum(x => x.Price);
}
public static ulong GetWaifuUserId(this DbSet<WaifuInfo> waifus, ulong ownerId, string name)
{
return waifus
.AsQueryable()
.AsNoTracking()
.Where(x => x.Claimer.UserId == ownerId
&& x.Waifu.Username + "#" + x.Waifu.Discriminator == name)
.Select(x => x.Waifu.UserId)
.FirstOrDefault();
}
public static WaifuInfoStats GetWaifuInfo(this NadekoContext ctx, ulong userId)
{
ctx.Database.ExecuteSqlInterpolated($@"
public static WaifuInfoStats GetWaifuInfo(this NadekoContext ctx, ulong userId)
{
ctx.Database.ExecuteSqlInterpolated($@"
INSERT OR IGNORE INTO WaifuInfo (AffinityId, ClaimerId, Price, WaifuId)
VALUES ({null}, {null}, {1}, (SELECT Id FROM DiscordUser WHERE UserId={userId}));");
var toReturn = ctx.WaifuInfo
var toReturn = ctx.WaifuInfo
.AsQueryable()
.Where(w => w.WaifuId == ctx.Set<DiscordUser>()
.AsQueryable()
.Where(w => w.WaifuId == ctx.Set<DiscordUser>()
.Where(u => u.UserId == userId)
.Select(u => u.Id).FirstOrDefault())
.Select(w => new WaifuInfoStats
{
FullName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.UserId == userId)
.Select(u => u.Id).FirstOrDefault())
.Select(w => new WaifuInfoStats
{
FullName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.UserId == userId)
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
AffinityCount = ctx.Set<WaifuUpdate>()
.AsQueryable()
.Count(x => x.UserId == w.WaifuId &&
x.UpdateType == WaifuUpdateType.AffinityChanged &&
x.NewId != null),
AffinityCount = ctx.Set<WaifuUpdate>()
.AsQueryable()
.Count(x => x.UserId == w.WaifuId &&
x.UpdateType == WaifuUpdateType.AffinityChanged &&
x.NewId != null),
AffinityName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.Id == w.AffinityId)
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
AffinityName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.Id == w.AffinityId)
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
ClaimCount = ctx.WaifuInfo
.AsQueryable()
.Count(x => x.ClaimerId == w.WaifuId),
ClaimCount = ctx.WaifuInfo
.AsQueryable()
.Count(x => x.ClaimerId == w.WaifuId),
ClaimerName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.Id == w.ClaimerId)
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
ClaimerName = ctx.Set<DiscordUser>()
.AsQueryable()
.Where(u => u.Id == w.ClaimerId)
.Select(u => u.Username + "#" + u.Discriminator)
.FirstOrDefault(),
DivorceCount = ctx
.Set<WaifuUpdate>()
.AsQueryable()
.Count(x => x.OldId == w.WaifuId &&
x.NewId == null &&
x.UpdateType == WaifuUpdateType.Claimed),
DivorceCount = ctx
.Set<WaifuUpdate>()
.AsQueryable()
.Count(x => x.OldId == w.WaifuId &&
x.NewId == null &&
x.UpdateType == WaifuUpdateType.Claimed),
Price = w.Price,
Price = w.Price,
Claims = ctx.WaifuInfo
.AsQueryable()
.Include(x => x.Waifu)
.Where(x => x.ClaimerId == w.WaifuId)
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
.ToList(),
Claims = ctx.WaifuInfo
.AsQueryable()
.Include(x => x.Waifu)
.Where(x => x.ClaimerId == w.WaifuId)
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
.ToList(),
Fans = ctx.WaifuInfo
.AsQueryable()
.Include(x => x.Waifu)
.Where(x => x.AffinityId == w.WaifuId)
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
.ToList(),
Fans = ctx.WaifuInfo
.AsQueryable()
.Include(x => x.Waifu)
.Where(x => x.AffinityId == w.WaifuId)
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
.ToList(),
Items = w.Items,
})
Items = w.Items,
})
.FirstOrDefault();
if (toReturn is null)
return null;
if (toReturn is null)
return null;
return toReturn;
}
return toReturn;
}
}

View File

@@ -1,56 +1,53 @@
using NadekoBot.Services.Database.Models;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace NadekoBot.Db
namespace NadekoBot.Db;
public static class WarningExtensions
{
public static class WarningExtensions
public static Warning[] ForId(this DbSet<Warning> warnings, ulong guildId, ulong userId)
{
public static Warning[] ForId(this DbSet<Warning> warnings, ulong guildId, ulong userId)
{
var query = warnings.AsQueryable()
.Where(x => x.GuildId == guildId && x.UserId == userId)
.OrderByDescending(x => x.DateAdded);
var query = warnings.AsQueryable()
.Where(x => x.GuildId == guildId && x.UserId == userId)
.OrderByDescending(x => x.DateAdded);
return query.ToArray();
}
public static bool Forgive(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod, int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
var warn = warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(index)
.FirstOrDefault();
if (warn is null || warn.Forgiven)
return false;
warn.Forgiven = true;
warn.ForgivenBy = mod;
return true;
}
public static async Task ForgiveAll(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod)
{
await warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
.ForEachAsync(x =>
{
if (x.Forgiven != true)
{
x.Forgiven = true;
x.ForgivenBy = mod;
}
});
}
public static Warning[] GetForGuild(this DbSet<Warning> warnings, ulong id)
{
return warnings.AsQueryable().Where(x => x.GuildId == id).ToArray();
}
return query.ToArray();
}
}
public static bool Forgive(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod, int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
var warn = warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(index)
.FirstOrDefault();
if (warn is null || warn.Forgiven)
return false;
warn.Forgiven = true;
warn.ForgivenBy = mod;
return true;
}
public static async Task ForgiveAll(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod)
{
await warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
.ForEachAsync(x =>
{
if (x.Forgiven != true)
{
x.Forgiven = true;
x.ForgivenBy = mod;
}
});
}
public static Warning[] GetForGuild(this DbSet<Warning> warnings, ulong id)
{
return warnings.AsQueryable().Where(x => x.GuildId == id).ToArray();
}
}

View File

@@ -1,68 +1,65 @@
using System;
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class AntiRaidSetting : DbEntity
{
public class AntiRaidSetting : DbEntity
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
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; }
public int UserThreshold { get; set; }
public int Seconds { get; set; }
public PunishmentAction Action { get; set; }
/// <summary>
/// Duration of the punishment, in minutes. This works only for supported Actions, like:
/// Mute, Chatmute, Voicemute, etc...
/// </summary>
public int PunishDuration { get; set; }
}
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; } = 0;
public ulong? RoleId { get; set; }
public HashSet<AntiSpamIgnore> IgnoredChannels { get; set; } = new HashSet<AntiSpamIgnore>();
}
public class AntiAltSetting
{
public int Id { get; set; }
public int GuildConfigId { get; set; }
public TimeSpan MinAge { get; set; }
public PunishmentAction Action { get; set; }
public int ActionDurationMinutes { get; set; }
public ulong? RoleId { get; set; }
}
public enum PunishmentAction
{
Mute,
Kick,
Ban,
Softban,
RemoveRoles,
ChatMute,
VoiceMute,
AddRole
}
public class AntiSpamIgnore : DbEntity
{
public ulong ChannelId { get; set; }
public override int GetHashCode() => ChannelId.GetHashCode();
public override bool Equals(object obj)
{
return obj is AntiSpamIgnore inst
? inst.ChannelId == ChannelId
: false;
}
}
/// <summary>
/// Duration of the punishment, in minutes. This works only for supported Actions, like:
/// Mute, Chatmute, Voicemute, etc...
/// </summary>
public int PunishDuration { get; set; }
}
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; } = 0;
public ulong? RoleId { get; set; }
public HashSet<AntiSpamIgnore> IgnoredChannels { get; set; } = new HashSet<AntiSpamIgnore>();
}
public class AntiAltSetting
{
public int Id { get; set; }
public int GuildConfigId { get; set; }
public TimeSpan MinAge { get; set; }
public PunishmentAction Action { get; set; }
public int ActionDurationMinutes { get; set; }
public ulong? RoleId { get; set; }
}
public enum PunishmentAction
{
Mute,
Kick,
Ban,
Softban,
RemoveRoles,
ChatMute,
VoiceMute,
AddRole
}
public class AntiSpamIgnore : DbEntity
{
public ulong ChannelId { get; set; }
public override int GetHashCode() => ChannelId.GetHashCode();
public override bool Equals(object obj)
{
return obj is AntiSpamIgnore inst
? inst.ChannelId == ChannelId
: false;
}
}

View File

@@ -1,14 +1,13 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class AutoCommand : DbEntity
{
public class AutoCommand : DbEntity
{
public string CommandText { get; set; }
public ulong ChannelId { get; set; }
public string ChannelName { get; set; }
public ulong? GuildId { get; set; }
public string GuildName { get; set; }
public ulong? VoiceChannelId {get; set; }
public string VoiceChannelName { get; set; }
public int Interval { get; set; }
}
public string CommandText { get; set; }
public ulong ChannelId { get; set; }
public string ChannelName { get; set; }
public ulong? GuildId { get; set; }
public string GuildName { get; set; }
public ulong? VoiceChannelId {get; set; }
public string VoiceChannelName { get; set; }
public int Interval { get; set; }
}

View File

@@ -1,12 +1,9 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class AutoTranslateChannel : DbEntity
{
public class AutoTranslateChannel : DbEntity
{
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public bool AutoDelete { get; set; }
public IList<AutoTranslateUser> Users { get; set; } = new List<AutoTranslateUser>();
}
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public bool AutoDelete { get; set; }
public IList<AutoTranslateUser> Users { get; set; } = new List<AutoTranslateUser>();
}

View File

@@ -1,11 +1,10 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class AutoTranslateUser : DbEntity
{
public class AutoTranslateUser : DbEntity
{
public int ChannelId { get; set; }
public AutoTranslateChannel Channel { get; set; }
public ulong UserId { get; set; }
public string Source { get; set; }
public string Target { get; set; }
}
public int ChannelId { get; set; }
public AutoTranslateChannel Channel { get; set; }
public ulong UserId { get; set; }
public string Source { get; set; }
public string Target { get; set; }
}

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class BanTemplate : DbEntity
{
public class BanTemplate : DbEntity
{
public ulong GuildId { get; set; }
public string Text { get; set; }
}
public ulong GuildId { get; set; }
public string Text { get; set; }
}

View File

@@ -1,18 +1,14 @@
using System;
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class BlacklistEntry : DbEntity
{
public class BlacklistEntry : DbEntity
{
public ulong ItemId { get; set; }
public BlacklistType Type { get; set; }
}
public ulong ItemId { get; set; }
public BlacklistType Type { get; set; }
}
public enum BlacklistType
{
Server,
Channel,
User
}
public enum BlacklistType
{
Server,
Channel,
User
}

View File

@@ -1,49 +1,47 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db.Models
namespace NadekoBot.Db.Models;
public class ClubInfo : DbEntity
{
public class ClubInfo : DbEntity
{
[MaxLength(20)]
public string Name { get; set; }
public int Discrim { get; set; }
[MaxLength(20)]
public string Name { get; set; }
public int Discrim { get; set; }
public string ImageUrl { get; set; } = "";
public int MinimumLevelReq { get; set; } = 5;
public int Xp { get; set; } = 0;
public string ImageUrl { get; set; } = "";
public int MinimumLevelReq { get; set; } = 5;
public int Xp { get; set; } = 0;
public int OwnerId { get; set; }
public DiscordUser Owner { get; set; }
public int OwnerId { get; set; }
public DiscordUser Owner { get; set; }
public List<DiscordUser> Users { get; set; } = new List<DiscordUser>();
public List<DiscordUser> Users { get; set; } = new List<DiscordUser>();
public List<ClubApplicants> Applicants { get; set; } = new List<ClubApplicants>();
public List<ClubBans> Bans { get; set; } = new List<ClubBans>();
public string Description { get; set; }
public List<ClubApplicants> Applicants { get; set; } = new List<ClubApplicants>();
public List<ClubBans> Bans { get; set; } = new List<ClubBans>();
public string Description { get; set; }
public override string ToString()
{
return Name + "#" + Discrim;
}
}
public class ClubApplicants
public override string ToString()
{
public int ClubId { get; set; }
public ClubInfo Club { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
}
public class ClubBans
{
public int ClubId { get; set; }
public ClubInfo Club { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
return Name + "#" + Discrim;
}
}
public class ClubApplicants
{
public int ClubId { get; set; }
public ClubInfo Club { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
}
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,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class CommandAlias : DbEntity
{
public class CommandAlias : DbEntity
{
public string Trigger { get; set; }
public string Mapping { get; set; }
}
}
public string Trigger { get; set; }
public string Mapping { get; set; }
}

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class CommandCooldown : DbEntity
{
public class CommandCooldown : DbEntity
{
public int Seconds { get; set; }
public string CommandName { get; set; }
}
}
public int Seconds { get; set; }
public string CommandName { get; set; }
}

View File

@@ -1,16 +1,15 @@
namespace NadekoBot.Services.Database.Models
{
public class CurrencyTransaction : DbEntity
{
public long Amount { get; set; }
public string Reason { get; set; }
public ulong UserId { get; set; }
namespace NadekoBot.Services.Database.Models;
public CurrencyTransaction Clone() => new CurrencyTransaction
{
Amount = Amount,
Reason = Reason,
UserId = UserId,
};
}
}
public class CurrencyTransaction : DbEntity
{
public long Amount { get; set; }
public string Reason { get; set; }
public ulong UserId { get; set; }
public CurrencyTransaction Clone() => new CurrencyTransaction
{
Amount = Amount,
Reason = Reason,
UserId = UserId,
};
}

View File

@@ -1,33 +1,27 @@
using Newtonsoft.Json;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.RegularExpressions;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class CustomReaction : DbEntity
{
public class CustomReaction : DbEntity
{
public ulong? GuildId { get; set; }
public string Response { get; set; }
public string Trigger { get; set; }
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 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(Reactions)
? Array.Empty<string>()
: Reactions.Split("@@@");
public string[] GetReactions() =>
string.IsNullOrWhiteSpace(Reactions)
? Array.Empty<string>()
: Reactions.Split("@@@");
public bool IsGlobal() => GuildId is null || GuildId == 0;
}
public class ReactionResponse : DbEntity
{
public bool OwnerOnly { get; set; }
public string Text { get; set; }
}
public bool IsGlobal() => GuildId is null || GuildId == 0;
}
public class ReactionResponse : DbEntity
{
public bool OwnerOnly { get; set; }
public string Text { get; set; }
}

View File

@@ -1,12 +1,10 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class DbEntity
{
public class DbEntity
{
[Key]
public int Id { get; set; }
public DateTime? DateAdded { get; set; } = DateTime.UtcNow;
}
}
[Key]
public int Id { get; set; }
public DateTime? DateAdded { get; set; } = DateTime.UtcNow;
}

View File

@@ -1,19 +1,18 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class DelMsgOnCmdChannel : DbEntity
{
public class DelMsgOnCmdChannel : DbEntity
public ulong ChannelId { get; set; }
public bool State { get; set; }
public override int GetHashCode()
{
public ulong ChannelId { get; set; }
public bool State { get; set; }
public override int GetHashCode()
{
return ChannelId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is DelMsgOnCmdChannel x
&& x.ChannelId == ChannelId;
}
return ChannelId.GetHashCode();
}
}
public override bool Equals(object obj)
{
return obj is DelMsgOnCmdChannel x
&& x.ChannelId == ChannelId;
}
}

View File

@@ -1,12 +1,11 @@
using Discord;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class DiscordPermOverride : DbEntity
{
public class DiscordPermOverride : DbEntity
{
public GuildPerm Perm { get; set; }
public GuildPerm Perm { get; set; }
public ulong? GuildId { get; set; }
public string Command { get; set; }
}
public ulong? GuildId { get; set; }
public string Command { get; set; }
}

View File

@@ -1,38 +1,36 @@
using System;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db.Models
namespace NadekoBot.Db.Models;
public class DiscordUser : DbEntity
{
public class DiscordUser : DbEntity
public ulong UserId { get; set; }
public string Username { get; set; }
public string Discriminator { get; set; }
public string AvatarId { get; set; }
public ClubInfo Club { get; set; }
public bool IsClubAdmin { get; set; }
public int TotalXp { get; set; }
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
public DateTime LastXpGain { get; set; } = DateTime.MinValue;
public XpNotificationLocation NotifyOnLevelUp { get; set; }
public long CurrencyAmount { get; set; }
public override bool Equals(object obj)
{
public ulong UserId { get; set; }
public string Username { get; set; }
public string Discriminator { get; set; }
public string AvatarId { get; set; }
public ClubInfo Club { get; set; }
public bool IsClubAdmin { get; set; }
public int TotalXp { get; set; }
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
public DateTime LastXpGain { get; set; } = DateTime.MinValue;
public XpNotificationLocation NotifyOnLevelUp { get; set; }
public long CurrencyAmount { get; set; }
public override bool Equals(object obj)
{
return obj is DiscordUser du
? du.UserId == UserId
: false;
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
public override string ToString() =>
Username + "#" + Discriminator;
return obj is DiscordUser du
? du.UserId == UserId
: false;
}
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
public override string ToString() =>
Username + "#" + Discriminator;
}

View File

@@ -1,47 +1,44 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class CurrencyEvent
{
public class CurrencyEvent
public enum Type
{
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; }
Reaction,
GameStatus,
//NotRaid,
}
public class AwardedUser
{
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,25 +1,22 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class FeedSub : DbEntity
{
public class FeedSub : DbEntity
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public string Url { get; set; }
public override int GetHashCode()
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public string Url { get; set; }
public override int GetHashCode()
{
return Url.GetHashCode(StringComparison.InvariantCulture) ^ GuildConfigId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is FeedSub s
&& s.Url.ToLower() == Url.ToLower()
&& s.GuildConfigId == GuildConfigId;
}
return Url.GetHashCode(StringComparison.InvariantCulture) ^ GuildConfigId.GetHashCode();
}
}
public override bool Equals(object obj)
{
return obj is FeedSub s
&& s.Url.ToLower() == Url.ToLower()
&& s.GuildConfigId == GuildConfigId;
}
}

View File

@@ -1,19 +1,18 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class FilterChannelId : DbEntity
{
public class FilterChannelId : DbEntity
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
return obj is FilterChannelId f
? f.ChannelId == ChannelId
: false;
}
public override int GetHashCode()
{
return ChannelId.GetHashCode();
}
return obj is FilterChannelId f
? f.ChannelId == ChannelId
: false;
}
}
public override int GetHashCode()
{
return ChannelId.GetHashCode();
}
}

View File

@@ -1,19 +1,18 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class FilterLinksChannelId : DbEntity
{
public class FilterLinksChannelId : DbEntity
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
return obj is FilterLinksChannelId f
? f.ChannelId == ChannelId
: false;
}
public override int GetHashCode()
{
return ChannelId.GetHashCode();
}
return obj is FilterLinksChannelId f
? f.ChannelId == ChannelId
: false;
}
}
public override int GetHashCode()
{
return ChannelId.GetHashCode();
}
}

View File

@@ -1,7 +1,6 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class FilteredWord : DbEntity
{
public class FilteredWord : DbEntity
{
public string Word { get; set; }
}
}
public string Word { get; set; }
}

View File

@@ -1,50 +1,48 @@
using System;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Models;
using NadekoBot.Modules.Searches.Common;
namespace NadekoBot.Db.Models
namespace NadekoBot.Db.Models;
public class FollowedStream : DbEntity
{
public class FollowedStream : DbEntity
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public string Username { get; set; }
public FType Type { get; set; }
public string Message { get; set; }
public enum FType
{
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public string Username { get; set; }
public FType Type { get; set; }
public string Message { get; set; }
public enum FType
{
Twitch = 0,
[Obsolete("No longer supported.")]
Smashcast = 1,
[Obsolete("No longer supported.")]
Mixer = 2,
Picarto = 3,
Youtube = 4,
Facebook = 5,
}
protected bool Equals(FollowedStream other)
{
return ChannelId == other.ChannelId
&& Username.Trim().ToUpperInvariant() == other.Username.Trim().ToUpperInvariant()
&& Type == other.Type;
}
public override int GetHashCode()
{
return HashCode.Combine(ChannelId, Username, (int) Type);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((FollowedStream) obj);
}
public StreamDataKey CreateKey() =>
new StreamDataKey(Type, Username.ToLower());
Twitch = 0,
[Obsolete("No longer supported.")]
Smashcast = 1,
[Obsolete("No longer supported.")]
Mixer = 2,
Picarto = 3,
Youtube = 4,
Facebook = 5,
}
protected bool Equals(FollowedStream other)
{
return ChannelId == other.ChannelId
&& Username.Trim().ToUpperInvariant() == other.Username.Trim().ToUpperInvariant()
&& Type == other.Type;
}
public override int GetHashCode()
{
return HashCode.Combine(ChannelId, Username, (int) Type);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((FollowedStream) obj);
}
public StreamDataKey CreateKey() =>
new StreamDataKey(Type, Username.ToLower());
}

View File

@@ -1,18 +1,17 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class GCChannelId : DbEntity
{
public class GCChannelId : DbEntity
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public override bool Equals(object obj)
{
return obj is GCChannelId gc
? gc.ChannelId == ChannelId
: false;
}
public override int GetHashCode() =>
this.ChannelId.GetHashCode();
return obj is GCChannelId gc
? gc.ChannelId == ChannelId
: false;
}
}
public override int GetHashCode() =>
this.ChannelId.GetHashCode();
}

View File

@@ -1,11 +1,10 @@
namespace NadekoBot.Services.Database.Models
{
public class GroupName : DbEntity
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
namespace NadekoBot.Services.Database.Models;
public int Number { get; set; }
public string Name { get; set; }
}
}
public class GroupName : DbEntity
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public int Number { get; set; }
public string Name { get; set; }
}

View File

@@ -1,109 +1,106 @@
using System;
using NadekoBot.Common.Collections;
using System.Collections.Generic;
using NadekoBot.Common.Collections;
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class GuildConfig : DbEntity
{
public class GuildConfig : DbEntity
{
public ulong GuildId { get; set; }
public ulong GuildId { get; set; }
public string Prefix { get; set; } = null;
public string Prefix { get; set; } = null;
public bool DeleteMessageOnCommand { get; set; }
public HashSet<DelMsgOnCmdChannel> DelMsgOnCmdChannels { get; set; } = new HashSet<DelMsgOnCmdChannel>();
public string AutoAssignRoleIds { get; set; }
//greet stuff
public bool AutoDeleteGreetMessages { get; set; } //unused
public bool AutoDeleteByeMessages { get; set; } // unused
public int AutoDeleteGreetMessagesTimer { get; set; } = 30;
public int AutoDeleteByeMessagesTimer { get; set; } = 30;
public bool DeleteMessageOnCommand { get; set; }
public HashSet<DelMsgOnCmdChannel> DelMsgOnCmdChannels { get; set; } = new HashSet<DelMsgOnCmdChannel>();
public string AutoAssignRoleIds { get; set; }
//greet stuff
public bool AutoDeleteGreetMessages { get; set; } //unused
public bool AutoDeleteByeMessages { get; set; } // unused
public int AutoDeleteGreetMessagesTimer { get; set; } = 30;
public int AutoDeleteByeMessagesTimer { get; set; } = 30;
public ulong GreetMessageChannelId { get; set; }
public ulong ByeMessageChannelId { get; set; }
public ulong GreetMessageChannelId { get; set; }
public ulong ByeMessageChannelId { get; set; }
public bool SendDmGreetMessage { get; set; }
public string DmGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
public bool SendDmGreetMessage { get; set; }
public string DmGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
public bool SendChannelGreetMessage { get; set; }
public string ChannelGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
public bool SendChannelGreetMessage { get; set; }
public string ChannelGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
#region Boost Message
#region Boost Message
public bool SendBoostMessage { get; set; }
public string BoostMessage { get; set; } = "%user% just boosted this server!";
public ulong BoostMessageChannelId { get; set; }
public int BoostMessageDeleteAfter { get; set; }
public bool SendBoostMessage { get; set; }
public string BoostMessage { get; set; } = "%user% just boosted this server!";
public ulong BoostMessageChannelId { get; set; }
public int BoostMessageDeleteAfter { get; set; }
#endregion
#endregion
public bool SendChannelByeMessage { get; set; }
public string ChannelByeMessageText { get; set; } = "%user% has left!";
public bool SendChannelByeMessage { get; set; }
public string ChannelByeMessageText { get; set; } = "%user% has left!";
//self assignable roles
public bool ExclusiveSelfAssignedRoles { get; set; }
public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
//self assignable roles
public bool ExclusiveSelfAssignedRoles { get; set; }
public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
//stream notifications
public HashSet<FollowedStream> FollowedStreams { get; set; } = new HashSet<FollowedStream>();
//stream notifications
public HashSet<FollowedStream> FollowedStreams { get; set; } = new HashSet<FollowedStream>();
//currencyGeneration
public HashSet<GCChannelId> GenerateCurrencyChannelIds { get; set; } = new HashSet<GCChannelId>();
//currencyGeneration
public HashSet<GCChannelId> GenerateCurrencyChannelIds { get; set; } = new HashSet<GCChannelId>();
public List<Permissionv2> Permissions { get; set; }
public bool VerbosePermissions { get; set; } = true;
public string PermissionRole { get; set; } = null;
public List<Permissionv2> Permissions { get; set; }
public bool VerbosePermissions { get; set; } = true;
public string PermissionRole { get; set; } = null;
public HashSet<CommandCooldown> CommandCooldowns { get; set; } = new HashSet<CommandCooldown>();
public HashSet<CommandCooldown> CommandCooldowns { get; set; } = new HashSet<CommandCooldown>();
//filtering
public bool FilterInvites { get; set; }
public bool FilterLinks { get; set; }
public HashSet<FilterChannelId> FilterInvitesChannelIds { get; set; } = new HashSet<FilterChannelId>();
public HashSet<FilterLinksChannelId> FilterLinksChannelIds { get; set; } = new HashSet<FilterLinksChannelId>();
//filtering
public bool FilterInvites { get; set; }
public bool FilterLinks { get; set; }
public HashSet<FilterChannelId> FilterInvitesChannelIds { get; set; } = new HashSet<FilterChannelId>();
public HashSet<FilterLinksChannelId> FilterLinksChannelIds { get; set; } = new HashSet<FilterLinksChannelId>();
//public bool FilterLinks { get; set; }
//public HashSet<FilterLinksChannelId> FilterLinksChannels { get; set; } = new HashSet<FilterLinksChannelId>();
//public bool FilterLinks { get; set; }
//public HashSet<FilterLinksChannelId> FilterLinksChannels { get; set; } = new HashSet<FilterLinksChannelId>();
public bool FilterWords { get; set; }
public HashSet<FilteredWord> FilteredWords { get; set; } = new HashSet<FilteredWord>();
public HashSet<FilterChannelId> FilterWordsChannelIds { get; set; } = new HashSet<FilterChannelId>();
public bool FilterWords { get; set; }
public HashSet<FilteredWord> FilteredWords { get; set; } = new HashSet<FilteredWord>();
public HashSet<FilterChannelId> FilterWordsChannelIds { get; set; } = new HashSet<FilterChannelId>();
public HashSet<MutedUserId> MutedUsers { get; set; } = new HashSet<MutedUserId>();
public HashSet<MutedUserId> MutedUsers { get; set; } = new HashSet<MutedUserId>();
public string MuteRoleName { get; set; }
public bool CleverbotEnabled { get; set; }
public string MuteRoleName { get; set; }
public bool CleverbotEnabled { get; set; }
public AntiRaidSetting AntiRaidSetting { get; set; }
public AntiSpamSetting AntiSpamSetting { get; set; }
public AntiAltSetting AntiAltSetting { get; set; }
public AntiRaidSetting AntiRaidSetting { get; set; }
public AntiSpamSetting AntiSpamSetting { get; set; }
public AntiAltSetting AntiAltSetting { get; set; }
public string Locale { get; set; } = null;
public string TimeZoneId { get; set; } = null;
public string Locale { get; set; } = null;
public string TimeZoneId { get; set; } = null;
public HashSet<UnmuteTimer> UnmuteTimers { get; set; } = new HashSet<UnmuteTimer>();
public HashSet<UnbanTimer> UnbanTimer { get; set; } = new HashSet<UnbanTimer>();
public HashSet<UnroleTimer> UnroleTimer { get; set; } = new HashSet<UnroleTimer>();
public HashSet<VcRoleInfo> VcRoleInfos { get; set; }
public HashSet<CommandAlias> CommandAliases { get; set; } = new HashSet<CommandAlias>();
public List<WarningPunishment> WarnPunishments { get; set; } = new List<WarningPunishment>();
public bool WarningsInitialized { get; set; }
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
public HashSet<UnmuteTimer> UnmuteTimers { get; set; } = new HashSet<UnmuteTimer>();
public HashSet<UnbanTimer> UnbanTimer { get; set; } = new HashSet<UnbanTimer>();
public HashSet<UnroleTimer> UnroleTimer { get; set; } = new HashSet<UnroleTimer>();
public HashSet<VcRoleInfo> VcRoleInfos { get; set; }
public HashSet<CommandAlias> CommandAliases { get; set; } = new HashSet<CommandAlias>();
public List<WarningPunishment> WarnPunishments { get; set; } = new List<WarningPunishment>();
public bool WarningsInitialized { get; set; }
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
public List<ShopEntry> ShopEntries { get; set; }
public ulong? GameVoiceChannel { get; set; } = null;
public bool VerboseErrors { get; set; } = false;
public List<ShopEntry> ShopEntries { get; set; }
public ulong? GameVoiceChannel { get; set; } = null;
public bool VerboseErrors { get; set; } = false;
public StreamRoleSettings StreamRole { get; set; }
public StreamRoleSettings StreamRole { get; set; }
public XpSettings XpSettings { get; set; }
public List<FeedSub> FeedSubs { get; set; } = new List<FeedSub>();
public IndexedCollection<ReactionRoleMessage> ReactionRoleMessages { get; set; } = new IndexedCollection<ReactionRoleMessage>();
public bool NotifyStreamOffline { get; set; }
public List<GroupName> SelfAssignableRoleGroupNames { get; set; }
public int WarnExpireHours { get; set; } = 0;
public WarnExpireAction WarnExpireAction { get; set; } = WarnExpireAction.Clear;
}
}
public XpSettings XpSettings { get; set; }
public List<FeedSub> FeedSubs { get; set; } = new List<FeedSub>();
public IndexedCollection<ReactionRoleMessage> ReactionRoleMessages { get; set; } = new IndexedCollection<ReactionRoleMessage>();
public bool NotifyStreamOffline { get; set; }
public List<GroupName> SelfAssignableRoleGroupNames { get; set; }
public int WarnExpireHours { get; set; } = 0;
public WarnExpireAction WarnExpireAction { get; set; } = WarnExpireAction.Clear;
}

View File

@@ -1,16 +1,15 @@
namespace NadekoBot.Services.Database.Models
{
public class IgnoredLogItem : DbEntity
{
public int LogSettingId { get; set; }
public LogSetting LogSetting { get; set; }
public ulong LogItemId { get; set; }
public IgnoredItemType ItemType { get; set; }
}
namespace NadekoBot.Services.Database.Models;
public enum IgnoredItemType
{
Channel,
User,
}
public class IgnoredLogItem : DbEntity
{
public int LogSettingId { get; set; }
public LogSetting LogSetting { get; set; }
public ulong LogItemId { get; set; }
public IgnoredItemType ItemType { get; set; }
}
public enum IgnoredItemType
{
Channel,
User,
}

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class IgnoredVoicePresenceChannel : DbEntity
{
public class IgnoredVoicePresenceChannel : DbEntity
{
public LogSetting LogSetting { get; set; }
public ulong ChannelId { get; set; }
}
}
public LogSetting LogSetting { get; set; }
public ulong ChannelId { get; set; }
}

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class ImageOnlyChannel : DbEntity
{
public class ImageOnlyChannel : DbEntity
{
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
}
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
}

View File

@@ -1,34 +1,31 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class LogSetting : DbEntity
{
public class LogSetting : DbEntity
{
public List<IgnoredLogItem> LogIgnores { get; set; } = new List<IgnoredLogItem>();
public List<IgnoredLogItem> LogIgnores { get; set; } = new List<IgnoredLogItem>();
public ulong GuildId { get; set; }
public ulong? LogOtherId { get; set; }
public ulong? MessageUpdatedId { get; set; }
public ulong? MessageDeletedId { get; set; }
public ulong GuildId { get; set; }
public ulong? LogOtherId { get; set; }
public ulong? MessageUpdatedId { get; set; }
public ulong? MessageDeletedId { get; set; }
public ulong? UserJoinedId { get; set; }
public ulong? UserLeftId { get; set; }
public ulong? UserBannedId { get; set; }
public ulong? UserUnbannedId { get; set; }
public ulong? UserUpdatedId { get; set; }
public ulong? UserJoinedId { get; set; }
public ulong? UserLeftId { get; set; }
public ulong? UserBannedId { get; set; }
public ulong? UserUnbannedId { get; set; }
public ulong? UserUpdatedId { get; set; }
public ulong? ChannelCreatedId { get; set; }
public ulong? ChannelDestroyedId { get; set; }
public ulong? ChannelUpdatedId { get; set; }
public ulong? ChannelCreatedId { get; set; }
public ulong? ChannelDestroyedId { get; set; }
public ulong? ChannelUpdatedId { get; set; }
public ulong? UserMutedId { get; set; }
public ulong? UserMutedId { get; set; }
//userpresence
public ulong? LogUserPresenceId { get; set; }
//userpresence
public ulong? LogUserPresenceId { get; set; }
//voicepresence
//voicepresence
public ulong? LogVoicePresenceId { get; set; }
public ulong? LogVoicePresenceTTSId { get; set; }
}
}
public ulong? LogVoicePresenceId { get; set; }
public ulong? LogVoicePresenceTTSId { get; set; }
}

View File

@@ -1,12 +1,9 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class MusicPlaylist : DbEntity
{
public class MusicPlaylist : DbEntity
{
public string Name { get; set; }
public string Author { get; set; }
public ulong AuthorId { get; set; }
public List<PlaylistSong> Songs { get; set; } = new List<PlaylistSong>();
}
}
public string Name { get; set; }
public string Author { get; set; }
public ulong AuthorId { get; set; }
public List<PlaylistSong> Songs { get; set; } = new List<PlaylistSong>();
}

View File

@@ -1,56 +1,55 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class MusicPlayerSettings
{
public class MusicPlayerSettings
{
/// <summary>
/// Auto generated Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// Auto generated Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// Id of the guild
/// </summary>
public ulong GuildId { get; set; }
/// <summary>
/// Id of the guild
/// </summary>
public ulong GuildId { get; set; }
/// <summary>
/// Queue repeat type
/// </summary>
public PlayerRepeatType PlayerRepeat { get; set; } = PlayerRepeatType.Queue;
/// <summary>
/// Queue repeat type
/// </summary>
public PlayerRepeatType PlayerRepeat { get; set; } = PlayerRepeatType.Queue;
/// <summary>
/// Channel id the bot will always try to send track related messages to
/// </summary>
public ulong? MusicChannelId { get; set; } = null;
/// <summary>
/// Channel id the bot will always try to send track related messages to
/// </summary>
public ulong? MusicChannelId { get; set; } = null;
/// <summary>
/// Default volume player will be created with
/// </summary>
public int Volume { get; set; } = 100;
/// <summary>
/// Default volume player will be created with
/// </summary>
public int Volume { get; set; } = 100;
/// <summary>
/// Whether the bot should auto disconnect from the voice channel once the queue is done
/// This only has effect if
/// </summary>
public bool AutoDisconnect { get; set; } = false;
/// <summary>
/// Whether the bot should auto disconnect from the voice channel once the queue is done
/// This only has effect if
/// </summary>
public bool AutoDisconnect { get; set; } = false;
/// <summary>
/// Selected quality preset for the music player
/// </summary>
public QualityPreset QualityPreset { get; set; }
}
public enum QualityPreset
{
Highest,
High,
Medium,
Low
}
public enum PlayerRepeatType
{
None,
Track,
Queue
}
/// <summary>
/// Selected quality preset for the music player
/// </summary>
public QualityPreset QualityPreset { get; set; }
}
public enum QualityPreset
{
Highest,
High,
Medium,
Low
}
public enum PlayerRepeatType
{
None,
Track,
Queue
}

View File

@@ -1,19 +1,18 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class MutedUserId : DbEntity
{
public class MutedUserId : DbEntity
public ulong UserId { get; set; }
public override int GetHashCode()
{
public ulong UserId { get; set; }
public override int GetHashCode()
{
return UserId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is MutedUserId mui
? mui.UserId == UserId
: false;
}
return UserId.GetHashCode();
}
}
public override bool Equals(object obj)
{
return obj is MutedUserId mui
? mui.UserId == UserId
: false;
}
}

View File

@@ -1,16 +1,13 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class NsfwBlacklistedTag : DbEntity
{
public class NsfwBlacklistedTag : DbEntity
{
public ulong GuildId { get; set; }
public string Tag { get; set; }
public ulong GuildId { get; set; }
public string Tag { get; set; }
public override int GetHashCode()
=> Tag.GetHashCode(StringComparison.InvariantCulture);
public override int GetHashCode()
=> Tag.GetHashCode(StringComparison.InvariantCulture);
public override bool Equals(object obj)
=> obj is NsfwBlacklistedTag x && x.Tag == Tag;
}
}
public override bool Equals(object obj)
=> obj is NsfwBlacklistedTag x && x.Tag == Tag;
}

View File

@@ -1,60 +1,58 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public interface IIndexed
{
public interface IIndexed
{
int Index { get; set; }
}
[DebuggerDisplay("{PrimaryTarget}{SecondaryTarget} {SecondaryTargetName} {State} {PrimaryTargetId}")]
public class Permissionv2 : DbEntity, IIndexed
{
public int? GuildConfigId { get; set; }
public int Index { get; set; }
public PrimaryPermissionType PrimaryTarget { get; set; }
public ulong PrimaryTargetId { get; set; }
public SecondaryPermissionType SecondaryTarget { get; set; }
public string SecondaryTargetName { get; set; }
public bool IsCustomCommand { get; set; }
public bool State { get; set; }
[NotMapped]
public static Permissionv2 AllowAllPerm => new Permissionv2()
{
PrimaryTarget = PrimaryPermissionType.Server,
PrimaryTargetId = 0,
SecondaryTarget = SecondaryPermissionType.AllModules,
SecondaryTargetName = "*",
State = true,
Index = 0,
};
public static List<Permissionv2> GetDefaultPermlist =>
new List<Permissionv2>
{
AllowAllPerm
};
}
public enum PrimaryPermissionType
{
User,
Channel,
Role,
Server
}
public enum SecondaryPermissionType
{
Module,
Command,
AllModules
}
int Index { get; set; }
}
[DebuggerDisplay("{PrimaryTarget}{SecondaryTarget} {SecondaryTargetName} {State} {PrimaryTargetId}")]
public class Permissionv2 : DbEntity, IIndexed
{
public int? GuildConfigId { get; set; }
public int Index { get; set; }
public PrimaryPermissionType PrimaryTarget { get; set; }
public ulong PrimaryTargetId { get; set; }
public SecondaryPermissionType SecondaryTarget { get; set; }
public string SecondaryTargetName { get; set; }
public bool IsCustomCommand { get; set; }
public bool State { get; set; }
[NotMapped]
public static Permissionv2 AllowAllPerm => new Permissionv2()
{
PrimaryTarget = PrimaryPermissionType.Server,
PrimaryTargetId = 0,
SecondaryTarget = SecondaryPermissionType.AllModules,
SecondaryTargetName = "*",
State = true,
Index = 0,
};
public static List<Permissionv2> GetDefaultPermlist =>
new List<Permissionv2>
{
AllowAllPerm
};
}
public enum PrimaryPermissionType
{
User,
Channel,
Role,
Server
}
public enum SecondaryPermissionType
{
Module,
Command,
AllModules
}

View File

@@ -1,12 +1,11 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class PlantedCurrency : DbEntity
{
public class PlantedCurrency : DbEntity
{
public long Amount { get; set; }
public string Password { get; set; }
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public ulong UserId { get; set; }
public ulong MessageId { get; set; }
}
}
public long Amount { get; set; }
public string Password { get; set; }
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public ulong UserId { get; set; }
public ulong MessageId { get; set; }
}

View File

@@ -1,19 +1,18 @@
namespace NadekoBot.Services.Database.Models
{
public class PlaylistSong : DbEntity
{
public string Provider { get; set; }
public MusicType ProviderType { get; set; }
public string Title { get; set; }
public string Uri { get; set; }
public string Query { get; set; }
}
namespace NadekoBot.Services.Database.Models;
public enum MusicType
{
Radio,
YouTube,
Local,
Soundcloud
}
public class PlaylistSong : DbEntity
{
public string Provider { get; set; }
public MusicType ProviderType { get; set; }
public string Title { get; set; }
public string Uri { get; set; }
public string Query { get; set; }
}
public enum MusicType
{
Radio,
YouTube,
Local,
Soundcloud
}

View File

@@ -1,20 +1,18 @@
using NadekoBot.Common.Collections;
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class Poll : DbEntity
{
public class Poll : DbEntity
{
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public string Question { get; set; }
public IndexedCollection<PollAnswer> Answers { get; set; }
public HashSet<PollVote> Votes { get; set; } = new HashSet<PollVote>();
}
public class PollAnswer : DbEntity, IIndexed
{
public int Index { get; set; }
public string Text { get; set; }
}
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public string Question { get; set; }
public IndexedCollection<PollAnswer> Answers { get; set; }
public HashSet<PollVote> Votes { get; set; } = new HashSet<PollVote>();
}
public class PollAnswer : DbEntity, IIndexed
{
public int Index { get; set; }
public string Text { get; set; }
}

View File

@@ -1,20 +1,19 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class PollVote : DbEntity
{
public class PollVote : DbEntity
public ulong UserId { get; set; }
public int VoteIndex { get; set; }
public override int GetHashCode()
{
public ulong UserId { get; set; }
public int VoteIndex { get; set; }
public override int GetHashCode()
{
return UserId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is PollVote p
? p.UserId == UserId
: false;
}
return UserId.GetHashCode();
}
}
public override bool Equals(object obj)
{
return obj is PollVote p
? p.UserId == UserId
: false;
}
}

View File

@@ -1,23 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class Quote : DbEntity
{
public class Quote : DbEntity
{
public ulong GuildId { get; set; }
[Required]
public string Keyword { get; set; }
[Required]
public string AuthorName { get; set; }
public ulong AuthorId { get; set; }
[Required]
public string Text { get; set; }
}
public enum OrderType
{
Id = -1,
Keyword = -2
}
public ulong GuildId { get; set; }
[Required]
public string Keyword { get; set; }
[Required]
public string AuthorName { get; set; }
public ulong AuthorId { get; set; }
[Required]
public string Text { get; set; }
}
public enum OrderType
{
Id = -1,
Keyword = -2
}

View File

@@ -1,24 +1,21 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class ReactionRoleMessage : DbEntity, IIndexed
{
public class ReactionRoleMessage : DbEntity, IIndexed
{
public int Index { get; set; }
public int Index { get; set; }
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public ulong ChannelId { get; set; }
public ulong MessageId { get; set; }
public ulong ChannelId { get; set; }
public ulong MessageId { get; set; }
public List<ReactionRole> ReactionRoles { get; set; }
public bool Exclusive { get; set; }
}
public class ReactionRole : DbEntity
{
public string EmoteName { get; set; }
public ulong RoleId { get; set; }
}
public List<ReactionRole> ReactionRoles { get; set; }
public bool Exclusive { get; set; }
}
public class ReactionRole : DbEntity
{
public string EmoteName { get; set; }
public ulong RoleId { get; set; }
}

View File

@@ -1,14 +1,11 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class Reminder : DbEntity
{
public class Reminder : DbEntity
{
public DateTime When { get; set; }
public ulong ChannelId { get; set; }
public ulong ServerId { get; set; }
public ulong UserId { get; set; }
public string Message { get; set; }
public bool IsPrivate { get; set; }
}
}
public DateTime When { get; set; }
public ulong ChannelId { get; set; }
public ulong ServerId { get; set; }
public ulong UserId { get; set; }
public string Message { get; set; }
public bool IsPrivate { get; set; }
}

View File

@@ -1,17 +1,14 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class Repeater
{
public class Repeater
{
public int Id { get; set; }
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public ulong? LastMessageId { get; set; }
public string Message { get; set; }
public TimeSpan Interval { get; set; }
public TimeSpan? StartTimeOfDay { get; set; }
public bool NoRedundant { get; set; }
public DateTime DateAdded { get; set; }
}
}
public int Id { get; set; }
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public ulong? LastMessageId { get; set; }
public string Message { get; set; }
public TimeSpan Interval { get; set; }
public TimeSpan? StartTimeOfDay { get; set; }
public bool NoRedundant { get; set; }
public DateTime DateAdded { get; set; }
}

View File

@@ -1,12 +1,9 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class RewardedUser : DbEntity
{
public class RewardedUser : DbEntity
{
public ulong UserId { get; set; }
public string PatreonUserId { get; set; }
public int AmountRewardedThisMonth { get; set; }
public DateTime LastReward { get; set; }
}
}
public ulong UserId { get; set; }
public string PatreonUserId { get; set; }
public int AmountRewardedThisMonth { get; set; }
public DateTime LastReward { get; set; }
}

View File

@@ -1,10 +1,9 @@
using Discord;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class RotatingPlayingStatus : DbEntity
{
public class RotatingPlayingStatus : DbEntity
{
public string Status { get; set; }
public ActivityType Type { get; set; }
}
public string Status { get; set; }
public ActivityType Type { get; set; }
}

View File

@@ -1,11 +1,10 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class SelfAssignedRole : DbEntity
{
public class SelfAssignedRole : DbEntity
{
public ulong GuildId { get; set; }
public ulong RoleId { get; set; }
public ulong GuildId { get; set; }
public ulong RoleId { get; set; }
public int Group { get; set; }
public int LevelRequirement { get; set; }
}
}
public int Group { get; set; }
public int LevelRequirement { get; set; }
}

View File

@@ -1,46 +1,42 @@
using System;
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public enum ShopEntryType
{
public enum ShopEntryType
{
Role,
List,
//Infinite_List,
}
public class ShopEntry : DbEntity, IIndexed
{
public int Index { get; set; }
public int Price { get; set; }
public string Name { get; set; }
public ulong AuthorId { get; set; }
public ShopEntryType Type { get; set; }
//role
public string RoleName { get; set; }
public ulong RoleId { get; set; }
//list
public HashSet<ShopEntryItem> Items { get; set; } = new HashSet<ShopEntryItem>();
}
public class ShopEntryItem : DbEntity
{
public string Text { get; set; }
public override bool Equals(object obj)
{
if (obj is null || GetType() != obj.GetType())
{
return false;
}
return ((ShopEntryItem)obj).Text == Text;
}
public override int GetHashCode() =>
Text.GetHashCode(StringComparison.InvariantCulture);
}
Role,
List,
//Infinite_List,
}
public class ShopEntry : DbEntity, IIndexed
{
public int Index { get; set; }
public int Price { get; set; }
public string Name { get; set; }
public ulong AuthorId { get; set; }
public ShopEntryType Type { get; set; }
//role
public string RoleName { get; set; }
public ulong RoleId { get; set; }
//list
public HashSet<ShopEntryItem> Items { get; set; } = new HashSet<ShopEntryItem>();
}
public class ShopEntryItem : DbEntity
{
public string Text { get; set; }
public override bool Equals(object obj)
{
if (obj is null || GetType() != obj.GetType())
{
return false;
}
return ((ShopEntryItem)obj).Text == Text;
}
public override int GetHashCode() =>
Text.GetHashCode(StringComparison.InvariantCulture);
}

View File

@@ -1,24 +1,23 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class SlowmodeIgnoredRole : DbEntity
{
public class SlowmodeIgnoredRole : DbEntity
public ulong RoleId { get; set; }
// override object.Equals
public override bool Equals(object obj)
{
public ulong RoleId { get; set; }
// override object.Equals
public override bool Equals(object obj)
if (obj is null || GetType() != obj.GetType())
{
if (obj is null || GetType() != obj.GetType())
{
return false;
}
return ((SlowmodeIgnoredRole)obj).RoleId == RoleId;
return false;
}
// override object.GetHashCode
public override int GetHashCode()
{
return RoleId.GetHashCode();
}
return ((SlowmodeIgnoredRole)obj).RoleId == RoleId;
}
}
// override object.GetHashCode
public override int GetHashCode()
{
return RoleId.GetHashCode();
}
}

View File

@@ -1,24 +1,23 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class SlowmodeIgnoredUser : DbEntity
{
public class SlowmodeIgnoredUser : DbEntity
public ulong UserId { get; set; }
// override object.Equals
public override bool Equals(object obj)
{
public ulong UserId { get; set; }
// override object.Equals
public override bool Equals(object obj)
if (obj is null || GetType() != obj.GetType())
{
if (obj is null || GetType() != obj.GetType())
{
return false;
}
return ((SlowmodeIgnoredUser)obj).UserId == UserId;
return false;
}
// override object.GetHashCode
public override int GetHashCode()
{
return UserId.GetHashCode();
}
return ((SlowmodeIgnoredUser)obj).UserId == UserId;
}
}
// override object.GetHashCode
public override int GetHashCode()
{
return UserId.GetHashCode();
}
}

View File

@@ -1,78 +1,75 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class StreamRoleSettings : DbEntity
{
public class StreamRoleSettings : DbEntity
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
/// <summary>
/// Whether the feature is enabled in the guild.
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// Id of the role to give to the users in the role 'FromRole' when they start streaming
/// </summary>
public ulong AddRoleId { get; set; }
/// <summary>
/// Id of the role whose users are eligible to get the 'AddRole'
/// </summary>
public ulong FromRoleId { get; set; }
/// <summary>
/// If set, feature will only apply to users who have this keyword in their streaming status.
/// </summary>
public string Keyword { get; set; }
/// <summary>
/// A collection of whitelisted users' IDs. Whitelisted users don't require 'keyword' in
/// order to get the stream role.
/// </summary>
public HashSet<StreamRoleWhitelistedUser> Whitelist { get; set; } = new HashSet<StreamRoleWhitelistedUser>();
/// <summary>
/// A collection of blacklisted users' IDs. Blacklisted useres will never get the stream role.
/// </summary>
public HashSet<StreamRoleBlacklistedUser> Blacklist { get; set; } = new HashSet<StreamRoleBlacklistedUser>();
}
public class StreamRoleBlacklistedUser : DbEntity
{
public ulong UserId { get; set; }
public string Username { get; set; }
public override bool Equals(object obj)
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
if (!(obj is StreamRoleBlacklistedUser x))
return false;
/// <summary>
/// Whether the feature is enabled in the guild.
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// Id of the role to give to the users in the role 'FromRole' when they start streaming
/// </summary>
public ulong AddRoleId { get; set; }
/// <summary>
/// Id of the role whose users are eligible to get the 'AddRole'
/// </summary>
public ulong FromRoleId { get; set; }
/// <summary>
/// If set, feature will only apply to users who have this keyword in their streaming status.
/// </summary>
public string Keyword { get; set; }
/// <summary>
/// A collection of whitelisted users' IDs. Whitelisted users don't require 'keyword' in
/// order to get the stream role.
/// </summary>
public HashSet<StreamRoleWhitelistedUser> Whitelist { get; set; } = new HashSet<StreamRoleWhitelistedUser>();
/// <summary>
/// A collection of blacklisted users' IDs. Blacklisted useres will never get the stream role.
/// </summary>
public HashSet<StreamRoleBlacklistedUser> Blacklist { get; set; } = new HashSet<StreamRoleBlacklistedUser>();
return x.UserId == UserId;
}
public class StreamRoleBlacklistedUser : DbEntity
public override int GetHashCode()
{
public ulong UserId { get; set; }
public string Username { get; set; }
public override bool Equals(object obj)
{
if (!(obj is StreamRoleBlacklistedUser x))
return false;
return x.UserId == UserId;
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
}
public class StreamRoleWhitelistedUser : DbEntity
{
public ulong UserId { get; set; }
public string Username { get; set; }
public override bool Equals(object obj)
{
return obj is StreamRoleWhitelistedUser x
? x.UserId == UserId
: false;
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
return UserId.GetHashCode();
}
}
public class StreamRoleWhitelistedUser : DbEntity
{
public ulong UserId { get; set; }
public string Username { get; set; }
public override bool Equals(object obj)
{
return obj is StreamRoleWhitelistedUser x
? x.UserId == UserId
: false;
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
}

View File

@@ -1,20 +1,17 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class UnbanTimer : DbEntity
{
public class UnbanTimer : DbEntity
public ulong UserId { get; set; }
public DateTime UnbanAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode();
public override bool Equals(object obj)
{
public ulong UserId { get; set; }
public DateTime UnbanAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode();
public override bool Equals(object obj)
{
return obj is UnbanTimer ut
? ut.UserId == UserId
: false;
}
return obj is UnbanTimer ut
? ut.UserId == UserId
: false;
}
}
}

View File

@@ -1,20 +1,17 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class UnmuteTimer : DbEntity
{
public class UnmuteTimer : DbEntity
public ulong UserId { get; set; }
public DateTime UnmuteAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode();
public override bool Equals(object obj)
{
public ulong UserId { get; set; }
public DateTime UnmuteAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode();
public override bool Equals(object obj)
{
return obj is UnmuteTimer ut
? ut.UserId == UserId
: false;
}
return obj is UnmuteTimer ut
? ut.UserId == UserId
: false;
}
}
}

View File

@@ -1,21 +1,18 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class UnroleTimer : DbEntity
{
public class UnroleTimer : DbEntity
public ulong UserId { get; set; }
public ulong RoleId { get; set; }
public DateTime UnbanAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode() ^ RoleId.GetHashCode();
public override bool Equals(object obj)
{
public ulong UserId { get; set; }
public ulong RoleId { get; set; }
public DateTime UnbanAt { get; set; }
public override int GetHashCode() =>
UserId.GetHashCode() ^ RoleId.GetHashCode();
public override bool Equals(object obj)
{
return obj is UnroleTimer ut
? ut.UserId == UserId && ut.RoleId == RoleId
: false;
}
return obj is UnroleTimer ut
? ut.UserId == UserId && ut.RoleId == RoleId
: false;
}
}
}

View File

@@ -1,16 +1,13 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class UserXpStats : DbEntity
{
public class UserXpStats : DbEntity
{
public ulong UserId { get; set; }
public ulong GuildId { get; set; }
public int Xp { get; set; }
public int AwardedXp { get; set; }
public XpNotificationLocation NotifyOnLevelUp { get; set; }
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
}
public enum XpNotificationLocation { None, Dm, Channel }
public ulong UserId { get; set; }
public ulong GuildId { get; set; }
public int Xp { get; set; }
public int AwardedXp { get; set; }
public XpNotificationLocation NotifyOnLevelUp { get; set; }
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
}
public enum XpNotificationLocation { None, Dm, Channel }

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class VcRoleInfo : DbEntity
{
public class VcRoleInfo : DbEntity
{
public ulong VoiceChannelId { get; set; }
public ulong RoleId { get; set; }
}
}
public ulong VoiceChannelId { get; set; }
public ulong RoleId { get; set; }
}

View File

@@ -1,90 +1,87 @@
using NadekoBot.Extensions;
using System.Collections.Generic;
using NadekoBot.Modules.Gambling.Common;
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class WaifuInfo : DbEntity
{
public class WaifuInfo : DbEntity
public int WaifuId { get; set; }
public DiscordUser Waifu { get; set; }
public int? ClaimerId { get; set; }
public DiscordUser Claimer { get; set; }
public int? AffinityId { get; set; }
public DiscordUser Affinity { get; set; }
public int Price { get; set; }
public List<WaifuItem> Items { get; set; } = new List<WaifuItem>();
public override string ToString()
{
public int WaifuId { get; set; }
public DiscordUser Waifu { get; set; }
var claimer = "no one";
var status = "";
public int? ClaimerId { get; set; }
public DiscordUser Claimer { get; set; }
var waifuUsername = Waifu.Username.TrimTo(20);
var claimerUsername = Claimer?.Username.TrimTo(20);
public int? AffinityId { get; set; }
public DiscordUser Affinity { get; set; }
public int Price { get; set; }
public List<WaifuItem> Items { get; set; } = new List<WaifuItem>();
public override string ToString()
if (ClaimerId != null)
{
var claimer = "no one";
var status = "";
var waifuUsername = Waifu.Username.TrimTo(20);
var claimerUsername = Claimer?.Username.TrimTo(20);
if (ClaimerId != null)
{
claimer = $"{ claimerUsername }#{Claimer.Discriminator}";
}
if (AffinityId is null)
{
status = $"... but {waifuUsername}'s heart is empty";
}
else if (AffinityId == ClaimerId)
{
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
}
else
{
status = $"... but {waifuUsername}'s heart belongs to {Affinity.Username.TrimTo(20)}#{Affinity.Discriminator}";
}
return $"**{waifuUsername}#{Waifu.Discriminator}** - claimed by **{claimer}**\n\t{status}";
claimer = $"{ claimerUsername }#{Claimer.Discriminator}";
}
if (AffinityId is null)
{
status = $"... but {waifuUsername}'s heart is empty";
}
else if (AffinityId == ClaimerId)
{
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
}
else
{
status = $"... but {waifuUsername}'s heart belongs to {Affinity.Username.TrimTo(20)}#{Affinity.Discriminator}";
}
return $"**{waifuUsername}#{Waifu.Discriminator}** - claimed by **{claimer}**\n\t{status}";
}
}
public class WaifuLbResult
public class WaifuLbResult
{
public string Username { get; set; }
public string Discrim { get; set; }
public string Claimer { get; set; }
public string ClaimerDiscrim { get; set; }
public string Affinity { get; set; }
public string AffinityDiscrim { get; set; }
public int Price { get; set; }
public override string ToString()
{
public string Username { get; set; }
public string Discrim { get; set; }
var claimer = "no one";
var status = "";
public string Claimer { get; set; }
public string ClaimerDiscrim { get; set; }
var waifuUsername = Username.TrimTo(20);
var claimerUsername = Claimer?.TrimTo(20);
public string Affinity { get; set; }
public string AffinityDiscrim { get; set; }
public int Price { get; set; }
public override string ToString()
if (Claimer != null)
{
var claimer = "no one";
var status = "";
var waifuUsername = Username.TrimTo(20);
var claimerUsername = Claimer?.TrimTo(20);
if (Claimer != null)
{
claimer = $"{ claimerUsername }#{ClaimerDiscrim}";
}
if (Affinity is null)
{
status = $"... but {waifuUsername}'s heart is empty";
}
else if (Affinity + AffinityDiscrim == Claimer + ClaimerDiscrim)
{
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
}
else
{
status = $"... but {waifuUsername}'s heart belongs to {Affinity.TrimTo(20)}#{AffinityDiscrim}";
}
return $"**{waifuUsername}#{Discrim}** - claimed by **{claimer}**\n\t{status}";
claimer = $"{ claimerUsername }#{ClaimerDiscrim}";
}
if (Affinity is null)
{
status = $"... but {waifuUsername}'s heart is empty";
}
else if (Affinity + AffinityDiscrim == Claimer + ClaimerDiscrim)
{
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
}
else
{
status = $"... but {waifuUsername}'s heart belongs to {Affinity.TrimTo(20)}#{AffinityDiscrim}";
}
return $"**{waifuUsername}#{Discrim}** - claimed by **{claimer}**\n\t{status}";
}
}

View File

@@ -1,11 +1,8 @@
using System;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class WaifuItem : DbEntity
{
public class WaifuItem : DbEntity
{
public int? WaifuInfoId { get; set; }
public string ItemEmoji { get; set; }
public string Name { get; set; }
}
public int? WaifuInfoId { get; set; }
public string ItemEmoji { get; set; }
public string Name { get; set; }
}

View File

@@ -1,23 +1,22 @@
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class WaifuUpdate : DbEntity
{
public class WaifuUpdate : DbEntity
{
public int UserId { get; set; }
public DiscordUser User { get; set; }
public WaifuUpdateType UpdateType { get; set; }
public int UserId { get; set; }
public DiscordUser User { get; set; }
public WaifuUpdateType UpdateType { get; set; }
public int? OldId { get; set; }
public DiscordUser Old { get; set; }
public int? OldId { get; set; }
public DiscordUser Old { get; set; }
public int? NewId { get; set; }
public DiscordUser New { get; set; }
}
public enum WaifuUpdateType
{
AffinityChanged,
Claimed
}
public int? NewId { get; set; }
public DiscordUser New { get; set; }
}
public enum WaifuUpdateType
{
AffinityChanged,
Claimed
}

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public enum WarnExpireAction
{
public enum WarnExpireAction
{
Clear,
Delete
}
}
Clear,
Delete
}

View File

@@ -1,13 +1,12 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class Warning : DbEntity
{
public class Warning : DbEntity
{
public ulong GuildId { get; set; }
public ulong UserId { get; set; }
public string Reason { get; set; }
public bool Forgiven { get; set; }
public string ForgivenBy { get; set; }
public string Moderator { get; set; }
public int Weight { get; set; }
}
}
public ulong GuildId { get; set; }
public ulong UserId { get; set; }
public string Reason { get; set; }
public bool Forgiven { get; set; }
public string ForgivenBy { get; set; }
public string Moderator { get; set; }
public int Weight { get; set; }
}

View File

@@ -1,10 +1,9 @@
namespace NadekoBot.Services.Database.Models
namespace NadekoBot.Services.Database.Models;
public class WarningPunishment : DbEntity
{
public class WarningPunishment : DbEntity
{
public int Count { get; set; }
public PunishmentAction Punishment { get; set; }
public int Time { get; set; }
public ulong? RoleId { get; set; }
}
}
public int Count { get; set; }
public PunishmentAction Punishment { get; set; }
public int Time { get; set; }
public ulong? RoleId { get; set; }
}

View File

@@ -1,76 +1,73 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models;
namespace NadekoBot.Services.Database.Models
public class XpSettings : DbEntity
{
public class XpSettings : DbEntity
{
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public int GuildConfigId { get; set; }
public GuildConfig GuildConfig { get; set; }
public HashSet<XpRoleReward> RoleRewards { get; set; } = new HashSet<XpRoleReward>();
public HashSet<XpCurrencyReward> CurrencyRewards { get; set; } = new HashSet<XpCurrencyReward>();
public HashSet<ExcludedItem> ExclusionList { get; set; } = new HashSet<ExcludedItem>();
public bool ServerExcluded { get; set; }
}
public HashSet<XpRoleReward> RoleRewards { get; set; } = new HashSet<XpRoleReward>();
public HashSet<XpCurrencyReward> CurrencyRewards { get; set; } = new HashSet<XpCurrencyReward>();
public HashSet<ExcludedItem> ExclusionList { get; set; } = new HashSet<ExcludedItem>();
public bool ServerExcluded { get; set; }
}
public enum ExcludedItemType { Channel, Role }
public enum ExcludedItemType { Channel, Role }
public class XpRoleReward : DbEntity
{
public int XpSettingsId { get; set; }
public XpSettings XpSettings { get; set; }
public class XpRoleReward : DbEntity
{
public int XpSettingsId { get; set; }
public XpSettings XpSettings { get; set; }
public int Level { get; set; }
public ulong RoleId { get; set; }
public int Level { get; set; }
public ulong RoleId { get; set; }
/// <summary>
/// Whether the role should be removed (true) or added (false)
/// </summary>
public bool Remove { get; set; }
/// <summary>
/// Whether the role should be removed (true) or added (false)
/// </summary>
public bool Remove { get; set; }
public override int GetHashCode()
{
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is XpRoleReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
}
public override int GetHashCode()
{
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
}
public class XpCurrencyReward : DbEntity
public override bool Equals(object obj)
{
public int XpSettingsId { get; set; }
public XpSettings XpSettings { get; set; }
public int Level { get; set; }
public int Amount { get; set; }
public override int GetHashCode()
{
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is XpCurrencyReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
}
}
public class ExcludedItem : DbEntity
{
public ulong ItemId { get; set; }
public ExcludedItemType ItemType { get; set; }
public override int GetHashCode()
{
return ItemId.GetHashCode() ^ ItemType.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is ExcludedItem ei && ei.ItemId == ItemId && ei.ItemType == ItemType;
}
return obj is XpRoleReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
}
}
public class XpCurrencyReward : DbEntity
{
public int XpSettingsId { get; set; }
public XpSettings XpSettings { get; set; }
public int Level { get; set; }
public int Amount { get; set; }
public override int GetHashCode()
{
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is XpCurrencyReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
}
}
public class ExcludedItem : DbEntity
{
public ulong ItemId { get; set; }
public ExcludedItemType ItemType { get; set; }
public override int GetHashCode()
{
return ItemId.GetHashCode() ^ ItemType.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is ExcludedItem ei && ei.ItemId == ItemId && ei.ItemType == ItemType;
}
}

View File

@@ -2,389 +2,387 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using NadekoBot.Services.Database.Models;
using System;
using System.IO;
using Microsoft.Extensions.Logging;
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database
namespace NadekoBot.Services.Database;
public class NadekoContextFactory : IDesignTimeDbContextFactory<NadekoContext>
{
public class NadekoContextFactory : IDesignTimeDbContextFactory<NadekoContext>
public NadekoContext CreateDbContext(string[] args)
{
public NadekoContext CreateDbContext(string[] args)
{
LogSetup.SetupLogger(-2);
var optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
IBotCredentials creds = new BotCredsProvider().GetCreds();
var builder = new SqliteConnectionStringBuilder(creds.Db.ConnectionString);
builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource);
optionsBuilder.UseSqlite(builder.ToString());
var ctx = new NadekoContext(optionsBuilder.Options);
ctx.Database.SetCommandTimeout(60);
return ctx;
}
}
public class NadekoContext : 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; }
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
public DbSet<CustomReaction> CustomReactions { get; set; }
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
public DbSet<WaifuUpdate> WaifuUpdates { get; set; }
public DbSet<Warning> Warnings { get; set; }
public DbSet<UserXpStats> UserXpStats { get; set; }
public DbSet<ClubInfo> Clubs { get; set; }
//logging
public DbSet<LogSetting> LogSettings { get; set; }
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
public DbSet<IgnoredLogItem> IgnoredLogChannels { get; set; }
public DbSet<RotatingPlayingStatus> RotatingStatus { get; set; }
public DbSet<BlacklistEntry> Blacklist { get; set; }
public DbSet<AutoCommand> AutoCommands { get; set; }
public DbSet<RewardedUser> RewardedUsers { get; set; }
public DbSet<PlantedCurrency> PlantedCurrency { get; set; }
public DbSet<BanTemplate> BanTemplates { get; set; }
public DbSet<DiscordPermOverride> DiscordPermOverrides { get; set; }
public DbSet<DiscordUser> DiscordUser { get; set; }
public DbSet<MusicPlayerSettings> MusicPlayerSettings { get; set; }
public DbSet<Repeater> Repeaters { get; set; }
public DbSet<Poll> Poll { get; set; }
public DbSet<WaifuInfo> WaifuInfo { get; set; }
public DbSet<ImageOnlyChannel> ImageOnlyChannels { get; set; }
public DbSet<NsfwBlacklistedTag> NsfwBlacklistedTags { get; set; }
public DbSet<AutoTranslateChannel> AutoTranslateChannels { get; set; }
public DbSet<AutoTranslateUser> AutoTranslateUsers { get; set; }
public NadekoContext(DbContextOptions<NadekoContext> options) : base(options)
{
}
#if DEBUG
public static readonly ILoggerFactory _debugLoggerFactory =
LoggerFactory.Create(x => x.AddConsole());
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLoggerFactory(_debugLoggerFactory);
}
#endif
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
#region QUOTES
var quoteEntity = modelBuilder.Entity<Quote>();
quoteEntity.HasIndex(x => x.GuildId);
quoteEntity.HasIndex(x => x.Keyword);
#endregion
#region GuildConfig
var configEntity = modelBuilder.Entity<GuildConfig>();
configEntity
.HasIndex(c => c.GuildId)
.IsUnique();
modelBuilder.Entity<AntiSpamSetting>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.AntiSpamSetting);
modelBuilder.Entity<AntiRaidSetting>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.AntiRaidSetting);
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.AntiAltSetting)
.WithOne()
.HasForeignKey<AntiAltSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<FeedSub>()
.HasAlternateKey(x => new { x.GuildConfigId, x.Url });
modelBuilder.Entity<PlantedCurrency>()
.HasIndex(x => x.MessageId)
.IsUnique();
modelBuilder.Entity<PlantedCurrency>()
.HasIndex(x => x.ChannelId);
configEntity.HasIndex(x => x.WarnExpireHours)
.IsUnique(false);
#endregion
#region streamrole
modelBuilder.Entity<StreamRoleSettings>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.StreamRole);
#endregion
#region Self Assignable Roles
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
selfassignableRolesEntity
.HasIndex(s => new { s.GuildId, s.RoleId })
.IsUnique();
selfassignableRolesEntity
.Property(x => x.Group)
.HasDefaultValue(0);
#endregion
#region MusicPlaylists
var musicPlaylistEntity = modelBuilder.Entity<MusicPlaylist>();
musicPlaylistEntity
.HasMany(p => p.Songs)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
#endregion
#region Waifus
var wi = modelBuilder.Entity<WaifuInfo>();
wi.HasOne(x => x.Waifu)
.WithOne();
wi.HasIndex(x => x.Price);
wi.HasIndex(x => x.ClaimerId);
// wi.HasMany(x => x.Items)
// .WithOne()
// .OnDelete(DeleteBehavior.Cascade);
var wu = modelBuilder.Entity<WaifuUpdate>();
#endregion
#region DiscordUser
modelBuilder.Entity<DiscordUser>(du =>
{
du.Property(x => x.IsClubAdmin)
.HasDefaultValue(false);
du.Property(x => x.NotifyOnLevelUp)
.HasDefaultValue(XpNotificationLocation.None);
du.Property(x => x.LastXpGain)
.HasDefaultValueSql("datetime('now', '-1 years')");
du.Property(x => x.LastLevelUp)
.HasDefaultValueSql("datetime('now')");
du.HasAlternateKey(w => w.UserId);
du.HasOne(x => x.Club)
.WithMany(x => x.Users)
.IsRequired(false);
du.HasIndex(x => x.TotalXp);
du.HasIndex(x => x.CurrencyAmount);
du.HasIndex(x => x.UserId);
});
#endregion
#region Warnings
modelBuilder.Entity<Warning>(warn =>
{
warn.HasIndex(x => x.GuildId);
warn.HasIndex(x => x.UserId);
warn.HasIndex(x => x.DateAdded);
warn.Property(x => x.Weight)
.HasDefaultValue(1);
});
#endregion
#region PatreonRewards
var pr = modelBuilder.Entity<RewardedUser>();
pr.HasIndex(x => x.PatreonUserId)
.IsUnique();
#endregion
#region XpStats
var xps = modelBuilder.Entity<UserXpStats>();
xps
.HasIndex(x => new { x.UserId, x.GuildId })
.IsUnique();
xps
.Property(x => x.LastLevelUp)
.HasDefaultValue(new DateTime(2017, 9, 21, 20, 53, 13, 307, DateTimeKind.Local));
xps.HasIndex(x => x.UserId);
xps.HasIndex(x => x.GuildId);
xps.HasIndex(x => x.Xp);
xps.HasIndex(x => x.AwardedXp);
#endregion
#region XpSettings
modelBuilder.Entity<XpSettings>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.XpSettings);
#endregion
#region XpRoleReward
modelBuilder.Entity<XpRoleReward>()
.HasIndex(x => new { x.XpSettingsId, x.Level })
.IsUnique();
#endregion
#region Club
var ci = modelBuilder.Entity<ClubInfo>();
ci.HasOne(x => x.Owner)
.WithOne()
.HasForeignKey<ClubInfo>(x => x.OwnerId);
ci.HasAlternateKey(x => new { x.Name, x.Discrim });
#endregion
#region ClubManytoMany
modelBuilder.Entity<ClubApplicants>()
.HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubApplicants>()
.HasOne(pt => pt.User)
.WithMany();
modelBuilder.Entity<ClubApplicants>()
.HasOne(pt => pt.Club)
.WithMany(x => x.Applicants);
modelBuilder.Entity<ClubBans>()
.HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubBans>()
.HasOne(pt => pt.User)
.WithMany();
modelBuilder.Entity<ClubBans>()
.HasOne(pt => pt.Club)
.WithMany(x => x.Bans);
#endregion
#region Polls
modelBuilder.Entity<Poll>()
.HasIndex(x => x.GuildId)
.IsUnique();
#endregion
#region CurrencyTransactions
modelBuilder.Entity<CurrencyTransaction>()
.HasIndex(x => x.UserId)
.IsUnique(false);
#endregion
#region Reminders
modelBuilder.Entity<Reminder>()
.HasIndex(x => x.When);
#endregion
#region GroupName
modelBuilder.Entity<GroupName>()
.HasIndex(x => new { x.GuildConfigId, x.Number })
.IsUnique();
modelBuilder.Entity<GroupName>()
.HasOne(x => x.GuildConfig)
.WithMany(x => x.SelfAssignableRoleGroupNames)
.IsRequired();
#endregion
#region BanTemplate
modelBuilder.Entity<BanTemplate>()
.HasIndex(x => x.GuildId)
.IsUnique();
#endregion
#region Perm Override
modelBuilder.Entity<DiscordPermOverride>()
.HasIndex(x => new {x.GuildId, x.Command})
.IsUnique();
#endregion
#region Music
modelBuilder.Entity<MusicPlayerSettings>()
.HasIndex(x => x.GuildId)
.IsUnique();
modelBuilder.Entity<MusicPlayerSettings>()
.Property(x => x.Volume)
.HasDefaultValue(100);
#endregion
#region Reaction roles
modelBuilder.Entity<ReactionRoleMessage>(rrm => rrm
.HasMany(x => x.ReactionRoles)
.WithOne()
.OnDelete(DeleteBehavior.Cascade));
#endregion
#region LogSettings
modelBuilder.Entity<LogSetting>(ls => ls
.HasIndex(x => x.GuildId)
.IsUnique());
modelBuilder.Entity<LogSetting>(ls => ls
.HasMany(x => x.LogIgnores)
.WithOne(x => x.LogSetting)
.OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity<IgnoredLogItem>(ili => ili
.HasIndex(x => new { x.LogSettingId, x.LogItemId, x.ItemType })
.IsUnique());
#endregion
modelBuilder.Entity<ImageOnlyChannel>(ioc => ioc
.HasIndex(x => x.ChannelId)
.IsUnique());
modelBuilder.Entity<NsfwBlacklistedTag>(nbt => nbt
.HasIndex(x => x.GuildId)
.IsUnique(false));
var atch = modelBuilder.Entity<AutoTranslateChannel>();
atch.HasIndex(x => x.GuildId)
.IsUnique(false);
atch.HasIndex(x => x.ChannelId)
.IsUnique();
atch
.HasMany(x => x.Users)
.WithOne(x => x.Channel)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AutoTranslateUser>(atu => atu
.HasAlternateKey(x => new { x.ChannelId, x.UserId }));
}
LogSetup.SetupLogger(-2);
var optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
IBotCredentials creds = new BotCredsProvider().GetCreds();
var builder = new SqliteConnectionStringBuilder(creds.Db.ConnectionString);
builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource);
optionsBuilder.UseSqlite(builder.ToString());
var ctx = new NadekoContext(optionsBuilder.Options);
ctx.Database.SetCommandTimeout(60);
return ctx;
}
}
public class NadekoContext : 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; }
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
public DbSet<CustomReaction> CustomReactions { get; set; }
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
public DbSet<WaifuUpdate> WaifuUpdates { get; set; }
public DbSet<Warning> Warnings { get; set; }
public DbSet<UserXpStats> UserXpStats { get; set; }
public DbSet<ClubInfo> Clubs { get; set; }
//logging
public DbSet<LogSetting> LogSettings { get; set; }
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
public DbSet<IgnoredLogItem> IgnoredLogChannels { get; set; }
public DbSet<RotatingPlayingStatus> RotatingStatus { get; set; }
public DbSet<BlacklistEntry> Blacklist { get; set; }
public DbSet<AutoCommand> AutoCommands { get; set; }
public DbSet<RewardedUser> RewardedUsers { get; set; }
public DbSet<PlantedCurrency> PlantedCurrency { get; set; }
public DbSet<BanTemplate> BanTemplates { get; set; }
public DbSet<DiscordPermOverride> DiscordPermOverrides { get; set; }
public DbSet<DiscordUser> DiscordUser { get; set; }
public DbSet<MusicPlayerSettings> MusicPlayerSettings { get; set; }
public DbSet<Repeater> Repeaters { get; set; }
public DbSet<Poll> Poll { get; set; }
public DbSet<WaifuInfo> WaifuInfo { get; set; }
public DbSet<ImageOnlyChannel> ImageOnlyChannels { get; set; }
public DbSet<NsfwBlacklistedTag> NsfwBlacklistedTags { get; set; }
public DbSet<AutoTranslateChannel> AutoTranslateChannels { get; set; }
public DbSet<AutoTranslateUser> AutoTranslateUsers { get; set; }
public NadekoContext(DbContextOptions<NadekoContext> options) : base(options)
{
}
#if DEBUG
public static readonly ILoggerFactory _debugLoggerFactory =
LoggerFactory.Create(x => x.AddConsole());
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLoggerFactory(_debugLoggerFactory);
}
#endif
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
#region QUOTES
var quoteEntity = modelBuilder.Entity<Quote>();
quoteEntity.HasIndex(x => x.GuildId);
quoteEntity.HasIndex(x => x.Keyword);
#endregion
#region GuildConfig
var configEntity = modelBuilder.Entity<GuildConfig>();
configEntity
.HasIndex(c => c.GuildId)
.IsUnique();
modelBuilder.Entity<AntiSpamSetting>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.AntiSpamSetting);
modelBuilder.Entity<AntiRaidSetting>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.AntiRaidSetting);
modelBuilder.Entity<GuildConfig>()
.HasOne(x => x.AntiAltSetting)
.WithOne()
.HasForeignKey<AntiAltSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<FeedSub>()
.HasAlternateKey(x => new { x.GuildConfigId, x.Url });
modelBuilder.Entity<PlantedCurrency>()
.HasIndex(x => x.MessageId)
.IsUnique();
modelBuilder.Entity<PlantedCurrency>()
.HasIndex(x => x.ChannelId);
configEntity.HasIndex(x => x.WarnExpireHours)
.IsUnique(false);
#endregion
#region streamrole
modelBuilder.Entity<StreamRoleSettings>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.StreamRole);
#endregion
#region Self Assignable Roles
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
selfassignableRolesEntity
.HasIndex(s => new { s.GuildId, s.RoleId })
.IsUnique();
selfassignableRolesEntity
.Property(x => x.Group)
.HasDefaultValue(0);
#endregion
#region MusicPlaylists
var musicPlaylistEntity = modelBuilder.Entity<MusicPlaylist>();
musicPlaylistEntity
.HasMany(p => p.Songs)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
#endregion
#region Waifus
var wi = modelBuilder.Entity<WaifuInfo>();
wi.HasOne(x => x.Waifu)
.WithOne();
wi.HasIndex(x => x.Price);
wi.HasIndex(x => x.ClaimerId);
// wi.HasMany(x => x.Items)
// .WithOne()
// .OnDelete(DeleteBehavior.Cascade);
var wu = modelBuilder.Entity<WaifuUpdate>();
#endregion
#region DiscordUser
modelBuilder.Entity<DiscordUser>(du =>
{
du.Property(x => x.IsClubAdmin)
.HasDefaultValue(false);
du.Property(x => x.NotifyOnLevelUp)
.HasDefaultValue(XpNotificationLocation.None);
du.Property(x => x.LastXpGain)
.HasDefaultValueSql("datetime('now', '-1 years')");
du.Property(x => x.LastLevelUp)
.HasDefaultValueSql("datetime('now')");
du.HasAlternateKey(w => w.UserId);
du.HasOne(x => x.Club)
.WithMany(x => x.Users)
.IsRequired(false);
du.HasIndex(x => x.TotalXp);
du.HasIndex(x => x.CurrencyAmount);
du.HasIndex(x => x.UserId);
});
#endregion
#region Warnings
modelBuilder.Entity<Warning>(warn =>
{
warn.HasIndex(x => x.GuildId);
warn.HasIndex(x => x.UserId);
warn.HasIndex(x => x.DateAdded);
warn.Property(x => x.Weight)
.HasDefaultValue(1);
});
#endregion
#region PatreonRewards
var pr = modelBuilder.Entity<RewardedUser>();
pr.HasIndex(x => x.PatreonUserId)
.IsUnique();
#endregion
#region XpStats
var xps = modelBuilder.Entity<UserXpStats>();
xps
.HasIndex(x => new { x.UserId, x.GuildId })
.IsUnique();
xps
.Property(x => x.LastLevelUp)
.HasDefaultValue(new DateTime(2017, 9, 21, 20, 53, 13, 307, DateTimeKind.Local));
xps.HasIndex(x => x.UserId);
xps.HasIndex(x => x.GuildId);
xps.HasIndex(x => x.Xp);
xps.HasIndex(x => x.AwardedXp);
#endregion
#region XpSettings
modelBuilder.Entity<XpSettings>()
.HasOne(x => x.GuildConfig)
.WithOne(x => x.XpSettings);
#endregion
#region XpRoleReward
modelBuilder.Entity<XpRoleReward>()
.HasIndex(x => new { x.XpSettingsId, x.Level })
.IsUnique();
#endregion
#region Club
var ci = modelBuilder.Entity<ClubInfo>();
ci.HasOne(x => x.Owner)
.WithOne()
.HasForeignKey<ClubInfo>(x => x.OwnerId);
ci.HasAlternateKey(x => new { x.Name, x.Discrim });
#endregion
#region ClubManytoMany
modelBuilder.Entity<ClubApplicants>()
.HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubApplicants>()
.HasOne(pt => pt.User)
.WithMany();
modelBuilder.Entity<ClubApplicants>()
.HasOne(pt => pt.Club)
.WithMany(x => x.Applicants);
modelBuilder.Entity<ClubBans>()
.HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubBans>()
.HasOne(pt => pt.User)
.WithMany();
modelBuilder.Entity<ClubBans>()
.HasOne(pt => pt.Club)
.WithMany(x => x.Bans);
#endregion
#region Polls
modelBuilder.Entity<Poll>()
.HasIndex(x => x.GuildId)
.IsUnique();
#endregion
#region CurrencyTransactions
modelBuilder.Entity<CurrencyTransaction>()
.HasIndex(x => x.UserId)
.IsUnique(false);
#endregion
#region Reminders
modelBuilder.Entity<Reminder>()
.HasIndex(x => x.When);
#endregion
#region GroupName
modelBuilder.Entity<GroupName>()
.HasIndex(x => new { x.GuildConfigId, x.Number })
.IsUnique();
modelBuilder.Entity<GroupName>()
.HasOne(x => x.GuildConfig)
.WithMany(x => x.SelfAssignableRoleGroupNames)
.IsRequired();
#endregion
#region BanTemplate
modelBuilder.Entity<BanTemplate>()
.HasIndex(x => x.GuildId)
.IsUnique();
#endregion
#region Perm Override
modelBuilder.Entity<DiscordPermOverride>()
.HasIndex(x => new {x.GuildId, x.Command})
.IsUnique();
#endregion
#region Music
modelBuilder.Entity<MusicPlayerSettings>()
.HasIndex(x => x.GuildId)
.IsUnique();
modelBuilder.Entity<MusicPlayerSettings>()
.Property(x => x.Volume)
.HasDefaultValue(100);
#endregion
#region Reaction roles
modelBuilder.Entity<ReactionRoleMessage>(rrm => rrm
.HasMany(x => x.ReactionRoles)
.WithOne()
.OnDelete(DeleteBehavior.Cascade));
#endregion
#region LogSettings
modelBuilder.Entity<LogSetting>(ls => ls
.HasIndex(x => x.GuildId)
.IsUnique());
modelBuilder.Entity<LogSetting>(ls => ls
.HasMany(x => x.LogIgnores)
.WithOne(x => x.LogSetting)
.OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity<IgnoredLogItem>(ili => ili
.HasIndex(x => new { x.LogSettingId, x.LogItemId, x.ItemType })
.IsUnique());
#endregion
modelBuilder.Entity<ImageOnlyChannel>(ioc => ioc
.HasIndex(x => x.ChannelId)
.IsUnique());
modelBuilder.Entity<NsfwBlacklistedTag>(nbt => nbt
.HasIndex(x => x.GuildId)
.IsUnique(false));
var atch = modelBuilder.Entity<AutoTranslateChannel>();
atch.HasIndex(x => x.GuildId)
.IsUnique(false);
atch.HasIndex(x => x.ChannelId)
.IsUnique();
atch
.HasMany(x => x.Users)
.WithOne(x => x.Channel)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AutoTranslateUser>(atu => atu
.HasAlternateKey(x => new { x.ChannelId, x.UserId }));
}
}