From 51a4499809866c4d04521fe93d9748760907a102 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 19 Jun 2021 05:07:27 +0200 Subject: [PATCH] DiscordUser repository removed --- .../TypeReaders/ShmartNumberTypeReader.cs | 2 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 8 +- .../Gambling/Services/GamblingService.cs | 7 +- .../Modules/Gambling/Services/WaifuService.cs | 20 ++--- .../Permissions/Services/BlacklistService.cs | 2 +- .../Modules/Xp/Services/ClubService.cs | 10 +-- .../Modules/Xp/Services/XpService.cs | 12 +-- .../Services/Database/IUnitOfWork.cs | 1 - .../Repositories/IDiscordUserRepository.cs | 28 ------- ...Repository.cs => DiscordUserExtensions.cs} | 75 ++++++++----------- src/NadekoBot/Services/Database/UnitOfWork.cs | 3 - .../Services/Impl/CurrencyService.cs | 4 +- src/NadekoBot/Services/NadekoBot.cs | 2 +- 13 files changed, 67 insertions(+), 107 deletions(-) delete mode 100644 src/NadekoBot/Services/Database/Repositories/IDiscordUserRepository.cs rename src/NadekoBot/Services/Database/Repositories/Impl/{DiscordUserRepository.cs => DiscordUserExtensions.cs} (62%) diff --git a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs index 2fcd30f9d..c6ecd3b7a 100644 --- a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs @@ -76,7 +76,7 @@ namespace NadekoBot.Core.Common.TypeReaders long cur; using (var uow = _db.GetDbContext()) { - cur = uow.DiscordUsers.GetUserCurrency(ctx.User.Id); + cur = uow._context.DiscordUser.GetUserCurrency(ctx.User.Id); uow.SaveChanges(); } return cur; diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 36a8d61f1..58afb4d78 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Gambling { using (var uow = _db.GetDbContext()) { - return n(uow.DiscordUsers.GetUserCurrency(id)); + return n(uow._context.DiscordUser.GetUserCurrency(id)); } } @@ -522,7 +522,7 @@ namespace NadekoBot.Modules.Gambling using (var uow = _db.GetDbContext()) { - cleanRichest = uow.DiscordUsers.GetTopRichest(_client.CurrentUser.Id, 10_000); + cleanRichest = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000); } await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); @@ -536,7 +536,7 @@ namespace NadekoBot.Modules.Gambling { using (var uow = _db.GetDbContext()) { - cleanRichest = uow.DiscordUsers.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); + cleanRichest = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); } } @@ -551,7 +551,7 @@ namespace NadekoBot.Modules.Gambling { using (var uow = _db.GetDbContext()) { - toSend = uow.DiscordUsers.GetTopRichest(_client.CurrentUser.Id, 9, curPage); + toSend = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage); } } else diff --git a/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs b/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs index 722c5faa1..908857e0a 100644 --- a/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; +using NadekoBot.Common; using NadekoBot.Modules.Gambling.Services; using Serilog; @@ -135,11 +136,11 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU using (var uow = _db.GetDbContext()) { - cash = uow.DiscordUsers.GetTotalCurrency(); - onePercent = uow.DiscordUsers.GetTopOnePercentCurrency(_client.CurrentUser.Id); + cash = uow._context.DiscordUser.GetTotalCurrency(); + onePercent = uow._context.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id); planted = uow._context.PlantedCurrency.AsQueryable().Sum(x => x.Amount); waifus = uow._context.WaifuInfo.GetTotalValue(); - bot = uow.DiscordUsers.GetUserCurrency(_client.CurrentUser.Id); + bot = uow._context.DiscordUser.GetUserCurrency(_client.CurrentUser.Id); } var result = new EconomyResult diff --git a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs index 76008f7c6..420fb7aca 100644 --- a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = _db.GetDbContext()) { var waifu = uow._context.WaifuInfo.ByWaifuUserId(waifuId); - var ownerUser = uow.DiscordUsers.GetOrCreate(owner); + var ownerUser = uow._context.GetOrCreateUser(owner); // owner has to be the owner of the waifu if (waifu == null || waifu.ClaimerId != ownerUser.Id) @@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Gambling.Services } //new claimerId is the id of the new owner - var newOwnerUser = uow.DiscordUsers.GetOrCreate(newOwner); + var newOwnerUser = uow._context.GetOrCreateUser(newOwner); waifu.ClaimerId = newOwnerUser.Id; await uow.SaveChangesAsync(); @@ -171,8 +171,8 @@ namespace NadekoBot.Modules.Gambling.Services isAffinity = (w?.Affinity?.UserId == user.Id); if (w == null) { - var claimer = uow.DiscordUsers.GetOrCreate(user); - var waifu = uow.DiscordUsers.GetOrCreate(target); + var claimer = uow._context.GetOrCreateUser(user); + var waifu = uow._context.GetOrCreateUser(target); if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true)) { result = WaifuClaimResult.NotEnoughFunds; @@ -205,7 +205,7 @@ namespace NadekoBot.Modules.Gambling.Services else { var oldClaimer = w.Claimer; - w.Claimer = uow.DiscordUsers.GetOrCreate(user); + w.Claimer = uow._context.GetOrCreateUser(user); w.Price = amount + (amount / 4); result = WaifuClaimResult.Success; @@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Gambling.Services else { var oldClaimer = w.Claimer; - w.Claimer = uow.DiscordUsers.GetOrCreate(user); + w.Claimer = uow._context.GetOrCreateUser(user); w.Price = amount; result = WaifuClaimResult.Success; @@ -258,7 +258,7 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = _db.GetDbContext()) { var w = uow._context.WaifuInfo.ByWaifuUserId(user.Id); - var newAff = target == null ? null : uow.DiscordUsers.GetOrCreate(target); + var newAff = target == null ? null : uow._context.GetOrCreateUser(target); if (w?.Affinity?.UserId == target?.Id) { } @@ -267,7 +267,7 @@ namespace NadekoBot.Modules.Gambling.Services } else if (w == null) { - var thisUser = uow.DiscordUsers.GetOrCreate(user); + var thisUser = uow._context.GetOrCreateUser(user); uow._context.WaifuInfo.Add(new WaifuInfo() { Affinity = newAff, @@ -391,7 +391,7 @@ namespace NadekoBot.Modules.Gambling.Services Affinity = null, Claimer = null, Price = 1, - Waifu = uow.DiscordUsers.GetOrCreate(giftedWaifu), + Waifu = uow._context.GetOrCreateUser(giftedWaifu), }); } @@ -445,7 +445,7 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - var du = uow.DiscordUsers.GetOrCreate(target); + var du = uow._context.GetOrCreateUser(target); return GetFullWaifuInfoAsync(target.Id); } diff --git a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs index 11eda51e1..175dcf6af 100644 --- a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs @@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Permissions.Services })); //clear their currencies - uow.DiscordUsers.RemoveFromMany(toBlacklist); + uow._context.DiscordUser.RemoveFromMany(toBlacklist); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Xp/Services/ClubService.cs b/src/NadekoBot/Modules/Xp/Services/ClubService.cs index 44505e747..5385be5f0 100644 --- a/src/NadekoBot/Modules/Xp/Services/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Services/ClubService.cs @@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Xp.Services club = null; using var uow = _db.GetDbContext(); - var du = uow.DiscordUsers.GetOrCreate(user); + var du = uow._context.GetOrCreateUser(user); uow._context.SaveChanges(); var xp = new LevelStats(du.TotalXp); @@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow._context.Clubs.GetByOwner(from.Id); - var newOwnerUser = uow.DiscordUsers.GetOrCreate(newOwner); + var newOwnerUser = uow._context.GetOrCreateUser(newOwner); if (club == null || club.Owner.UserId != from.Id || @@ -85,7 +85,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { var club = uow._context.Clubs.GetByOwner(owner.Id); - var adminUser = uow.DiscordUsers.GetOrCreate(toAdmin); + var adminUser = uow._context.GetOrCreateUser(toAdmin); if (club == null || club.Owner.UserId != owner.Id || !club.Users.Contains(adminUser)) @@ -160,7 +160,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow.DiscordUsers.GetOrCreate(user); + var du = uow._context.GetOrCreateUser(user); uow._context.SaveChanges(); if (du.Club != null @@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow.DiscordUsers.GetOrCreate(user); + var du = uow._context.GetOrCreateUser(user); if (du.Club == null || du.Club.OwnerId == du.Id) return false; diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index 8bc3851b1..d14d655e0 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -168,7 +168,7 @@ namespace NadekoBot.Modules.Xp.Services // amounts for every user (in order to give rewards) var usr = uow._context.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id); - var du = uow.DiscordUsers.GetOrCreate(item.Key.User); + var du = uow._context.GetOrCreateUser(item.Key.User); var globalXp = du.TotalXp; var oldGlobalLevelData = new LevelStats(globalXp); @@ -425,7 +425,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow.DiscordUsers.GetUsersXpLeaderboardFor(page); + return uow._context.DiscordUser.GetUsersXpLeaderboardFor(page); } } @@ -452,7 +452,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow.DiscordUsers.GetOrCreate(user).NotifyOnLevelUp; + return uow._context.GetOrCreateUser(user).NotifyOnLevelUp; } } @@ -460,7 +460,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow.DiscordUsers.GetOrCreate(user); + var du = uow._context.GetOrCreateUser(user); du.NotifyOnLevelUp = type; await uow.SaveChangesAsync(); } @@ -706,9 +706,9 @@ namespace NadekoBot.Modules.Xp.Services int guildRank; using (var uow = _db.GetDbContext()) { - du = uow.DiscordUsers.GetOrCreate(user); + du = uow._context.GetOrCreateUser(user); totalXp = du.TotalXp; - globalRank = uow.DiscordUsers.GetUserGlobalRank(user.Id); + globalRank = uow._context.DiscordUser.GetUserGlobalRank(user.Id); guildRank = uow._context.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId); stats = uow._context.GetOrCreateUserXpStats(user.GuildId, user.Id); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Services/Database/IUnitOfWork.cs b/src/NadekoBot/Services/Database/IUnitOfWork.cs index 4606aef20..932f88b79 100644 --- a/src/NadekoBot/Services/Database/IUnitOfWork.cs +++ b/src/NadekoBot/Services/Database/IUnitOfWork.cs @@ -7,7 +7,6 @@ namespace NadekoBot.Core.Services.Database public interface IUnitOfWork : IDisposable { NadekoContext _context { get; } - IDiscordUserRepository DiscordUsers { get; } int SaveChanges(); Task SaveChangesAsync(); diff --git a/src/NadekoBot/Services/Database/Repositories/IDiscordUserRepository.cs b/src/NadekoBot/Services/Database/Repositories/IDiscordUserRepository.cs deleted file mode 100644 index 4827ddefc..000000000 --- a/src/NadekoBot/Services/Database/Repositories/IDiscordUserRepository.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Discord; -using NadekoBot.Core.Services.Database.Models; -using System.Collections.Generic; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Database.Repositories; - -namespace NadekoBot.Core.Services.Database.Repositories -{ - public interface IDiscordUserRepository : IRepository - { - void EnsureCreated(ulong userId, string username, string discrim, string avatarId); - DiscordUser GetOrCreate(ulong userId, string username, string discrim, string avatarId); - DiscordUser GetOrCreate(IUser original); - int GetUserGlobalRank(ulong id); - DiscordUser[] GetUsersXpLeaderboardFor(int page); - - long GetUserCurrency(ulong userId); - bool TryUpdateCurrencyState(ulong userId, string name, string discrim, string avatar, long change, bool allowNegative = false); - List GetTopRichest(ulong botId, int count, int page); - List GetTopRichest(ulong botId, int count); - void RemoveFromMany(IEnumerable ids); - decimal GetTotalCurrency(); - decimal GetTopOnePercentCurrency(ulong botId); - } -} diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserExtensions.cs similarity index 62% rename from src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserRepository.cs rename to src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserExtensions.cs index 91077204f..1d8fc9f45 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserExtensions.cs @@ -4,19 +4,16 @@ using Microsoft.EntityFrameworkCore; using Discord; using System.Collections.Generic; using System; +using NadekoBot.Core.Services.Database; using NadekoBot.Core.Services.Database.Repositories; -namespace NadekoBot.Services.Database.Repositories.Impl +namespace NadekoBot.Core.Services { - public class DiscordUserRepository : Repository, IDiscordUserRepository + public static class DiscordUserExtensions { - public DiscordUserRepository(DbContext context) : base(context) + public static void EnsureUserCreated(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId) { - } - - public void EnsureCreated(ulong userId, string username, string discrim, string avatarId) - { - _context.Database.ExecuteSqlInterpolated($@" + ctx.Database.ExecuteSqlInterpolated($@" UPDATE OR IGNORE DiscordUser SET Username={username}, Discriminator={discrim}, @@ -29,27 +26,21 @@ VALUES ({userId}, {username}, {discrim}, {avatarId}); } //temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown - public DiscordUser GetOrCreate(ulong userId, string username, string discrim, string avatarId) + public static DiscordUser GetOrCreateUser(this NadekoContext ctx, ulong userId, string username, string discrim, string avatarId) { - EnsureCreated(userId, username, discrim, avatarId); - return _set + ctx.EnsureUserCreated(userId, username, discrim, avatarId); + return ctx.DiscordUser .Include(x => x.Club) .First(u => u.UserId == userId); } - public DiscordUser GetOrCreate(IUser original) - => GetOrCreate(original.Id, original.Username, original.Discriminator, original.AvatarId); + public static DiscordUser GetOrCreateUser(this NadekoContext ctx, IUser original) + => ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId); - public int GetUserGlobalRank(ulong id) + public static int GetUserGlobalRank(this DbSet users, ulong id) { - // @"SELECT COUNT(*) + 1 - //FROM DiscordUser - //WHERE TotalXp > COALESCE((SELECT TotalXp - // FROM DiscordUser - // WHERE UserId = @p1 - // LIMIT 1), 0);" - return _set.AsQueryable() - .Where(x => x.TotalXp > (_set + return users.AsQueryable() + .Where(x => x.TotalXp > (users .AsQueryable() .Where(y => y.UserId == id) .Select(y => y.TotalXp) @@ -57,9 +48,9 @@ VALUES ({userId}, {username}, {discrim}, {avatarId}); .Count() + 1; } - public DiscordUser[] GetUsersXpLeaderboardFor(int page) + public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet users, int page) { - return _set.AsQueryable() + return users.AsQueryable() .OrderByDescending(x => x.TotalXp) .Skip(page * 9) .Take(9) @@ -67,9 +58,9 @@ VALUES ({userId}, {username}, {discrim}, {avatarId}); .ToArray(); } - public List GetTopRichest(ulong botId, int count, int page = 0) + public static List GetTopRichest(this DbSet users, ulong botId, int count, int page = 0) { - return _set.AsQueryable() + return users.AsQueryable() .Where(c => c.CurrencyAmount > 0 && botId != c.UserId) .OrderByDescending(c => c.CurrencyAmount) .Skip(page * 9) @@ -77,30 +68,30 @@ VALUES ({userId}, {username}, {discrim}, {avatarId}); .ToList(); } - public List GetTopRichest(ulong botId, int count) + public static List GetTopRichest(this DbSet users, ulong botId, int count) { - return _set.AsQueryable() + return users.AsQueryable() .Where(c => c.CurrencyAmount > 0 && botId != c.UserId) .OrderByDescending(c => c.CurrencyAmount) .Take(count) .ToList(); } - public long GetUserCurrency(ulong userId) => - _set.AsNoTracking() + public static long GetUserCurrency(this DbSet users, ulong userId) => + users.AsNoTracking() .FirstOrDefault(x => x.UserId == userId) ?.CurrencyAmount ?? 0; - public void RemoveFromMany(IEnumerable ids) + public static void RemoveFromMany(this DbSet users, IEnumerable ids) { - var items = _set.AsQueryable().Where(x => ids.Contains(x.UserId)); + var items = users.AsQueryable().Where(x => ids.Contains(x.UserId)); foreach (var item in items) { item.CurrencyAmount = 0; } } - public bool TryUpdateCurrencyState(ulong userId, string name, string discrim, string avatarId, long amount, bool allowNegative = false) + 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; @@ -109,7 +100,7 @@ VALUES ({userId}, {username}, {discrim}, {avatarId}); // and return number of rows > 0 (was there a change) if (amount < 0 && !allowNegative) { - var rows = _context.Database.ExecuteSqlInterpolated($@" + var rows = ctx.Database.ExecuteSqlInterpolated($@" UPDATE DiscordUser SET CurrencyAmount=CurrencyAmount+{amount} WHERE UserId={userId} AND CurrencyAmount>={-amount};"); @@ -119,7 +110,7 @@ WHERE UserId={userId} AND CurrencyAmount>={-amount};"); // if remove and negative is allowed, just remove without any condition if (amount < 0 && allowNegative) { - var rows = _context.Database.ExecuteSqlInterpolated($@" + var rows = ctx.Database.ExecuteSqlInterpolated($@" UPDATE DiscordUser SET CurrencyAmount=CurrencyAmount+{amount} WHERE UserId={userId};"); @@ -137,7 +128,7 @@ WHERE UserId={userId};"); // just update the amount, there is no new user data if (!updatedUserData) { - _context.Database.ExecuteSqlInterpolated($@" + ctx.Database.ExecuteSqlInterpolated($@" UPDATE OR IGNORE DiscordUser SET CurrencyAmount=CurrencyAmount+{amount} WHERE UserId={userId}; @@ -148,7 +139,7 @@ VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}); } else { - _context.Database.ExecuteSqlInterpolated($@" + ctx.Database.ExecuteSqlInterpolated($@" UPDATE OR IGNORE DiscordUser SET CurrencyAmount=CurrencyAmount+{amount}, Username={name}, @@ -163,18 +154,18 @@ VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}); return true; } - public decimal GetTotalCurrency() + public static decimal GetTotalCurrency(this DbSet users) { - return _set + return users .Sum(x => x.CurrencyAmount); } - public decimal GetTopOnePercentCurrency(ulong botId) + public static decimal GetTopOnePercentCurrency(this DbSet users, ulong botId) { - return _set.AsQueryable() + return users.AsQueryable() .Where(x => x.UserId != botId) .OrderByDescending(x => x.CurrencyAmount) - .Take(_set.Count() / 100 == 0 ? 1 : _set.Count() / 100) + .Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100) .Sum(x => x.CurrencyAmount); } } diff --git a/src/NadekoBot/Services/Database/UnitOfWork.cs b/src/NadekoBot/Services/Database/UnitOfWork.cs index e82b1fb54..1b60df06a 100644 --- a/src/NadekoBot/Services/Database/UnitOfWork.cs +++ b/src/NadekoBot/Services/Database/UnitOfWork.cs @@ -11,9 +11,6 @@ namespace NadekoBot.Services.Database { public NadekoContext _context { get; } - private IDiscordUserRepository _discordUsers; - public IDiscordUserRepository DiscordUsers => _discordUsers ?? (_discordUsers = new DiscordUserRepository(_context)); - public UnitOfWork(NadekoContext context) { _context = context; diff --git a/src/NadekoBot/Services/Impl/CurrencyService.cs b/src/NadekoBot/Services/Impl/CurrencyService.cs index 6536b6cf5..bc36212cf 100644 --- a/src/NadekoBot/Services/Impl/CurrencyService.cs +++ b/src/NadekoBot/Services/Impl/CurrencyService.cs @@ -35,7 +35,7 @@ namespace NadekoBot.Core.Services private bool InternalChange(ulong userId, string userName, string discrim, string avatar, string reason, long amount, bool gamble, IUnitOfWork uow) { - var result = uow.DiscordUsers.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount); + var result = uow._context.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount); if (result) { var t = GetCurrencyTransaction(userId, reason, amount); @@ -45,7 +45,7 @@ namespace NadekoBot.Core.Services { var t2 = GetCurrencyTransaction(_bot.Id, reason, -amount); uow._context.CurrencyTransactions.Add(t2); - uow.DiscordUsers.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true); + uow._context.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true); } } return result; diff --git a/src/NadekoBot/Services/NadekoBot.cs b/src/NadekoBot/Services/NadekoBot.cs index f78983b1a..2261c46cf 100644 --- a/src/NadekoBot/Services/NadekoBot.cs +++ b/src/NadekoBot/Services/NadekoBot.cs @@ -147,7 +147,7 @@ namespace NadekoBot using (var uow = _db.GetDbContext()) { - uow.DiscordUsers.EnsureCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId); + uow._context.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId); AllGuildConfigs = uow._context.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); }