From c127dcd1e3053d386b36aa33ffdb33204ef525c7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 19 Jun 2021 05:16:27 +0200 Subject: [PATCH] UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow --- .../TypeReaders/ShmartNumberTypeReader.cs | 2 +- .../Services/AdministrationService.cs | 8 +-- .../Services/AutoAssignRoleService.cs | 6 +- .../Services/DangerousCommandsService.cs | 20 +++--- .../Services/DiscordPermOverrideService.cs | 16 ++--- .../Services/GameVoiceChannelService.cs | 2 +- .../Services/GuildTimezoneService.cs | 2 +- .../Services/LogCommandService.cs | 10 +-- .../Administration/Services/MuteService.cs | 22 +++--- .../Services/PlayingRotateService.cs | 10 +-- .../Services/ProtectionService.cs | 20 +++--- .../Services/RoleCommandsService.cs | 6 +- .../Services/SelfAssignedRolesService.cs | 26 +++---- .../Administration/Services/SelfService.cs | 22 +++--- .../Services/UserPunishService.cs | 46 ++++++------ .../Administration/Services/VcRoleService.cs | 14 ++-- .../Services/CustomReactionsService.cs | 28 ++++---- src/NadekoBot/Modules/Gambling/Gambling.cs | 10 +-- .../Gambling/Services/GamblingService.cs | 38 ++-------- .../Gambling/Services/Impl/ShopService.cs | 4 +- .../Gambling/Services/PlantPickService.cs | 14 ++-- .../Modules/Gambling/Services/WaifuService.cs | 70 +++++++++---------- .../Modules/Gambling/ShopCommands.cs | 24 +++---- .../Modules/Games/CleverBotCommands.cs | 4 +- .../Modules/Games/Common/PollRunner.cs | 2 +- .../Games/Services/GamesConfigService.cs | 2 +- .../Modules/Games/Services/PollService.cs | 6 +- .../Modules/Music/PlaylistCommands.cs | 12 ++-- .../Modules/Music/Services/MusicService.cs | 7 +- .../Music/Services/_OldMusicService.cs | 8 +-- src/NadekoBot/Modules/Music/_OldMusic.cs | 2 +- .../Modules/Permissions/CmdCdsCommands.cs | 4 +- .../Modules/Permissions/FilterCommands.cs | 22 +++--- .../Modules/Permissions/Permissions.cs | 12 ++-- .../Permissions/Services/BlacklistService.cs | 12 ++-- .../Permissions/Services/FilterService.cs | 4 +- .../Services/PermissionsService.cs | 8 +-- .../Modules/Searches/Services/FeedsService.cs | 10 +-- .../Searches/Services/SearchesService.cs | 4 +- .../Services/StreamNotificationService.cs | 26 +++---- .../Searches/Services/YtTrackService.cs | 2 +- .../Searches/StreamNotificationCommands.cs | 2 +- .../Modules/Utility/CommandMapCommands.cs | 10 +-- .../Modules/Utility/QuoteCommands.cs | 19 +++-- .../Modules/Utility/RemindCommands.cs | 8 +-- .../Utility/Services/CommandMapService.cs | 4 +- .../Utility/Services/PatreonRewardsService.cs | 2 +- .../Modules/Utility/Services/RemindService.cs | 4 +- .../Utility/Services/RepeaterService.cs | 19 +++-- .../Utility/Services/StreamRoleService.cs | 12 ++-- .../Utility/Services/VerboseErrorsService.cs | 2 +- .../Modules/Xp/Services/ClubService.cs | 60 ++++++++-------- .../Modules/Xp/Services/XpConfigMigrator.cs | 2 +- .../Modules/Xp/Services/XpService.cs | 64 ++++++++--------- src/NadekoBot/Services/CommandHandler.cs | 2 +- .../Impl => Extensions}/ClubExtensions.cs | 0 .../CurrencyTransactionExtensions.cs | 0 .../CustomReactionsExtensions.cs | 0 .../Impl => Extensions}/DbExtensions.cs | 0 .../DiscordUserExtensions.cs | 0 .../GuildConfigExtensions.cs | 0 .../MusicPlayerSettingsExtensions.cs | 0 .../MusicPlaylistExtensions.cs | 0 .../Impl => Extensions}/PollExtensions.cs | 0 .../Impl => Extensions}/QuoteExtensions.cs | 0 .../Impl => Extensions}/ReminderExtensions.cs | 0 .../SelfAssignableRolesExtensions.cs | 0 .../Impl => Extensions}/UserXpExtensions.cs | 0 .../Impl => Extensions}/WaifuExtensions.cs | 0 .../Impl => Extensions}/WarningExtensions.cs | 0 .../Services/Database/IUnitOfWork.cs | 14 ---- .../Database/Repositories/IRepository.cs | 11 --- .../Database/Repositories/Impl/Repository.cs | 23 ------ src/NadekoBot/Services/Database/UnitOfWork.cs | 31 -------- src/NadekoBot/Services/DbService.cs | 2 +- .../Services/GreetSettingsService.cs | 32 ++++----- .../Services/Impl/CurrencyService.cs | 10 +-- src/NadekoBot/Services/Impl/Localization.cs | 4 +- src/NadekoBot/Services/NadekoBot.cs | 8 +-- .../Services/Settings/BotConfigMigrator.cs | 2 +- .../Settings/GamblingConfigMigrator.cs | 2 +- 81 files changed, 404 insertions(+), 512 deletions(-) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/ClubExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories => Extensions}/CurrencyTransactionExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/CustomReactionsExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/DbExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/DiscordUserExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/GuildConfigExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/MusicPlayerSettingsExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/MusicPlaylistExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/PollExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/QuoteExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/ReminderExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/SelfAssignableRolesExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/UserXpExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/WaifuExtensions.cs (100%) rename src/NadekoBot/Services/Database/{Repositories/Impl => Extensions}/WarningExtensions.cs (100%) delete mode 100644 src/NadekoBot/Services/Database/IUnitOfWork.cs delete mode 100644 src/NadekoBot/Services/Database/Repositories/IRepository.cs delete mode 100644 src/NadekoBot/Services/Database/Repositories/Impl/Repository.cs delete mode 100644 src/NadekoBot/Services/Database/UnitOfWork.cs diff --git a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs index c6ecd3b7a..8f12fbb54 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._context.DiscordUser.GetUserCurrency(ctx.User.Id); + cur = uow.DiscordUser.GetUserCurrency(ctx.User.Id); uow.SaveChanges(); } return cur; diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index 5edc8702f..151baa6a5 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, + var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); return (conf.DeleteMessageOnCommand, conf.DelMsgOnCmdChannels); @@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services bool enabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.DeleteMessageOnCommand = !conf.DeleteMessageOnCommand; uow.SaveChanges(); @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, + var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId); @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Administration.Services if (!(old is null)) { conf.DelMsgOnCmdChannels.Remove(old); - uow._context.Remove(old); + uow.Remove(old); } } else diff --git a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs index 313de2b1e..d47d02ae7 100644 --- a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs @@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Administration.Services public async Task> ToggleAarAsync(ulong guildId, ulong roleId) { using var uow = _db.GetDbContext(); - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); var roles = gc.GetAutoAssignableRoles(); if(!roles.Remove(roleId) && roles.Count < 3) roles.Add(roleId); @@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services { using var uow = _db.GetDbContext(); - await uow._context + await uow .GuildConfigs .AsNoTracking() .Where(x => x.GuildId == guildId) @@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Administration.Services { using var uow = _db.GetDbContext(); - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); gc.SetAutoAssignableRoles(newRoles); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs index d88391d22..228e3b92a 100644 --- a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs @@ -46,7 +46,7 @@ DELETE FROM Clubs;"; int res; using (var uow = _db.GetDbContext()) { - res = await uow._context.Database.ExecuteSqlRawAsync(sql); + res = await uow.Database.ExecuteSqlRawAsync(sql); } return res; } @@ -67,7 +67,7 @@ DELETE FROM Clubs;"; using (var uow = _db.GetDbContext()) { - var conn = uow._context.Database.GetDbConnection(); + var conn = uow.Database.GetDbConnection(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = sql; @@ -97,31 +97,31 @@ DELETE FROM Clubs;"; using var uow = _db.GetDbContext(); // get waifu info - var wi = await uow._context.Set() + var wi = await uow.Set() .FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId); // if it exists, delete waifu related things if (!(wi is null)) { // remove updates which have new or old as this waifu - await uow._context + await uow .WaifuUpdates .DeleteAsync(wu => wu.New.UserId == userId || wu.Old.UserId == userId); // delete all items this waifu owns - await uow._context + await uow .Set() .DeleteAsync(x => x.WaifuInfoId == wi.Id); // all waifus this waifu claims are released - await uow._context + await uow .Set() .AsQueryable() .Where(x => x.Claimer.UserId == userId) .UpdateAsync(x => new WaifuInfo() {ClaimerId = null}); // all affinities set to this waifu are reset - await uow._context + await uow .Set() .AsQueryable() .Where(x => x.Affinity.UserId == userId) @@ -129,16 +129,16 @@ DELETE FROM Clubs;"; } // delete guild xp - await uow._context + await uow .UserXpStats .DeleteAsync(x => x.UserId == userId); // delete currency transactions - await uow._context.Set() + await uow.Set() .DeleteAsync(x => x.UserId == userId); // delete user, currency, and clubs go away with it - await uow._context.DiscordUser + await uow.DiscordUser .DeleteAsync(u => u.UserId == userId); } } diff --git a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs index a4d13b55a..1c3f3682f 100644 --- a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration.Services _db = db; _services = services; using var uow = _db.GetDbContext(); - _overrides = uow._context.DiscordPermOverrides + _overrides = uow.DiscordPermOverrides .AsNoTracking() .AsEnumerable() .ToDictionary(o => (o.GuildId ?? 0, o.Command), o => o) @@ -60,14 +60,14 @@ namespace NadekoBot.Modules.Administration.Services commandName = commandName.ToLowerInvariant(); using (var uow = _db.GetDbContext()) { - var over = await uow._context + var over = await uow .Set() .AsQueryable() .FirstOrDefaultAsync(x => x.GuildId == guildId && commandName == x.Command); if (over is null) { - uow._context.Set() + uow.Set() .Add(over = new DiscordPermOverride() { Command = commandName, @@ -90,14 +90,14 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var overrides = await uow._context + var overrides = await uow .Set() .AsQueryable() .AsNoTracking() .Where(x => x.GuildId == guildId) .ToListAsync(); - uow._context.RemoveRange(overrides); + uow.RemoveRange(overrides); await uow.SaveChangesAsync(); foreach (var over in overrides) @@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = _db.GetDbContext()) { - var over = await uow._context + var over = await uow .Set() .AsQueryable() .AsNoTracking() @@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration.Services if (over is null) return; - uow._context.Remove(over); + uow.Remove(over); await uow.SaveChangesAsync(); _overrides.TryRemove((guildId, commandName), out _); @@ -133,7 +133,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - return uow._context + return uow .Set() .AsQueryable() .AsNoTracking() diff --git a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs index 448445446..9b0a67671 100644 --- a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs +++ b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs @@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Administration.Services ulong? id; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); if (gc.GameVoiceChannel == vchId) { diff --git a/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs b/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs index 0a00c40ee..2b3054a5f 100644 --- a/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs +++ b/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); gc.TimeZoneId = tz?.Id; uow.SaveChanges(); diff --git a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs index a0f28bcd1..f08832b2d 100644 --- a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs @@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = db.GetDbContext()) { var guildIds = client.Guilds.Select(x => x.Id).ToList(); - var configs = uow._context + var configs = uow .Set() .AsQueryable() .Include(gc => gc.LogSetting) @@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration.Services int removed = 0; using (var uow = _db.GetDbContext()) { - var config = uow._context.LogSettingsFor(gid); + var config = uow.LogSettingsFor(gid); LogSetting logSetting = GuildLogSettings.GetOrAdd(gid, (id) => config.LogSetting); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid); config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid); @@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Administration.Services LogSetting logSetting; using (var uow = _db.GetDbContext()) { - logSetting = uow._context.LogSettingsFor(guildId).LogSetting; + logSetting = uow.LogSettingsFor(guildId).LogSetting; GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting); logSetting.LogOtherId = logSetting.MessageUpdatedId = @@ -256,7 +256,7 @@ namespace NadekoBot.Modules.Administration.Services ulong? channelId = null; using (var uow = _db.GetDbContext()) { - var logSetting = uow._context.LogSettingsFor(gid).LogSetting; + var logSetting = uow.LogSettingsFor(gid).LogSetting; GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting); switch (type) { @@ -1220,7 +1220,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var newLogSetting = uow._context.LogSettingsFor(guildId).LogSetting; + var newLogSetting = uow.LogSettingsFor(guildId).LogSetting; switch (logChannelType) { case LogType.Other: diff --git a/src/NadekoBot/Modules/Administration/Services/MuteService.cs b/src/NadekoBot/Modules/Administration/Services/MuteService.cs index e51405f02..7c04445a9 100644 --- a/src/NadekoBot/Modules/Administration/Services/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Services/MuteService.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = db.GetDbContext()) { var guildIds = client.Guilds.Select(x => x.Id).ToList(); - var configs = uow._context.Set().AsQueryable() + var configs = uow.Set().AsQueryable() .Include(x => x.MutedUsers) .Include(x => x.UnbanTimer) .Include(x => x.UnmuteTimers) @@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, set => set); + var config = uow.GuildConfigsForId(guildId, set => set); config.MuteRoleName = name; GuildMuteRoles.AddOrUpdate(guildId, name, (id, old) => name); await uow.SaveChangesAsync(); @@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Administration.Services StopTimer(usr.GuildId, usr.Id, TimerType.Mute); using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(usr.Guild.Id, + var config = uow.GuildConfigsForId(usr.Guild.Id, set => set.Include(gc => gc.MutedUsers) .Include(gc => gc.UnmuteTimers)); config.MutedUsers.Add(new MutedUserId() @@ -231,7 +231,7 @@ namespace NadekoBot.Modules.Administration.Services StopTimer(guildId, usrId, TimerType.Mute); using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers) + var config = uow.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers) .Include(gc => gc.UnmuteTimers)); var match = new MutedUserId() { @@ -240,7 +240,7 @@ namespace NadekoBot.Modules.Administration.Services var toRemove = config.MutedUsers.FirstOrDefault(x => x.Equals(match)); if (toRemove != null) { - uow._context.Remove(toRemove); + uow.Remove(toRemove); } if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet muted)) muted.TryRemove(usrId); @@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Administration.Services await MuteUser(user, mod, muteType, reason).ConfigureAwait(false); // mute the user. This will also remove any previous unmute timers using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers)); + var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers)); config.UnmuteTimers.Add(new UnmuteTimer() { UserId = user.Id, @@ -343,7 +343,7 @@ namespace NadekoBot.Modules.Administration.Services await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false); using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer)); + var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer)); config.UnbanTimer.Add(new UnbanTimer() { UserId = user.Id, @@ -360,7 +360,7 @@ namespace NadekoBot.Modules.Administration.Services await user.AddRoleAsync(role).ConfigureAwait(false); using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer)); + var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer)); config.UnroleTimer.Add(new UnroleTimer() { UserId = user.Id, @@ -458,17 +458,17 @@ namespace NadekoBot.Modules.Administration.Services object toDelete; if (type == TimerType.Mute) { - var config = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.UnmuteTimers)); + var config = uow.GuildConfigsForId(guildId, set => set.Include(x => x.UnmuteTimers)); toDelete = config.UnmuteTimers.FirstOrDefault(x => x.UserId == userId); } else { - var config = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.UnbanTimer)); + var config = uow.GuildConfigsForId(guildId, set => set.Include(x => x.UnbanTimer)); toDelete = config.UnbanTimer.FirstOrDefault(x => x.UserId == userId); } if (toDelete != null) { - uow._context.Remove(toDelete); + uow.Remove(toDelete); } uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs b/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs index 54cf83792..998476a0a 100644 --- a/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs +++ b/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs @@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Administration.Services IReadOnlyList rotatingStatuses; using (var uow = _db.GetDbContext()) { - rotatingStatuses = uow._context.RotatingStatus + rotatingStatuses = uow.RotatingStatus .AsNoTracking() .OrderBy(x => x.Id) .ToList(); @@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services throw new ArgumentOutOfRangeException(nameof(index)); using var uow = _db.GetDbContext(); - var toRemove = await uow._context.RotatingStatus + var toRemove = await uow.RotatingStatus .AsQueryable() .AsNoTracking() .Skip(index) @@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Administration.Services if (toRemove is null) return null; - uow._context.Remove(toRemove); + uow.Remove(toRemove); await uow.SaveChangesAsync(); return toRemove.Status; } @@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Administration.Services { using var uow = _db.GetDbContext(); var toAdd = new RotatingPlayingStatus {Status = status, Type = t}; - uow._context.Add(toAdd); + uow.Add(toAdd); await uow.SaveChangesAsync(); } @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Administration.Services public IReadOnlyList GetRotatingStatuses() { using var uow = _db.GetDbContext(); - return uow._context.RotatingStatus.AsNoTracking().ToList(); + return uow.RotatingStatus.AsNoTracking().ToList(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs index a0f153c08..c8a0a1ea5 100644 --- a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs +++ b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs @@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Administration.Services var ids = client.GetGuildIds(); using (var uow = db.GetDbContext()) { - var configs = uow._context.Set() + var configs = uow.Set() .AsQueryable() .Include(x => x.AntiRaidSetting) .Include(x => x.AntiSpamSetting) @@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Administration.Services private Task _bot_JoinedGuild(GuildConfig gc) { using var uow = _db.GetDbContext(); - var gcWithData = uow._context.GuildConfigsForId(gc.GuildId, + var gcWithData = uow.GuildConfigsForId(gc.GuildId, set => set .Include(x => x.AntiRaidSetting) .Include(x => x.AntiAltSetting) @@ -304,7 +304,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting)); gc.AntiRaidSetting = stats.AntiRaidSettings; await uow.SaveChangesAsync(); @@ -319,7 +319,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting)); gc.AntiRaidSetting = null; uow.SaveChanges(); @@ -336,7 +336,7 @@ namespace NadekoBot.Modules.Administration.Services removed.UserStats.ForEach(x => x.Value.Dispose()); using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting) + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting) .ThenInclude(x => x.IgnoredChannels)); gc.AntiSpamSetting = null; @@ -375,7 +375,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)); if (gc.AntiSpamSetting != null) { @@ -402,7 +402,7 @@ namespace NadekoBot.Modules.Administration.Services bool added; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; if (spam is null) { @@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Administration.Services else { var toRemove = spam.IgnoredChannels.First(x => x.ChannelId == channelId); - uow._context.Set().Remove(toRemove); // remove from db + uow.Set().Remove(toRemove); // remove from db if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) { temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache @@ -459,7 +459,7 @@ namespace NadekoBot.Modules.Administration.Services int actionDurationMinutes = 0, ulong? roleId = null) { using var uow = _db.GetDbContext(); - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); gc.AntiAltSetting = new AntiAltSetting() { Action = action, @@ -478,7 +478,7 @@ namespace NadekoBot.Modules.Administration.Services return false; using var uow = _db.GetDbContext(); - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); gc.AntiAltSetting = null; await uow.SaveChangesAsync(); return true; diff --git a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs index e37db913a..e71f105a9 100644 --- a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs @@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(id, set => set + var gc = uow.GuildConfigsForId(id, set => set .Include(x => x.ReactionRoleMessages) .ThenInclude(x => x.ReactionRoles)); if (gc.ReactionRoleMessages.Count >= 10) @@ -174,10 +174,10 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(id, + var gc = uow.GuildConfigsForId(id, set => set.Include(x => x.ReactionRoleMessages) .ThenInclude(x => x.ReactionRoles)); - uow._context.Set() + uow.Set() .RemoveRange(gc.ReactionRoleMessages[index].ReactionRoles); gc.ReactionRoleMessages.RemoveAt(index); _models.AddOrUpdate(id, diff --git a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs index 458d53434..b63c71fe2 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs @@ -43,13 +43,13 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId); + var roles = uow.SelfAssignableRoles.GetFromGuild(guildId); if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id)) { return false; } - uow._context.SelfAssignableRoles.Add(new SelfAssignedRole + uow.SelfAssignableRoles.Add(new SelfAssignedRole { Group = group, RoleId = role.Id, @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration.Services bool newval; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, set => set); + var config = uow.GuildConfigsForId(guildId, set => set); newval = config.AutoDeleteSelfAssignedRoleMessages = !config.AutoDeleteSelfAssignedRoleMessages; uow.SaveChanges(); } @@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Administration.Services LevelStats userLevelData; using (var uow = _db.GetDbContext()) { - var stats = uow._context.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id); + var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id); userLevelData = new LevelStats(stats.Xp + stats.AwardedXp); } @@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Administration.Services bool set = false; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames)); + var gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames)); var toUpdate = gc.SelfAssignableRoleGroupNames.FirstOrDefault(x => x.Number == group); if (string.IsNullOrWhiteSpace(name)) @@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Administration.Services bool success; using (var uow = _db.GetDbContext()) { - success = uow._context.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId); + success = uow.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId); uow.SaveChanges(); } return success; @@ -207,10 +207,10 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); var autoDelete = gc.AutoDeleteSelfAssignedRoleMessages; var exclusive = gc.ExclusiveSelfAssignedRoles; - var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId); + var roles = uow.SelfAssignableRoles.GetFromGuild(guildId); return (autoDelete, exclusive, roles); } @@ -220,7 +220,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId); + var roles = uow.SelfAssignableRoles.GetFromGuild(guildId); var sar = roles.FirstOrDefault(x => x.RoleId == role.Id); if (sar != null) { @@ -241,7 +241,7 @@ namespace NadekoBot.Modules.Administration.Services bool areExclusive; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, set => set); + var config = uow.GuildConfigsForId(guildId, set => set); areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles; uow.SaveChanges(); @@ -257,13 +257,13 @@ namespace NadekoBot.Modules.Administration.Services IDictionary groupNames; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames)); + var gc = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames)); exclusive = gc.ExclusiveSelfAssignedRoles; groupNames = gc.SelfAssignableRoleGroupNames.ToDictionary(x => x.Number, x => x.Name); - var roleModels = uow._context.SelfAssignableRoles.GetFromGuild(guild.Id); + var roleModels = uow.SelfAssignableRoles.GetFromGuild(guild.Id); roles = roleModels .Select(x => (Model: x, Role: guild.GetRole(x.RoleId))); - uow._context.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray()); + uow.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray()); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index 049b08313..f9cc3fbe5 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Administration.Services { using var uow = _db.GetDbContext(); - _autoCommands = uow._context + _autoCommands = uow .AutoCommands .AsNoTracking() .Where(x => x.Interval >= 5) @@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration.Services .ToConcurrent()) .ToConcurrent(); - var startupCommands = uow._context.AutoCommands.AsNoTracking().Where(x => x.Interval == 0); + var startupCommands = uow.AutoCommands.AsNoTracking().Where(x => x.Interval == 0); foreach (var cmd in startupCommands) { try @@ -163,7 +163,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - uow._context.AutoCommands.Add(cmd); + uow.AutoCommands.Add(cmd); uow.SaveChanges(); } @@ -181,7 +181,7 @@ namespace NadekoBot.Modules.Administration.Services public IEnumerable GetStartupCommands() { using var uow = _db.GetDbContext(); - return uow._context + return uow .AutoCommands .AsNoTracking() .Where(x => x.Interval == 0) @@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Administration.Services public IEnumerable GetAutoCommands() { using var uow = _db.GetDbContext(); - return uow._context + return uow .AutoCommands .AsNoTracking() .Where(x => x.Interval >= 5) @@ -297,7 +297,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - cmd = uow._context.AutoCommands + cmd = uow.AutoCommands .AsNoTracking() .Where(x => x.Interval == 0) .Skip(index) @@ -305,7 +305,7 @@ namespace NadekoBot.Modules.Administration.Services if (cmd != null) { - uow._context.Remove(cmd); + uow.Remove(cmd); uow.SaveChanges(); return true; } @@ -318,7 +318,7 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - cmd = uow._context.AutoCommands + cmd = uow.AutoCommands .AsNoTracking() .Where(x => x.Interval >= 5) .Skip(index) @@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Administration.Services if (cmd != null) { - uow._context.Remove(cmd); + uow.Remove(cmd); if (_autoCommands.TryGetValue(cmd.GuildId, out var autos)) if (autos.TryRemove(cmd.Id, out var timer)) timer.Change(Timeout.Infinite, Timeout.Infinite); @@ -369,12 +369,12 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var toRemove = uow._context + var toRemove = uow .AutoCommands .AsNoTracking() .Where(x => x.Interval == 0); - uow._context.AutoCommands.RemoveRange(toRemove); + uow.AutoCommands.RemoveRange(toRemove); uow.SaveChanges(); } } diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index 2d36eacf3..47f454514 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -61,16 +61,16 @@ namespace NadekoBot.Modules.Administration.Services List ps; using (var uow = _db.GetDbContext()) { - ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)) + ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)) .WarnPunishments; - warnings += uow._context + warnings += uow .Warnings .ForId(guildId, userId) .Where(w => !w.Forgiven && w.UserId == userId) .Count(); - uow._context.Warnings.Add(warn); + uow.Warnings.Add(warn); uow.SaveChanges(); } @@ -169,14 +169,14 @@ namespace NadekoBot.Modules.Administration.Services { using (var uow = _db.GetDbContext()) { - var cleared = await uow._context.Database.ExecuteSqlRawAsync($@"UPDATE Warnings + var cleared = await uow.Database.ExecuteSqlRawAsync($@"UPDATE Warnings SET Forgiven = 1, ForgivenBy = 'Expiry' WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 0) AND Forgiven = 0 AND DateAdded < datetime('now', (SELECT '-' || WarnExpireHours || ' hours' FROM GuildConfigs as gc WHERE gc.GuildId = Warnings.GuildId));"); - var deleted = await uow._context.Database.ExecuteSqlRawAsync($@"DELETE FROM Warnings + var deleted = await uow.Database.ExecuteSqlRawAsync($@"DELETE FROM Warnings WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 1) AND DateAdded < datetime('now', (SELECT '-' || WarnExpireHours || ' hours' FROM GuildConfigs as gc WHERE gc.GuildId = Warnings.GuildId));"); @@ -191,7 +191,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, inc => inc); + var config = uow.GuildConfigsForId(guildId, inc => inc); if (config.WarnExpireHours == 0) return; @@ -199,7 +199,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND var hours = $"{-config.WarnExpireHours} hours"; if (config.WarnExpireAction == WarnExpireAction.Clear) { - await uow._context.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings + await uow.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings SET Forgiven = 1, ForgivenBy = 'Expiry' WHERE GuildId={guildId} @@ -208,7 +208,7 @@ WHERE GuildId={guildId} } else if (config.WarnExpireAction == WarnExpireAction.Delete) { - await uow._context.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings + await uow.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings WHERE GuildId={guildId} AND DateAdded < datetime('now', {hours})"); } @@ -220,7 +220,7 @@ WHERE GuildId={guildId} public Task GetWarnExpire(ulong guildId) { using var uow = _db.GetDbContext(); - var config = uow._context.GuildConfigsForId(guildId, set => set); + var config = uow.GuildConfigsForId(guildId, set => set); return Task.FromResult(config.WarnExpireHours / 24); } @@ -228,7 +228,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, inc => inc); + var config = uow.GuildConfigsForId(guildId, inc => inc); config.WarnExpireHours = days * 24; config.WarnExpireAction = delete ? WarnExpireAction.Delete : WarnExpireAction.Clear; @@ -246,7 +246,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - return uow._context.Warnings.GetForGuild(gid).GroupBy(x => x.UserId).ToArray(); + return uow.Warnings.GetForGuild(gid).GroupBy(x => x.UserId).ToArray(); } } @@ -254,7 +254,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - return uow._context.Warnings.ForId(gid, userId); + return uow.Warnings.ForId(gid, userId); } } @@ -265,11 +265,11 @@ WHERE GuildId={guildId} { if (index == 0) { - await uow._context.Warnings.ForgiveAll(guildId, userId, moderator); + await uow.Warnings.ForgiveAll(guildId, userId, moderator); } else { - toReturn = uow._context.Warnings.Forgive(guildId, userId, moderator, index - 1); + toReturn = uow.Warnings.Forgive(guildId, userId, moderator, index - 1); } uow.SaveChanges(); } @@ -286,10 +286,10 @@ WHERE GuildId={guildId} using (var uow = _db.GetDbContext()) { - var ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; + var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; var toDelete = ps.Where(x => x.Count == number); - uow._context.RemoveRange(toDelete); + uow.RemoveRange(toDelete); ps.Add(new WarningPunishment() { @@ -310,12 +310,12 @@ WHERE GuildId={guildId} using (var uow = _db.GetDbContext()) { - var ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; + var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; var p = ps.FirstOrDefault(x => x.Count == number); if (p != null) { - uow._context.Remove(p); + uow.Remove(p); uow.SaveChanges(); } } @@ -326,7 +326,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - return uow._context.GuildConfigsForId(guildId, gc => gc.Include(x => x.WarnPunishments)) + return uow.GuildConfigsForId(guildId, gc => gc.Include(x => x.WarnPunishments)) .WarnPunishments .OrderBy(x => x.Count) .ToArray(); @@ -374,7 +374,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - var template = uow._context.BanTemplates + var template = uow.BanTemplates .AsQueryable() .FirstOrDefault(x => x.GuildId == guildId); return template?.Text; @@ -385,7 +385,7 @@ WHERE GuildId={guildId} { using (var uow = _db.GetDbContext()) { - var template = uow._context.BanTemplates + var template = uow.BanTemplates .AsQueryable() .FirstOrDefault(x => x.GuildId == guildId); @@ -394,11 +394,11 @@ WHERE GuildId={guildId} if (template is null) return; - uow._context.Remove(template); + uow.Remove(template); } else if (template == null) { - uow._context.BanTemplates.Add(new BanTemplate() + uow.BanTemplates.Add(new BanTemplate() { GuildId = guildId, Text = text, diff --git a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs index 9a551a3ac..61acd956b 100644 --- a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = db.GetDbContext()) { var guildIds = client.Guilds.Select(x => x.Id).ToList(); - var configs = uow._context.Set() + var configs = uow.Set() .AsQueryable() .Include(x => x.VcRoleInfos) .Where(x => guildIds.Contains(x.GuildId)) @@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services // need to load new guildconfig with vc role included using (var uow = _db.GetDbContext()) { - var configWithVcRole = uow._context.GuildConfigsForId( + var configWithVcRole = uow.GuildConfigsForId( arg.GuildId, set => set.Include(x => x.VcRoleInfos) ); @@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = _db.GetDbContext()) { Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}"); - uow._context.RemoveRange(missingRoles); + uow.RemoveRange(missingRoles); await uow.SaveChangesAsync(); } } @@ -144,11 +144,11 @@ namespace NadekoBot.Modules.Administration.Services guildVcRoles.AddOrUpdate(vcId, role, (key, old) => role); using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos)); + var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos)); var toDelete = conf.VcRoleInfos.FirstOrDefault(x => x.VoiceChannelId == vcId); // remove old one if(toDelete != null) { - uow._context.Remove(toDelete); + uow.Remove(toDelete); } conf.VcRoleInfos.Add(new VcRoleInfo() { @@ -169,9 +169,9 @@ namespace NadekoBot.Modules.Administration.Services using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos)); + var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos)); var toRemove = conf.VcRoleInfos.Where(x => x.VoiceChannelId == vcId).ToList(); - uow._context.RemoveRange(toRemove); + uow.RemoveRange(toRemove); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index f94abffde..adc6b345b 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -90,7 +90,7 @@ namespace NadekoBot.Modules.CustomReactions.Services private async Task ReloadInternal(IReadOnlyList allGuildIds) { using var uow = _db.GetDbContext(); - var guildItems = await uow._context.CustomReactions + var guildItems = await uow.CustomReactions .AsNoTracking() .Where(x => allGuildIds.Contains(x.GuildId.Value)) .ToListAsync(); @@ -107,7 +107,7 @@ namespace NadekoBot.Modules.CustomReactions.Services lock (_gcrWriteLock) { - var globalItems = uow._context + var globalItems = uow .CustomReactions .AsNoTracking() .Where(x => x.GuildId == null || x.GuildId == 0) @@ -195,7 +195,7 @@ namespace NadekoBot.Modules.CustomReactions.Services private async Task OnJoinedGuild(GuildConfig gc) { using var uow = _db.GetDbContext(); - var crs = await uow._context + var crs = await uow .CustomReactions .AsNoTracking() .Where(x => x.GuildId == gc.GuildId) @@ -223,7 +223,7 @@ namespace NadekoBot.Modules.CustomReactions.Services using (var uow = _db.GetDbContext()) { - uow._context.CustomReactions.Add(cr); + uow.CustomReactions.Add(cr); await uow.SaveChangesAsync(); } @@ -235,7 +235,7 @@ namespace NadekoBot.Modules.CustomReactions.Services public async Task EditAsync(ulong? guildId, int id, string message) { using var uow = _db.GetDbContext(); - var cr = uow._context.CustomReactions.GetById(id); + var cr = uow.CustomReactions.GetById(id); if (cr == null || cr.GuildId != guildId) return null; @@ -263,14 +263,14 @@ namespace NadekoBot.Modules.CustomReactions.Services public async Task DeleteAsync(ulong? guildId, int id) { using var uow = _db.GetDbContext(); - var toDelete = uow._context.CustomReactions.GetById(id); + var toDelete = uow.CustomReactions.GetById(id); if (toDelete is null) return null; if ((toDelete.IsGlobal() && guildId == null) || (guildId == toDelete.GuildId)) { - uow._context.CustomReactions.Remove(toDelete); + uow.CustomReactions.Remove(toDelete); await uow.SaveChangesAsync(); await DeleteInternalAsync(guildId, id); return toDelete; @@ -469,7 +469,7 @@ namespace NadekoBot.Modules.CustomReactions.Services { CustomReaction cr; using var uow = _db.GetDbContext(); - cr = uow._context.CustomReactions.GetById(id); + cr = uow.CustomReactions.GetById(id); if (cr is null) return; @@ -587,7 +587,7 @@ namespace NadekoBot.Modules.CustomReactions.Services CustomReaction cr; using (var uow = _db.GetDbContext()) { - cr = uow._context.CustomReactions.GetById(id); + cr = uow.CustomReactions.GetById(id); if (cr is null) return; @@ -605,7 +605,7 @@ namespace NadekoBot.Modules.CustomReactions.Services CustomReaction cr; using (var uow = _db.GetDbContext()) { - cr = uow._context.CustomReactions.GetById(id); + cr = uow.CustomReactions.GetById(id); if (cr is null) return (false, false); if (field == CrField.AutoDelete) @@ -628,7 +628,7 @@ namespace NadekoBot.Modules.CustomReactions.Services public CustomReaction GetCustomReaction(ulong? guildId, int id) { using var uow = _db.GetDbContext(); - var cr = uow._context.CustomReactions.GetById(id); + var cr = uow.CustomReactions.GetById(id); if (cr == null || cr.GuildId != guildId) return null; @@ -638,7 +638,7 @@ namespace NadekoBot.Modules.CustomReactions.Services public int DeleteAllCustomReactions(ulong guildId) { using var uow = _db.GetDbContext(); - var count = uow._context.CustomReactions.ClearFromGuild(guildId); + var count = uow.CustomReactions.ClearFromGuild(guildId); uow.SaveChanges(); _newGuildReactions.TryRemove(guildId, out _); @@ -649,7 +649,7 @@ namespace NadekoBot.Modules.CustomReactions.Services public bool ReactionExists(ulong? guildId, string input) { using var uow = _db.GetDbContext(); - var cr = uow._context.CustomReactions.GetByGuildIdAndInput(guildId, input); + var cr = uow.CustomReactions.GetByGuildIdAndInput(guildId, input); return cr != null; } @@ -705,7 +705,7 @@ namespace NadekoBot.Modules.CustomReactions.Services foreach (var entry in data) { var trigger = entry.Key; - await uow._context.CustomReactions.AddRangeAsync(entry.Value + await uow.CustomReactions.AddRangeAsync(entry.Value .Where(cr => !string.IsNullOrWhiteSpace(cr.Res)) .Select(cr => new CustomReaction() { diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 58afb4d78..c2a22ff5e 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._context.DiscordUser.GetUserCurrency(id)); + return n(uow.DiscordUser.GetUserCurrency(id)); } } @@ -193,7 +193,7 @@ namespace NadekoBot.Modules.Gambling var trs = new List(); using (var uow = _db.GetDbContext()) { - trs = uow._context.CurrencyTransactions.GetPageFor(userId, page); + trs = uow.CurrencyTransactions.GetPageFor(userId, page); } var embed = new EmbedBuilder() @@ -522,7 +522,7 @@ namespace NadekoBot.Modules.Gambling using (var uow = _db.GetDbContext()) { - cleanRichest = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000); + cleanRichest = uow.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._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); + cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); } } @@ -551,7 +551,7 @@ namespace NadekoBot.Modules.Gambling { using (var uow = _db.GetDbContext()) { - toSend = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage); + toSend = uow.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 908857e0a..c3267c965 100644 --- a/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/GamblingService.cs @@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Gambling.Services if (maxDecay == 0) maxDecay = int.MaxValue; - uow._context.Database.ExecuteSqlInterpolated($@" + uow.Database.ExecuteSqlInterpolated($@" UPDATE DiscordUser SET CurrencyAmount= CASE WHEN @@ -80,32 +80,6 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU } }, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); } - - //using (var uow = _db.UnitOfWork) - //{ - // //refund all of the currency users had at stake in gambling games - // //at the time bot was restarted - - // var stakes = uow._context.Set() - // .ToArray(); - - // var userIds = stakes.Select(x => x.UserId).ToArray(); - // var reasons = stakes.Select(x => "Stake-" + x.Source).ToArray(); - // var amounts = stakes.Select(x => x.Amount).ToArray(); - - // _cs.AddBulkAsync(userIds, reasons, amounts, gamble: true).ConfigureAwait(false); - - // foreach (var s in stakes) - // { - // _cs.AddAsync(s.UserId, "Stake-" + s.Source, s.Amount, gamble: true) - // .GetAwaiter() - // .GetResult(); - // } - - // uow._context.Set().RemoveRange(stakes); - // uow.Complete(); - // Log.Information("Refunded {0} users' stakes.", stakes.Length); - //} } public struct EconomyResult @@ -136,11 +110,11 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU using (var uow = _db.GetDbContext()) { - 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._context.DiscordUser.GetUserCurrency(_client.CurrentUser.Id); + cash = uow.DiscordUser.GetTotalCurrency(); + onePercent = uow.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id); + planted = uow.PlantedCurrency.AsQueryable().Sum(x => x.Amount); + waifus = uow.WaifuInfo.GetTotalValue(); + bot = uow.DiscordUser.GetUserCurrency(_client.CurrentUser.Id); } var result = new EconomyResult diff --git a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs index 087deadfc..7ef7735f2 100644 --- a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs @@ -19,8 +19,8 @@ namespace NadekoBot.Modules.Gambling.Services _db = db; } - private IndexedCollection GetEntriesInternal(IUnitOfWork uow, ulong guildId) => - uow._context.GuildConfigsForId( + private IndexedCollection GetEntriesInternal(NadekoContext uow, ulong guildId) => + uow.GuildConfigsForId( guildId, set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items) ) diff --git a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs index 19b94ccf4..77f6ad3e1 100644 --- a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs @@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = db.GetDbContext()) { var guildIds = client.Guilds.Select(x => x.Id).ToList(); - var configs = uow._context.Set() + var configs = uow.Set() .AsQueryable() .Include(x => x.GenerateCurrencyChannelIds) .Where(x => guildIds.Contains(x.GuildId)) @@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Gambling.Services bool enabled; using (var uow = _db.GetDbContext()) { - var guildConfig = uow._context.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds)); + var guildConfig = uow.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds)); var toAdd = new GCChannelId() { ChannelId = cid }; if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd)) @@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Gambling.Services var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd)); if (toDelete != null) { - uow._context.Remove(toDelete); + uow.Remove(toDelete); } _generationChannels.TryRemove(cid); enabled = false; @@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - var chs = uow._context.GuildConfigs.GetGeneratingChannels(); + var chs = uow.GuildConfigs.GetGeneratingChannels(); return chs; } } @@ -270,7 +270,7 @@ namespace NadekoBot.Modules.Gambling.Services pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant(); // gets all plants in this channel with the same password - var entries = uow._context.PlantedCurrency + var entries = uow.PlantedCurrency .AsQueryable() .Where(x => x.ChannelId == ch.Id && pass == x.Password) .ToList(); @@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Gambling.Services amount = entries.Sum(x => x.Amount); ids = entries.Select(x => x.MessageId).ToArray(); // remove them from the database - uow._context.RemoveRange(entries); + uow.RemoveRange(entries); if (amount > 0) @@ -369,7 +369,7 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - uow._context.PlantedCurrency.Add(new PlantedCurrency + uow.PlantedCurrency.Add(new PlantedCurrency { Amount = amount, GuildId = gid, diff --git a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs index 420fb7aca..f32a62384 100644 --- a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs @@ -46,8 +46,8 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = _db.GetDbContext()) { - var waifu = uow._context.WaifuInfo.ByWaifuUserId(waifuId); - var ownerUser = uow._context.GetOrCreateUser(owner); + var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId); + var ownerUser = uow.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._context.GetOrCreateUser(newOwner); + var newOwnerUser = uow.GetOrCreateUser(newOwner); waifu.ClaimerId = newOwnerUser.Id; await uow.SaveChangesAsync(); @@ -96,16 +96,16 @@ namespace NadekoBot.Modules.Gambling.Services var settings = _gss.Data; using (var uow = _db.GetDbContext()) { - var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id); + var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id); if (waifu == null) return settings.Waifu.MinPrice; - var divorces = uow._context.WaifuUpdates.Count(x => x.Old != null && + var divorces = uow.WaifuUpdates.Count(x => x.Old != null && x.Old.UserId == user.Id && x.UpdateType == WaifuUpdateType.Claimed && x.New == null); - var affs = uow._context.WaifuUpdates + var affs = uow.WaifuUpdates .AsQueryable() .Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged && w.New != null) @@ -126,13 +126,13 @@ namespace NadekoBot.Modules.Gambling.Services if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true)) return false; - var affs = uow._context.WaifuUpdates + var affs = uow.WaifuUpdates .AsQueryable() .Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged && w.New != null); - var divorces = uow._context.WaifuUpdates + var divorces = uow.WaifuUpdates .AsQueryable() .Where(x => x.Old != null && x.Old.UserId == user.Id && @@ -140,10 +140,10 @@ namespace NadekoBot.Modules.Gambling.Services x.New == null); //reset changes of heart to 0 - uow._context.WaifuUpdates.RemoveRange(affs); + uow.WaifuUpdates.RemoveRange(affs); //reset divorces to 0 - uow._context.WaifuUpdates.RemoveRange(divorces); - var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id); + uow.WaifuUpdates.RemoveRange(divorces); + var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id); //reset price, remove items //remove owner, remove affinity waifu.Price = 50; @@ -167,26 +167,26 @@ namespace NadekoBot.Modules.Gambling.Services bool isAffinity; using (var uow = _db.GetDbContext()) { - w = uow._context.WaifuInfo.ByWaifuUserId(target.Id); + w = uow.WaifuInfo.ByWaifuUserId(target.Id); isAffinity = (w?.Affinity?.UserId == user.Id); if (w == null) { - var claimer = uow._context.GetOrCreateUser(user); - var waifu = uow._context.GetOrCreateUser(target); + var claimer = uow.GetOrCreateUser(user); + var waifu = uow.GetOrCreateUser(target); if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true)) { result = WaifuClaimResult.NotEnoughFunds; } else { - uow._context.WaifuInfo.Add(w = new WaifuInfo() + uow.WaifuInfo.Add(w = new WaifuInfo() { Waifu = waifu, Claimer = claimer, Affinity = null, Price = amount }); - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = waifu, Old = null, @@ -205,11 +205,11 @@ namespace NadekoBot.Modules.Gambling.Services else { var oldClaimer = w.Claimer; - w.Claimer = uow._context.GetOrCreateUser(user); + w.Claimer = uow.GetOrCreateUser(user); w.Price = amount + (amount / 4); result = WaifuClaimResult.Success; - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = w.Waifu, Old = oldClaimer, @@ -227,11 +227,11 @@ namespace NadekoBot.Modules.Gambling.Services else { var oldClaimer = w.Claimer; - w.Claimer = uow._context.GetOrCreateUser(user); + w.Claimer = uow.GetOrCreateUser(user); w.Price = amount; result = WaifuClaimResult.Success; - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = w.Waifu, Old = oldClaimer, @@ -257,8 +257,8 @@ namespace NadekoBot.Modules.Gambling.Services TimeSpan? remaining = null; using (var uow = _db.GetDbContext()) { - var w = uow._context.WaifuInfo.ByWaifuUserId(user.Id); - var newAff = target == null ? null : uow._context.GetOrCreateUser(target); + var w = uow.WaifuInfo.ByWaifuUserId(user.Id); + var newAff = target == null ? null : uow.GetOrCreateUser(target); if (w?.Affinity?.UserId == target?.Id) { } @@ -267,8 +267,8 @@ namespace NadekoBot.Modules.Gambling.Services } else if (w == null) { - var thisUser = uow._context.GetOrCreateUser(user); - uow._context.WaifuInfo.Add(new WaifuInfo() + var thisUser = uow.GetOrCreateUser(user); + uow.WaifuInfo.Add(new WaifuInfo() { Affinity = newAff, Waifu = thisUser, @@ -277,7 +277,7 @@ namespace NadekoBot.Modules.Gambling.Services }); success = true; - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = thisUser, Old = null, @@ -292,7 +292,7 @@ namespace NadekoBot.Modules.Gambling.Services w.Affinity = newAff; success = true; - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = w.Waifu, Old = oldAff, @@ -311,14 +311,14 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - return uow._context.WaifuInfo.GetTop(9, page * 9); + return uow.WaifuInfo.GetTop(9, page * 9); } } public ulong GetWaifuUserId(ulong ownerId, string name) { using var uow = _db.GetDbContext(); - return uow._context.WaifuInfo.GetWaifuUserId(ownerId, name); + return uow.WaifuInfo.GetWaifuUserId(ownerId, name); } public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId) @@ -329,7 +329,7 @@ namespace NadekoBot.Modules.Gambling.Services WaifuInfo w = null; using (var uow = _db.GetDbContext()) { - w = uow._context.WaifuInfo.ByWaifuUserId(targetId); + w = uow.WaifuInfo.ByWaifuUserId(targetId); var now = DateTime.UtcNow; if (w?.Claimer == null || w.Claimer.UserId != user.Id) result = DivorceResult.NotYourWife; @@ -357,7 +357,7 @@ namespace NadekoBot.Modules.Gambling.Services var oldClaimer = w.Claimer; w.Claimer = null; - uow._context.WaifuUpdates.Add(new WaifuUpdate() + uow.WaifuUpdates.Add(new WaifuUpdate() { User = w.Waifu, Old = oldClaimer, @@ -381,17 +381,17 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = _db.GetDbContext()) { - var w = uow._context.WaifuInfo.ByWaifuUserId(giftedWaifu.Id, + var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id, set => set.Include(x => x.Items) .Include(x => x.Claimer)); if (w == null) { - uow._context.WaifuInfo.Add(w = new WaifuInfo() + uow.WaifuInfo.Add(w = new WaifuInfo() { Affinity = null, Claimer = null, Price = 1, - Waifu = uow._context.GetOrCreateUser(giftedWaifu), + Waifu = uow.GetOrCreateUser(giftedWaifu), }); } @@ -420,7 +420,7 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - var wi = uow._context.GetWaifuInfo(targetId); + var wi = uow.GetWaifuInfo(targetId); if (wi is null) { wi = new WaifuInfoStats @@ -445,7 +445,7 @@ namespace NadekoBot.Modules.Gambling.Services { using (var uow = _db.GetDbContext()) { - var du = uow._context.GetOrCreateUser(target); + var du = uow.GetOrCreateUser(target); return GetFullWaifuInfoAsync(target.Id); } diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index 5e3a80c45..69b6c42ae 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Gambling throw new ArgumentOutOfRangeException(nameof(page)); using var uow = _db.GetDbContext(); - var entries = uow._context.GuildConfigsForId(ctx.Guild.Id, + var entries = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries .ToIndexed(); @@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Gambling ShopEntry entry; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set + var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set .Include(x => x.ShopEntries) .ThenInclude(x => x.Items)); var entries = new IndexedCollection(config.ShopEntries); @@ -165,7 +165,7 @@ namespace NadekoBot.Modules.Gambling { using (var uow = _db.GetDbContext()) { - var x = uow._context.Set().Remove(item); + var x = uow.Set().Remove(item); uow.SaveChanges(); } try @@ -189,7 +189,7 @@ namespace NadekoBot.Modules.Gambling entry.Price).ConfigureAwait(false); using (var uow = _db.GetDbContext()) { - var entries = new IndexedCollection(uow._context.GuildConfigsForId(ctx.Guild.Id, + var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entry = entries.ElementAtOrDefault(index); @@ -235,13 +235,13 @@ namespace NadekoBot.Modules.Gambling }; using (var uow = _db.GetDbContext()) { - var entries = new IndexedCollection(uow._context.GuildConfigsForId(ctx.Guild.Id, + var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries) { entry }; - uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; + uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; uow.SaveChanges(); } await ctx.Channel.EmbedAsync(EntryToEmbed(entry) @@ -263,13 +263,13 @@ namespace NadekoBot.Modules.Gambling }; using (var uow = _db.GetDbContext()) { - var entries = new IndexedCollection(uow._context.GuildConfigsForId(ctx.Guild.Id, + var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries) { entry }; - uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; + uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; uow.SaveChanges(); } await ctx.Channel.EmbedAsync(EntryToEmbed(entry) @@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Gambling bool added = false; using (var uow = _db.GetDbContext()) { - var entries = new IndexedCollection(uow._context.GuildConfigsForId(ctx.Guild.Id, + var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entry = entries.ElementAtOrDefault(index); @@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Gambling ShopEntry removed; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set + var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set .Include(x => x.ShopEntries) .ThenInclude(x => x.Items)); @@ -334,8 +334,8 @@ namespace NadekoBot.Modules.Gambling removed = entries.ElementAtOrDefault(index); if (removed != null) { - uow._context.RemoveRange(removed.Items); - uow._context.Remove(removed); + uow.RemoveRange(removed.Items); + uow.Remove(removed); uow.SaveChanges(); } } diff --git a/src/NadekoBot/Modules/Games/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/CleverBotCommands.cs index 325552ca8..540c348a1 100644 --- a/src/NadekoBot/Modules/Games/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/CleverBotCommands.cs @@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games { using (var uow = _db.GetDbContext()) { - uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false); + uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false); await uow.SaveChangesAsync(); } await ReplyConfirmLocalizedAsync("cleverbot_disabled").ConfigureAwait(false); @@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Games using (var uow = _db.GetDbContext()) { - uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true); + uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true); await uow.SaveChangesAsync(); } diff --git a/src/NadekoBot/Modules/Games/Common/PollRunner.cs b/src/NadekoBot/Modules/Games/Common/PollRunner.cs index a468d1f7c..fcd01d93d 100644 --- a/src/NadekoBot/Modules/Games/Common/PollRunner.cs +++ b/src/NadekoBot/Modules/Games/Common/PollRunner.cs @@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Games.Common finally { _locker.Release(); } using (var uow = _db.GetDbContext()) { - var trackedPoll = uow._context.Poll.FirstOrDefault(x => x.Id == Poll.Id); + var trackedPoll = uow.Poll.FirstOrDefault(x => x.Id == Poll.Id); trackedPoll.Votes.Add(voteObj); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs index 88ed284bb..971223e14 100644 --- a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs +++ b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Games.Services // public void EnsureMigrated() // { // using var uow = _db.GetDbContext(); - // using var conn = uow._context.Database.GetDbConnection(); + // using var conn = uow.Database.GetDbConnection(); // MigrateRaceAnimals(conn); // MigrateEightBall(conn); // } diff --git a/src/NadekoBot/Modules/Games/Services/PollService.cs b/src/NadekoBot/Modules/Games/Services/PollService.cs index c12db6ca6..4f7c7f94e 100644 --- a/src/NadekoBot/Modules/Games/Services/PollService.cs +++ b/src/NadekoBot/Modules/Games/Services/PollService.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Games.Services using (var uow = db.GetDbContext()) { - ActivePolls = uow._context.Poll.GetAllPolls() + ActivePolls = uow.Poll.GetAllPolls() .ToDictionary(x => x.GuildId, x => { var pr = new PollRunner(db, x); @@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Games.Services { using (var uow = _db.GetDbContext()) { - uow._context.Poll.Add(p); + uow.Poll.Add(p); uow.SaveChanges(); } @@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Games.Services pr.OnVoted -= Pr_OnVoted; using var uow = _db.GetDbContext(); - uow._context.RemovePoll(pr.Poll.Id); + uow.RemovePoll(pr.Poll.Id); uow.SaveChanges(); return pr.Poll; diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index 4e76bcf3d..427452e56 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Music using (var uow = _db.GetDbContext()) { - playlists = uow._context.MusicPlaylists.GetPlaylistsOnPage(num); + playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); } var embed = new EmbedBuilder() @@ -78,13 +78,13 @@ namespace NadekoBot.Modules.Music { using (var uow = _db.GetDbContext()) { - var pl = uow._context.MusicPlaylists.FirstOrDefault(x => x.Id == id); + var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id); if (pl != null) { if (_creds.IsOwner(ctx.User) || pl.AuthorId == ctx.User.Id) { - uow._context.MusicPlaylists.Remove(pl); + uow.MusicPlaylists.Remove(pl); await uow.SaveChangesAsync(); success = true; } @@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Music MusicPlaylist mpl; using (var uow = _db.GetDbContext()) { - mpl = uow._context.MusicPlaylists.GetWithSongs(id); + mpl = uow.MusicPlaylists.GetWithSongs(id); } await ctx.SendPaginatedConfirmAsync(page, (cur) => @@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Music AuthorId = ctx.User.Id, Songs = songs.ToList(), }; - uow._context.MusicPlaylists.Add(playlist); + uow.MusicPlaylists.Add(playlist); await uow.SaveChangesAsync(); } @@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Music MusicPlaylist mpl; using (var uow = _db.GetDbContext()) { - mpl = uow._context.MusicPlaylists.GetWithSongs(id); + mpl = uow.MusicPlaylists.GetWithSongs(id); } if (mpl == null) diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index 4ccf03d10..7cf24902f 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -13,7 +13,6 @@ using NadekoBot.Core.Services.Database.Repositories.Impl; using NadekoBot.Modules.Music; using NadekoBot.Services; using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Database.Repositories.Impl; using NadekoBot.Extensions; using Serilog; @@ -352,7 +351,7 @@ namespace NadekoBot.Modules.Music.Services return settings; using var uow = _db.GetDbContext(); - var toReturn = _settings[guildId] = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId); + var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId); await uow.SaveChangesAsync(); return toReturn; @@ -364,7 +363,7 @@ namespace NadekoBot.Modules.Music.Services TState state) { using var uow = _db.GetDbContext(); - var ms = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId); + var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId); action(ms, state); await uow.SaveChangesAsync(); _settings[guildId] = ms; @@ -444,7 +443,7 @@ namespace NadekoBot.Modules.Music.Services public async Task GetMusicQualityAsync(ulong guildId) { using var uow = _db.GetDbContext(); - var settings = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId); + var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId); return settings.QualityPreset; } diff --git a/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs b/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs index 43da0fc32..37b62f3ff 100644 --- a/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs @@ -82,7 +82,7 @@ // { // using (var uow = _db.GetDbContext()) // { -// return uow._context.GuildConfigsForId(guildId, set => set).DefaultMusicVolume; +// return uow.GuildConfigsForId(guildId, set => set).DefaultMusicVolume; // } // }); // } @@ -256,7 +256,7 @@ // bool val; // using (var uow = _db.GetDbContext()) // { -// var gc = uow._context.GuildConfigsForId(id, set => set); +// var gc = uow.GuildConfigsForId(id, set => set); // val = gc.AutoDcFromVc = !gc.AutoDcFromVc; // uow.SaveChanges(); // } @@ -278,7 +278,7 @@ // { // using (var uow = _db.GetDbContext()) // { -// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings; +// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings; // ms.MusicChannelId = cid; // uow.SaveChanges(); // } @@ -288,7 +288,7 @@ // { // using (var uow = _db.GetDbContext()) // { -// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings; +// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings; // ms.SongAutoDelete = val; // uow.SaveChanges(); // } diff --git a/src/NadekoBot/Modules/Music/_OldMusic.cs b/src/NadekoBot/Modules/Music/_OldMusic.cs index 7ffcb3114..83bb2706b 100644 --- a/src/NadekoBot/Modules/Music/_OldMusic.cs +++ b/src/NadekoBot/Modules/Music/_OldMusic.cs @@ -395,7 +395,7 @@ // } // using (var uow = _db.GetDbContext()) // { -// uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f; +// uow.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f; // uow.SaveChanges(); // } // await ReplyConfirmLocalizedAsync("defvol_set", val).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs index 1b552a437..2ad16e59c 100644 --- a/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs @@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Permissions var name = command.Name.ToLowerInvariant(); using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns)); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns)); var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); var toDelete = config.CommandCooldowns.FirstOrDefault(cc => cc.CommandName == name); if (toDelete != null) - uow._context.Set().Remove(toDelete); + uow.Set().Remove(toDelete); localSet.RemoveWhere(cc => cc.CommandName == name); if (secs != 0) { diff --git a/src/NadekoBot/Modules/Permissions/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/FilterCommands.cs index 91d31babe..e4339d55a 100644 --- a/src/NadekoBot/Modules/Permissions/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/FilterCommands.cs @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Permissions bool enabled; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterInvites = !config.FilterInvites; await uow.SaveChangesAsync(); } @@ -69,7 +69,7 @@ namespace NadekoBot.Modules.Permissions FilterChannelId removed; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds)); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds)); var match = new FilterChannelId() { ChannelId = channel.Id @@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions } else { - uow._context.Remove(removed); + uow.Remove(removed); } await uow.SaveChangesAsync(); } @@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Permissions bool enabled; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterLinks = !config.FilterLinks; await uow.SaveChangesAsync(); } @@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Permissions FilterLinksChannelId removed; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds)); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds)); var match = new FilterLinksChannelId() { ChannelId = channel.Id @@ -147,7 +147,7 @@ namespace NadekoBot.Modules.Permissions } else { - uow._context.Remove(removed); + uow.Remove(removed); } await uow.SaveChangesAsync(); } @@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Permissions bool enabled; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterWords = !config.FilterWords; await uow.SaveChangesAsync(); } @@ -199,7 +199,7 @@ namespace NadekoBot.Modules.Permissions FilterChannelId removed; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds)); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds)); var match = new FilterChannelId() { @@ -212,7 +212,7 @@ namespace NadekoBot.Modules.Permissions } else { - uow._context.Remove(removed); + uow.Remove(removed); } await uow.SaveChangesAsync(); } @@ -243,7 +243,7 @@ namespace NadekoBot.Modules.Permissions FilteredWord removed; using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords)); + var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords)); removed = config.FilteredWords.FirstOrDefault(fw => fw.Word.Trim().ToLowerInvariant() == word); @@ -251,7 +251,7 @@ namespace NadekoBot.Modules.Permissions config.FilteredWords.Add(new FilteredWord() { Word = word }); else { - uow._context.Remove(removed); + uow.Remove(removed); } await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index aad21c52a..0d839e2d4 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Permissions { using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); + var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); if (action == null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle. config.VerbosePermissions = action.Value; await uow.SaveChangesAsync(); @@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Permissions using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); + var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); config.PermissionRole = role.Id.ToString(); uow.SaveChanges(); _service.UpdateCache(config); @@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Permissions { using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); + var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); config.PermissionRole = null; await uow.SaveChangesAsync(); _service.UpdateCache(config); @@ -148,11 +148,11 @@ namespace NadekoBot.Modules.Permissions Permissionv2 p; using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); + var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var permsCol = new PermissionsCollection(config.Permissions); p = permsCol[index]; permsCol.RemoveAt(index); - uow._context.Remove(p); + uow.Remove(p); await uow.SaveChangesAsync(); _service.UpdateCache(config); } @@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Permissions Permissionv2 fromPerm; using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); + var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var permsCol = new PermissionsCollection(config.Permissions); var fromFound = from < permsCol.Count; diff --git a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs index 175dcf6af..7d1ad46e0 100644 --- a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Permissions.Services public void Reload(bool publish = true) { using var uow = _db.GetDbContext(); - var toPublish = uow._context.Blacklist.AsNoTracking().ToArray(); + var toPublish = uow.Blacklist.AsNoTracking().ToArray(); _blacklist = toPublish; if (publish) { @@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Permissions.Services using var uow = _db.GetDbContext(); var item = new BlacklistEntry { ItemId = id, Type = type }; - uow._context.Blacklist.Add(item); + uow.Blacklist.Add(item); uow.SaveChanges(); Reload(true); @@ -85,11 +85,11 @@ namespace NadekoBot.Modules.Permissions.Services public void UnBlacklist(BlacklistType type, ulong id) { using var uow = _db.GetDbContext(); - var toRemove = uow._context.Blacklist + var toRemove = uow.Blacklist .FirstOrDefault(bi => bi.ItemId == id && bi.Type == type); if (!(toRemove is null)) - uow._context.Blacklist.Remove(toRemove); + uow.Blacklist.Remove(toRemove); uow.SaveChanges(); @@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Permissions.Services { using (var uow = _db.GetDbContext()) { - var bc = uow._context.Blacklist; + var bc = uow.Blacklist; //blacklist the users bc.AddRange(toBlacklist.Select(x => new BlacklistEntry @@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Permissions.Services })); //clear their currencies - uow._context.DiscordUser.RemoveFromMany(toBlacklist); + uow.DiscordUser.RemoveFromMany(toBlacklist); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs index af57d6024..69bed43fc 100644 --- a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Permissions.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FilteredWords) .Include(x => x.FilterWordsChannelIds)); @@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions.Services using(var uow = db.GetDbContext()) { var ids = client.GetGuildIds(); - var configs = uow._context.Set() + var configs = uow.Set() .AsQueryable() .Include(x => x.FilteredWords) .Include(x => x.FilterLinksChannelIds) diff --git a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs index e291cddfa..f12c0497f 100644 --- a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs @@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Permissions.Services using (var uow = _db.GetDbContext()) { - foreach (var x in uow._context.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList())) + foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList())) { Cache.TryAdd(x.GuildId, new PermissionCache() { @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Permissions.Services { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(guildId, + var config = uow.GuildConfigsForId(guildId, set => set.Include(x => x.Permissions)); UpdateCache(config); } @@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Permissions.Services { using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(guildId); + var config = uow.GcWithPermissionsv2For(guildId); //var orderedPerms = new PermissionsCollection(config.Permissions); var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest foreach (var perm in perms) @@ -175,7 +175,7 @@ namespace NadekoBot.Modules.Permissions.Services { using (var uow = _db.GetDbContext()) { - var config = uow._context.GcWithPermissionsv2For(guildId); + var config = uow.GcWithPermissionsv2For(guildId); config.Permissions = Permissionv2.GetDefaultPermlist; await uow.SaveChangesAsync(); UpdateCache(config); diff --git a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs index a2fe15047..3a6459fca 100644 --- a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs @@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches.Services using (var uow = db.GetDbContext()) { var guildConfigIds = bot.AllGuildConfigs.Select(x => x.Id).ToList(); - _subs = uow._context.GuildConfigs + _subs = uow.GuildConfigs .AsQueryable() .Where(x => guildConfigIds.Contains(x.Id)) .Include(x => x.FeedSubs) @@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Searches.Services { using (var uow = _db.GetDbContext()) { - return uow._context.GuildConfigsForId(guildId, + return uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs) .ThenInclude(x => x.GuildConfig)) .FeedSubs @@ -188,7 +188,7 @@ namespace NadekoBot.Modules.Searches.Services using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs) .ThenInclude(x => x.GuildConfig)); @@ -224,7 +224,7 @@ namespace NadekoBot.Modules.Searches.Services using (var uow = _db.GetDbContext()) { - var items = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs)) + var items = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs)) .FeedSubs .OrderBy(x => x.Id) .ToList(); @@ -237,7 +237,7 @@ namespace NadekoBot.Modules.Searches.Services old.Remove(toRemove); return old; }); - uow._context.Remove(toRemove); + uow.Remove(toRemove); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs index 7fd91c9c1..57bbf1e22 100644 --- a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs @@ -410,7 +410,7 @@ namespace NadekoBot.Modules.Searches.Services bool added; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags)); if (gc.NsfwBlacklistedTags.Add(tagObj)) added = true; else @@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Searches.Services gc.NsfwBlacklistedTags.Remove(tagObj); var toRemove = gc.NsfwBlacklistedTags.FirstOrDefault(x => x.Equals(tagObj)); if (toRemove != null) - uow._context.Remove(toRemove); + uow.Remove(toRemove); added = false; } var newTags = new HashSet(gc.NsfwBlacklistedTags.Select(x => x.Tag)); diff --git a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs index 63c802361..5dc11fcce 100644 --- a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs @@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Searches.Services using (var uow = db.GetDbContext()) { var ids = client.GetGuildIds(); - var guildConfigs = uow._context.Set() + var guildConfigs = uow.Set() .AsQueryable() .Include(x => x.FollowedStreams) .Where(x => ids.Contains(x.GuildId)) @@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Searches.Services // shard 0 will keep track of when there are no more guilds which track a stream if (client.ShardId == 0) { - var allFollowedStreams = uow._context.Set() + var allFollowedStreams = uow.Set() .AsQueryable() .ToList(); @@ -132,12 +132,12 @@ namespace NadekoBot.Modules.Searches.Services Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " + $"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}"); - var toDelete = uow._context.Set() + var toDelete = uow.Set() .AsQueryable() .Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username)) .ToList(); - uow._context.RemoveRange(toDelete); + uow.RemoveRange(toDelete); uow.SaveChanges(); foreach(var loginToDelete in kvp.Value) @@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Searches.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigs + var gc = uow.GuildConfigs .AsQueryable() .Include(x => x.FollowedStreams) .FirstOrDefault(x => x.GuildId == guildConfig.GuildId); @@ -320,7 +320,7 @@ namespace NadekoBot.Modules.Searches.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams)); + var gc = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams)); _offlineNotificationServers.TryRemove(gc.GuildId); @@ -342,7 +342,7 @@ namespace NadekoBot.Modules.Searches.Services int count; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); count = gc.FollowedStreams.Count; gc.FollowedStreams.Clear(); uow.SaveChanges(); @@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Searches.Services FollowedStream fs; using (var uow = _db.GetDbContext()) { - var fss = uow._context.Set() + var fss = uow.Set() .AsQueryable() .Where(x => x.GuildId == guildId) .OrderBy(x => x.Id) @@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Searches.Services return null; fs = fss[index]; - uow._context.Remove(fs); + uow.Remove(fs); await uow.SaveChangesAsync(); @@ -411,7 +411,7 @@ namespace NadekoBot.Modules.Searches.Services FollowedStream fs; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); // add it to the database fs = new FollowedStream() @@ -481,7 +481,7 @@ namespace NadekoBot.Modules.Searches.Services bool newValue; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); newValue = gc.NotifyStreamOffline = !gc.NotifyStreamOffline; uow.SaveChanges(); @@ -530,7 +530,7 @@ namespace NadekoBot.Modules.Searches.Services { using (var uow = _db.GetDbContext()) { - var fss = uow._context.Set() + var fss = uow.Set() .AsQueryable() .Where(x => x.GuildId == guildId) .OrderBy(x => x.Id) @@ -564,7 +564,7 @@ namespace NadekoBot.Modules.Searches.Services { using var uow = _db.GetDbContext(); - var all = uow._context.Set() + var all = uow.Set() .ToList(); if (all.Count == 0) diff --git a/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs b/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs index c913afd70..4440696ca 100644 --- a/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs +++ b/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs @@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Searches.Services // // using(var uow = _db.GetDbContext()) // { - // var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels)); + // var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels)); // // // see if this yt channel was already followed on this discord channel // var oldObj = gc.YtFollowedChannels diff --git a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs index a9b68d38f..51697308c 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs @@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Searches List streams = new List(); using (var uow = _db.GetDbContext()) { - var all = uow._context + var all = uow .GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) .FollowedStreams .OrderBy(x => x.Id) diff --git a/src/NadekoBot/Modules/Utility/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/CommandMapCommands.cs index 4805728ea..f9664e4fa 100644 --- a/src/NadekoBot/Modules/Utility/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/CommandMapCommands.cs @@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Utility using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); + var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); var toAdd = new CommandAlias() { Mapping = mapping, @@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Utility }; var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger); if (tr != null) - uow._context.Set().Remove(tr); + uow.Set().Remove(tr); uow.SaveChanges(); } @@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Utility { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); + var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); config.CommandAliases.Add(new CommandAlias() { Mapping = mapping, @@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Utility { using (var uow = _db.GetDbContext()) { - var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); + var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); var toAdd = new CommandAlias() { Mapping = mapping, @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Utility }; var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger); if (toRemove.Any()) - uow._context.RemoveRange(toRemove.ToArray()); + uow.RemoveRange(toRemove.ToArray()); config.CommandAliases.Add(toAdd); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 3bd9038a8..e3ee66650 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -12,7 +12,6 @@ using System.Threading.Tasks; using NadekoBot.Core.Services; using NadekoBot.Core.Services.Database.Models; using NadekoBot.Core.Services.Database.Repositories.Impl; -using NadekoBot.Services.Database.Repositories.Impl; using NadekoBot.Db; namespace NadekoBot.Modules.Utility @@ -47,7 +46,7 @@ namespace NadekoBot.Modules.Utility IEnumerable quotes; using (var uow = _db.GetDbContext()) { - quotes = uow._context.Quotes.GetGroup(ctx.Guild.Id, page, order); + quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order); } if (quotes.Any()) @@ -70,7 +69,7 @@ namespace NadekoBot.Modules.Utility Quote quote; using (var uow = _db.GetDbContext()) { - quote = await uow._context.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword); + quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword); //if (quote != null) //{ // quote.UseCount += 1; @@ -102,7 +101,7 @@ namespace NadekoBot.Modules.Utility Quote quote; using (var uow = _db.GetDbContext()) { - quote = uow._context.Quotes.GetById(id); + quote = uow.Quotes.GetById(id); if (quote.GuildId != Context.Guild.Id) quote = null; } @@ -141,7 +140,7 @@ namespace NadekoBot.Modules.Utility Quote keywordquote; using (var uow = _db.GetDbContext()) { - keywordquote = await uow._context.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); + keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); } if (keywordquote == null) @@ -166,7 +165,7 @@ namespace NadekoBot.Modules.Utility using (var uow = _db.GetDbContext()) { - quote = uow._context.Quotes.GetById(id); + quote = uow.Quotes.GetById(id); } if (quote is null || quote.GuildId != ctx.Guild.Id) @@ -203,7 +202,7 @@ namespace NadekoBot.Modules.Utility Quote q; using (var uow = _db.GetDbContext()) { - uow._context.Quotes.Add(q = new Quote + uow.Quotes.Add(q = new Quote { AuthorId = ctx.Message.Author.Id, AuthorName = ctx.Message.Author.Username, @@ -226,7 +225,7 @@ namespace NadekoBot.Modules.Utility string response; using (var uow = _db.GetDbContext()) { - var q = uow._context.Quotes.GetById(id); + var q = uow.Quotes.GetById(id); if ((q?.GuildId != ctx.Guild.Id) || (!isAdmin && q.AuthorId != ctx.Message.Author.Id)) { @@ -234,7 +233,7 @@ namespace NadekoBot.Modules.Utility } else { - uow._context.Quotes.Remove(q); + uow.Quotes.Remove(q); await uow.SaveChangesAsync(); success = true; response = GetText("quote_deleted", id); @@ -258,7 +257,7 @@ namespace NadekoBot.Modules.Utility using (var uow = _db.GetDbContext()) { - uow._context.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant()); + uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant()); await uow.SaveChangesAsync(); } diff --git a/src/NadekoBot/Modules/Utility/RemindCommands.cs b/src/NadekoBot/Modules/Utility/RemindCommands.cs index 0b4587e3b..53b460a66 100644 --- a/src/NadekoBot/Modules/Utility/RemindCommands.cs +++ b/src/NadekoBot/Modules/Utility/RemindCommands.cs @@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Utility List rems; using (var uow = _db.GetDbContext()) { - rems = uow._context.Reminders.RemindersFor(ctx.User.Id, page) + rems = uow.Reminders.RemindersFor(ctx.User.Id, page) .ToList(); } @@ -133,13 +133,13 @@ namespace NadekoBot.Modules.Utility Reminder rem = null; using (var uow = _db.GetDbContext()) { - var rems = uow._context.Reminders.RemindersFor(ctx.User.Id, index / 10) + var rems = uow.Reminders.RemindersFor(ctx.User.Id, index / 10) .ToList(); var pageIndex = index % 10; if (rems.Count > pageIndex) { rem = rems[pageIndex]; - uow._context.Reminders.Remove(rem); + uow.Reminders.Remove(rem); uow.SaveChanges(); } } @@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Utility using (var uow = _db.GetDbContext()) { - uow._context.Reminders.Add(rem); + uow.Reminders.Add(rem); await uow.SaveChangesAsync(); } diff --git a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs index b2d92d30e..6c4e1adfa 100644 --- a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs +++ b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs @@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Utility.Services using (var uow = db.GetDbContext()) { var guildIds = client.Guilds.Select(x => x.Id).ToList(); - var configs = uow._context.Set() + var configs = uow.Set() .Include(gc => gc.CommandAliases) .Where(x => guildIds.Contains(x.GuildId)) .ToList(); @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Utility.Services int count; using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases)); + var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases)); count = gc.CommandAliases.Count; gc.CommandAliases.Clear(); uow.SaveChanges(); diff --git a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs index e8bdd87c4..4453060e0 100644 --- a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs @@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Utility.Services using (var uow = _db.GetDbContext()) { - var users = uow._context.Set(); + var users = uow.Set(); var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id); if (usr == null) diff --git a/src/NadekoBot/Modules/Utility/Services/RemindService.cs b/src/NadekoBot/Modules/Utility/Services/RemindService.cs index a62659e5b..31a912a35 100644 --- a/src/NadekoBot/Modules/Utility/Services/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RemindService.cs @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility.Services { using (var uow = _db.GetDbContext()) { - uow._context.Set() + uow.Set() .RemoveRange(reminders); await uow.SaveChangesAsync(); @@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Utility.Services { using (var uow = _db.GetDbContext()) { - return uow._context.Reminders + return uow.Reminders .FromSqlInterpolated($"select * from reminders where ((serverid >> 22) % {_creds.TotalShards}) == {_client.ShardId} and \"when\" < {now};") .ToListAsync(); } diff --git a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs index af22ad4f5..8515055c3 100644 --- a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs @@ -40,8 +40,7 @@ namespace NadekoBot.Modules.Utility.Services _client = client; var uow = _db.GetDbContext(); - var shardRepeaters = uow - ._context + var shardRepeaters = uow .Set() .FromSqlInterpolated($@"select * from repeaters where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") @@ -133,7 +132,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") { using var uow = _db.GetDbContext(); - var toTrigger = await uow._context.Repeaters + var toTrigger = await uow.Repeaters .AsNoTracking() .Skip(index) .FirstOrDefaultAsyncEF(x => x.GuildId == guildId); @@ -290,7 +289,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") _noRedundant.TryRemove(r.Id); using var uow = _db.GetDbContext(); - await uow._context + await uow .Repeaters .DeleteAsync(x => x.Id == r.Id); @@ -313,7 +312,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId) { using var uow = _db.GetDbContext(); - await uow._context.Repeaters + await uow.Repeaters .AsQueryable() .Where(x => x.Id == repeaterId) .UpdateAsync(rep => new Repeater() @@ -345,8 +344,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") using var uow = _db.GetDbContext(); - if (await uow._context.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS) - uow._context.Repeaters.Add(rep); + if (await uow.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS) + uow.Repeaters.Add(rep); else return null; @@ -365,7 +364,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") throw new ArgumentOutOfRangeException(nameof(index)); using var uow = _db.GetDbContext(); - var toRemove = await uow._context.Repeaters + var toRemove = await uow.Repeaters .AsNoTracking() .Skip(index) .FirstOrDefaultAsyncEF(x => x.GuildId == guildId); @@ -380,7 +379,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") return null; _noRedundant.TryRemove(toRemove.Id); - uow._context.Repeaters.Remove(toRemove); + uow.Repeaters.Remove(toRemove); await uow.SaveChangesAsync(); return removed; } @@ -396,7 +395,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") public async Task ToggleRedundantAsync(ulong guildId, int index) { using var uow = _db.GetDbContext(); - var toToggle = await uow._context + var toToggle = await uow .Repeaters .AsQueryable() .Skip(index) diff --git a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs index 4a1bbc5c7..05f5e0401 100644 --- a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs +++ b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Utility.Services bool success = false; using (var uow = _db.GetDbContext()) { - var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); + var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); if (listType == StreamRoleListType.Whitelist) { @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Utility.Services var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj)); if (toDelete != null) { - uow._context.Remove(toDelete); + uow.Remove(toDelete); success = true; } } @@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Utility.Services using (var uow = _db.GetDbContext()) { - var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); + var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); streamRoleSettings.Keyword = keyword; UpdateCache(guild.Id, streamRoleSettings); @@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Utility.Services StreamRoleSettings setting; using (var uow = _db.GetDbContext()) { - setting = uow._context.GetStreamRoleSettings(guildId); + setting = uow.GetStreamRoleSettings(guildId); } UpdateCache(guildId, setting); @@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility.Services StreamRoleSettings setting; using (var uow = _db.GetDbContext()) { - var streamRoleSettings = uow._context.GetStreamRoleSettings(fromRole.Guild.Id); + var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id); streamRoleSettings.Enabled = true; streamRoleSettings.AddRoleId = addRole.Id; @@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Utility.Services { using (var uow = _db.GetDbContext()) { - var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); + var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); streamRoleSettings.Enabled = false; streamRoleSettings.AddRoleId = 0; streamRoleSettings.FromRoleId = 0; diff --git a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs index 41ae00f8d..4fad8dcaa 100644 --- a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Utility.Services { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); if (enabled==null) enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it. diff --git a/src/NadekoBot/Modules/Xp/Services/ClubService.cs b/src/NadekoBot/Modules/Xp/Services/ClubService.cs index 5385be5f0..a67d803bc 100644 --- a/src/NadekoBot/Modules/Xp/Services/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Services/ClubService.cs @@ -29,8 +29,8 @@ namespace NadekoBot.Modules.Xp.Services club = null; using var uow = _db.GetDbContext(); - var du = uow._context.GetOrCreateUser(user); - uow._context.SaveChanges(); + var du = uow.GetOrCreateUser(user); + uow.SaveChanges(); var xp = new LevelStats(du.TotalXp); if (xp.Level >= 5 && du.Club == null) @@ -39,17 +39,17 @@ namespace NadekoBot.Modules.Xp.Services du.Club = new ClubInfo() { Name = clubName, - Discrim = uow._context.Clubs.GetNextDiscrim(clubName), + Discrim = uow.Clubs.GetNextDiscrim(clubName), Owner = du, }; - uow._context.Clubs.Add(du.Club); - uow._context.SaveChanges(); + uow.Clubs.Add(du.Club); + uow.SaveChanges(); } else return false; - uow._context.Set() - .RemoveRange(uow._context.Set() + uow.Set() + .RemoveRange(uow.Set() .AsQueryable() .Where(x => x.UserId == du.Id)); club = du.Club; @@ -63,8 +63,8 @@ namespace NadekoBot.Modules.Xp.Services ClubInfo club; using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByOwner(from.Id); - var newOwnerUser = uow._context.GetOrCreateUser(newOwner); + club = uow.Clubs.GetByOwner(from.Id); + var newOwnerUser = uow.GetOrCreateUser(newOwner); if (club == null || club.Owner.UserId != from.Id || @@ -84,8 +84,8 @@ namespace NadekoBot.Modules.Xp.Services bool newState; using (var uow = _db.GetDbContext()) { - var club = uow._context.Clubs.GetByOwner(owner.Id); - var adminUser = uow._context.GetOrCreateUser(toAdmin); + var club = uow.Clubs.GetByOwner(owner.Id); + var adminUser = uow.GetOrCreateUser(toAdmin); if (club == null || club.Owner.UserId != owner.Id || !club.Users.Contains(adminUser)) @@ -103,7 +103,7 @@ namespace NadekoBot.Modules.Xp.Services public ClubInfo GetClubByMember(IUser user) { using var uow = _db.GetDbContext(); - var member = uow._context.Clubs.GetByMember(user.Id); + var member = uow.Clubs.GetByMember(user.Id); return member; } @@ -121,7 +121,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { - var club = uow._context.Clubs.GetByOwner(ownerUserId); + var club = uow.Clubs.GetByOwner(ownerUserId); if (club == null) return false; @@ -148,7 +148,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByName(name, discrim); + club = uow.Clubs.GetByName(name, discrim); if (club == null) return false; else @@ -160,8 +160,8 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow._context.GetOrCreateUser(user); - uow._context.SaveChanges(); + var du = uow.GetOrCreateUser(user); + uow.SaveChanges(); if (du.Club != null || new LevelStats(du.TotalXp).Level < club.MinimumLevelReq @@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Xp.Services UserId = du.Id, }; - uow._context.Set().Add(app); + uow.Set().Add(app); uow.SaveChanges(); } @@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Xp.Services discordUser = null; using (var uow = _db.GetDbContext()) { - var club = uow._context.Clubs.GetByOwnerOrAdmin(clubOwnerUserId); + var club = uow.Clubs.GetByOwnerOrAdmin(clubOwnerUserId); if (club == null) return false; @@ -204,8 +204,8 @@ namespace NadekoBot.Modules.Xp.Services club.Applicants.Remove(applicant); //remove that user's all other applications - uow._context.Set() - .RemoveRange(uow._context.Set() + uow.Set() + .RemoveRange(uow.Set() .AsQueryable() .Where(x => x.UserId == applicant.User.Id)); @@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.Clubs.GetByOwnerOrAdmin(ownerUserId); + return uow.Clubs.GetByOwnerOrAdmin(ownerUserId); } } @@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow._context.GetOrCreateUser(user); + var du = uow.GetOrCreateUser(user); if (du.Club == null || du.Club.OwnerId == du.Id) return false; @@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { - var club = uow._context.Clubs.GetByOwner(userId); + var club = uow.Clubs.GetByOwner(userId); if (club == null) return false; @@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var club = uow._context.Clubs.GetByOwner(userId); + var club = uow.Clubs.GetByOwner(userId); if (club == null) return false; @@ -275,11 +275,11 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByOwner(userId); + club = uow.Clubs.GetByOwner(userId); if (club == null) return false; - uow._context.Clubs.Remove(club); + uow.Clubs.Remove(club); uow.SaveChanges(); } return true; @@ -289,7 +289,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByOwnerOrAdmin(bannerId); + club = uow.Clubs.GetByOwnerOrAdmin(bannerId); if (club == null) return false; @@ -322,7 +322,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByOwnerOrAdmin(ownerUserId); + club = uow.Clubs.GetByOwnerOrAdmin(ownerUserId); if (club == null) return false; @@ -341,7 +341,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - club = uow._context.Clubs.GetByOwnerOrAdmin(kickerId); + club = uow.Clubs.GetByOwnerOrAdmin(kickerId); if (club == null) return false; @@ -368,7 +368,7 @@ namespace NadekoBot.Modules.Xp.Services throw new ArgumentOutOfRangeException(nameof(page)); using var uow = _db.GetDbContext(); - return uow._context.Clubs.GetClubLeaderboardPage(page); + return uow.Clubs.GetClubLeaderboardPage(page); } } } diff --git a/src/NadekoBot/Modules/Xp/Services/XpConfigMigrator.cs b/src/NadekoBot/Modules/Xp/Services/XpConfigMigrator.cs index 28e08a6af..311f180d9 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpConfigMigrator.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpConfigMigrator.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Xp.Services public void EnsureMigrated() { using var uow = _db.GetDbContext(); - using var conn = uow._context.Database.GetDbConnection(); + using var conn = uow.Database.GetDbConnection(); Migrate(conn); } diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index d14d655e0..f696080cd 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -167,8 +167,8 @@ namespace NadekoBot.Modules.Xp.Services //2. (better but much harder) Move everything to the database, and get old and new xp // amounts for every user (in order to give rewards) - var usr = uow._context.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id); - var du = uow._context.GetOrCreateUser(item.Key.User); + var usr = uow.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id); + var du = uow.GetOrCreateUser(item.Key.User); var globalXp = du.TotalXp; var oldGlobalLevelData = new LevelStats(globalXp); @@ -201,13 +201,13 @@ namespace NadekoBot.Modules.Xp.Services //give role if (!roleRewards.TryGetValue(usr.GuildId, out var rrews)) { - rrews = uow._context.XpSettingsFor(usr.GuildId).RoleRewards.ToList(); + rrews = uow.XpSettingsFor(usr.GuildId).RoleRewards.ToList(); roleRewards.Add(usr.GuildId, rrews); } if (!curRewards.TryGetValue(usr.GuildId, out var crews)) { - crews = uow._context.XpSettingsFor(usr.GuildId).CurrencyRewards.ToList(); + crews = uow.XpSettingsFor(usr.GuildId).CurrencyRewards.ToList(); curRewards.Add(usr.GuildId, crews); } @@ -317,14 +317,14 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var settings = uow._context.XpSettingsFor(guildId); + var settings = uow.XpSettingsFor(guildId); if (amount <= 0) { var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level); if (toRemove != null) { - uow._context.Remove(toRemove); + uow.Remove(toRemove); settings.CurrencyRewards.Remove(toRemove); } } @@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.XpSettingsFor(id) + return uow.XpSettingsFor(id) .CurrencyRewards .ToArray(); } @@ -359,7 +359,7 @@ namespace NadekoBot.Modules.Xp.Services public IEnumerable GetRoleRewards(ulong id) { using var uow = _db.GetDbContext(); - return uow._context.XpSettingsFor(id) + return uow.XpSettingsFor(id) .RoleRewards .ToArray(); } @@ -367,12 +367,12 @@ namespace NadekoBot.Modules.Xp.Services public void ResetRoleReward(ulong guildId, int level) { using var uow = _db.GetDbContext(); - var settings = uow._context.XpSettingsFor(guildId); + var settings = uow.XpSettingsFor(guildId); var toRemove = settings.RoleRewards.FirstOrDefault(x => x.Level == level); if (toRemove != null) { - uow._context.Remove(toRemove); + uow.Remove(toRemove); settings.RoleRewards.Remove(toRemove); } @@ -382,7 +382,7 @@ namespace NadekoBot.Modules.Xp.Services public void SetRoleReward(ulong guildId, int level, ulong roleId, bool remove) { using var uow = _db.GetDbContext(); - var settings = uow._context.XpSettingsFor(guildId); + var settings = uow.XpSettingsFor(guildId); var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level); @@ -409,7 +409,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.UserXpStats.GetUsersFor(guildId, page); + return uow.UserXpStats.GetUsersFor(guildId, page); } } @@ -417,7 +417,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.UserXpStats.GetTopUserXps(guildId, count); + return uow.UserXpStats.GetTopUserXps(guildId, count); } } @@ -425,7 +425,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.DiscordUser.GetUsersXpLeaderboardFor(page); + return uow.DiscordUser.GetUsersXpLeaderboardFor(page); } } @@ -433,7 +433,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var user = uow._context.GetOrCreateUserXpStats(guildId, userId); + var user = uow.GetOrCreateUserXpStats(guildId, userId); user.NotifyOnLevelUp = type; await uow.SaveChangesAsync(); } @@ -443,7 +443,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var user = uow._context.GetOrCreateUserXpStats(guildId, userId); + var user = uow.GetOrCreateUserXpStats(guildId, userId); return user.NotifyOnLevelUp; } } @@ -452,7 +452,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - return uow._context.GetOrCreateUser(user).NotifyOnLevelUp; + return uow.GetOrCreateUser(user).NotifyOnLevelUp; } } @@ -460,7 +460,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var du = uow._context.GetOrCreateUser(user); + var du = uow.GetOrCreateUser(user); du.NotifyOnLevelUp = type; await uow.SaveChangesAsync(); } @@ -657,7 +657,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var usr = uow._context.GetOrCreateUserXpStats(guildId, userId); + var usr = uow.GetOrCreateUserXpStats(guildId, userId); usr.AwardedXp += amount; @@ -706,11 +706,11 @@ namespace NadekoBot.Modules.Xp.Services int guildRank; using (var uow = _db.GetDbContext()) { - du = uow._context.GetOrCreateUser(user); + du = uow.GetOrCreateUser(user); totalXp = du.TotalXp; - globalRank = uow._context.DiscordUser.GetUserGlobalRank(user.Id); - guildRank = uow._context.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId); - stats = uow._context.GetOrCreateUserXpStats(user.GuildId, user.Id); + globalRank = uow.DiscordUser.GetUserGlobalRank(user.Id); + guildRank = uow.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId); + stats = uow.GetOrCreateUserXpStats(user.GuildId, user.Id); await uow.SaveChangesAsync(); } @@ -747,7 +747,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - var xpSetting = uow._context.XpSettingsFor(id); + var xpSetting = uow.XpSettingsFor(id); if (_excludedServers.Add(id)) { xpSetting.ServerExcluded = true; @@ -767,7 +767,7 @@ namespace NadekoBot.Modules.Xp.Services var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet()); using (var uow = _db.GetDbContext()) { - var xpSetting = uow._context.XpSettingsFor(guildId); + var xpSetting = uow.XpSettingsFor(guildId); var excludeObj = new ExcludedItem { ItemId = rId, @@ -790,7 +790,7 @@ namespace NadekoBot.Modules.Xp.Services var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj)); if (toDelete != null) { - uow._context.Remove(toDelete); + uow.Remove(toDelete); uow.SaveChanges(); } @@ -804,7 +804,7 @@ namespace NadekoBot.Modules.Xp.Services var channels = _excludedChannels.GetOrAdd(guildId, _ => new ConcurrentHashSet()); using (var uow = _db.GetDbContext()) { - var xpSetting = uow._context.XpSettingsFor(guildId); + var xpSetting = uow.XpSettingsFor(guildId); var excludeObj = new ExcludedItem { ItemId = chId, @@ -1200,7 +1200,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - uow._context.UserXpStats.ResetGuildUserXp(userId, guildId); + uow.UserXpStats.ResetGuildUserXp(userId, guildId); uow.SaveChanges(); } } @@ -1209,7 +1209,7 @@ namespace NadekoBot.Modules.Xp.Services { using (var uow = _db.GetDbContext()) { - uow._context.UserXpStats.ResetGuildXp(guildId); + uow.UserXpStats.ResetGuildXp(guildId); uow.SaveChanges(); } } @@ -1217,15 +1217,15 @@ namespace NadekoBot.Modules.Xp.Services public async Task ResetXpRewards(ulong guildId) { using var uow = _db.GetDbContext(); - var guildConfig = uow._context.GuildConfigsForId(guildId, + var guildConfig = uow.GuildConfigsForId(guildId, set => set .Include(x => x.XpSettings) .ThenInclude(x => x.CurrencyRewards) .Include(x => x.XpSettings) .ThenInclude(x => x.RoleRewards)); - uow._context.RemoveRange(guildConfig.XpSettings.RoleRewards); - uow._context.RemoveRange(guildConfig.XpSettings.CurrencyRewards); + uow.RemoveRange(guildConfig.XpSettings.RoleRewards); + uow.RemoveRange(guildConfig.XpSettings.CurrencyRewards); await uow.SaveChangesAsync(); } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 6cf17b450..77d95bf70 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -108,7 +108,7 @@ namespace NadekoBot.Core.Services using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guild.Id, set => set); + var gc = uow.GuildConfigsForId(guild.Id, set => set); gc.Prefix = prefix; uow.SaveChanges(); } diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/ClubExtensions.cs b/src/NadekoBot/Services/Database/Extensions/ClubExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/ClubExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/ClubExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/CurrencyTransactionExtensions.cs b/src/NadekoBot/Services/Database/Extensions/CurrencyTransactionExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/CurrencyTransactionExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/CurrencyTransactionExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/CustomReactionsExtensions.cs b/src/NadekoBot/Services/Database/Extensions/CustomReactionsExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/CustomReactionsExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/CustomReactionsExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/DbExtensions.cs b/src/NadekoBot/Services/Database/Extensions/DbExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/DbExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/DbExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserExtensions.cs b/src/NadekoBot/Services/Database/Extensions/DiscordUserExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/DiscordUserExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/DiscordUserExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigExtensions.cs b/src/NadekoBot/Services/Database/Extensions/GuildConfigExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/GuildConfigExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/MusicPlayerSettingsExtensions.cs b/src/NadekoBot/Services/Database/Extensions/MusicPlayerSettingsExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/MusicPlayerSettingsExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/MusicPlayerSettingsExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/MusicPlaylistExtensions.cs b/src/NadekoBot/Services/Database/Extensions/MusicPlaylistExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/MusicPlaylistExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/MusicPlaylistExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/PollExtensions.cs b/src/NadekoBot/Services/Database/Extensions/PollExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/PollExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/PollExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteExtensions.cs b/src/NadekoBot/Services/Database/Extensions/QuoteExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/QuoteExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/QuoteExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/ReminderExtensions.cs b/src/NadekoBot/Services/Database/Extensions/ReminderExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/ReminderExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/ReminderExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignableRolesExtensions.cs b/src/NadekoBot/Services/Database/Extensions/SelfAssignableRolesExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignableRolesExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/SelfAssignableRolesExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/UserXpExtensions.cs b/src/NadekoBot/Services/Database/Extensions/UserXpExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/UserXpExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/UserXpExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/WaifuExtensions.cs b/src/NadekoBot/Services/Database/Extensions/WaifuExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/WaifuExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/WaifuExtensions.cs diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/WarningExtensions.cs b/src/NadekoBot/Services/Database/Extensions/WarningExtensions.cs similarity index 100% rename from src/NadekoBot/Services/Database/Repositories/Impl/WarningExtensions.cs rename to src/NadekoBot/Services/Database/Extensions/WarningExtensions.cs diff --git a/src/NadekoBot/Services/Database/IUnitOfWork.cs b/src/NadekoBot/Services/Database/IUnitOfWork.cs deleted file mode 100644 index 932f88b79..000000000 --- a/src/NadekoBot/Services/Database/IUnitOfWork.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NadekoBot.Core.Services.Database.Repositories; -using System; -using System.Threading.Tasks; - -namespace NadekoBot.Core.Services.Database -{ - public interface IUnitOfWork : IDisposable - { - NadekoContext _context { get; } - - int SaveChanges(); - Task SaveChangesAsync(); - } -} diff --git a/src/NadekoBot/Services/Database/Repositories/IRepository.cs b/src/NadekoBot/Services/Database/Repositories/IRepository.cs deleted file mode 100644 index bde82d803..000000000 --- a/src/NadekoBot/Services/Database/Repositories/IRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using NadekoBot.Core.Services.Database.Models; -using NadekoBot.Services.Database.Models; - -namespace NadekoBot.Services.Database.Repositories -{ - public interface IRepository where T : DbEntity - { - void Add(T obj); - } -} diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/Repository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/Repository.cs deleted file mode 100644 index 9504e0f85..000000000 --- a/src/NadekoBot/Services/Database/Repositories/Impl/Repository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using NadekoBot.Services.Database.Models; -using System.Collections.Generic; -using System.Linq; -using NadekoBot.Core.Services.Database.Models; - -namespace NadekoBot.Services.Database.Repositories.Impl -{ - public abstract class Repository : IRepository where T : DbEntity - { - protected DbContext _context { get; set; } - protected DbSet _set { get; set; } - - public Repository(DbContext context) - { - _context = context; - _set = context.Set(); - } - - public void Add(T obj) => - _set.Add(obj); - } -} diff --git a/src/NadekoBot/Services/Database/UnitOfWork.cs b/src/NadekoBot/Services/Database/UnitOfWork.cs deleted file mode 100644 index 1b60df06a..000000000 --- a/src/NadekoBot/Services/Database/UnitOfWork.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NadekoBot.Services.Database.Repositories; -using NadekoBot.Services.Database.Repositories.Impl; -using System; -using System.Threading.Tasks; -using NadekoBot.Core.Services.Database; -using NadekoBot.Core.Services.Database.Repositories; - -namespace NadekoBot.Services.Database -{ - public sealed class UnitOfWork : IUnitOfWork - { - public NadekoContext _context { get; } - - public UnitOfWork(NadekoContext context) - { - _context = context; - } - - public int SaveChanges() => - _context.SaveChanges(); - - public Task SaveChangesAsync() => - _context.SaveChangesAsync(); - - public void Dispose() - { - _context.Dispose(); - GC.SuppressFinalize(this); - } - } -} diff --git a/src/NadekoBot/Services/DbService.cs b/src/NadekoBot/Services/DbService.cs index 694000393..e27d779e7 100644 --- a/src/NadekoBot/Services/DbService.cs +++ b/src/NadekoBot/Services/DbService.cs @@ -57,6 +57,6 @@ namespace NadekoBot.Core.Services return context; } - public IUnitOfWork GetDbContext() => new UnitOfWork(GetDbContextInternal()); + public NadekoContext GetDbContext() => GetDbContextInternal(); } } \ No newline at end of file diff --git a/src/NadekoBot/Services/GreetSettingsService.cs b/src/NadekoBot/Services/GreetSettingsService.cs index 1ee701c50..fe695b905 100644 --- a/src/NadekoBot/Services/GreetSettingsService.cs +++ b/src/NadekoBot/Services/GreetSettingsService.cs @@ -107,7 +107,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - return uow._context.GuildConfigsForId(id, set => set)?.DmGreetMessageText; + return uow.GuildConfigsForId(id, set => set)?.DmGreetMessageText; } } @@ -115,7 +115,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - return uow._context.GuildConfigsForId(gid, set => set).ChannelGreetMessageText; + return uow.GuildConfigsForId(gid, set => set).ChannelGreetMessageText; } } @@ -319,7 +319,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - return uow._context.GuildConfigsForId(gid, set => set).ChannelByeMessageText; + return uow.GuildConfigsForId(gid, set => set).ChannelByeMessageText; } } @@ -331,7 +331,7 @@ namespace NadekoBot.Core.Services using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); settings = GreetSettings.Create(gc); } @@ -351,7 +351,7 @@ namespace NadekoBot.Core.Services using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); conf.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions(); conf.ChannelGreetMessageText = settings.ChannelGreetMessageText?.SanitizeMentions(); conf.ChannelByeMessageText = settings.ChannelByeMessageText?.SanitizeMentions(); @@ -382,7 +382,7 @@ namespace NadekoBot.Core.Services bool enabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage; conf.GreetMessageChannelId = channelId; @@ -404,7 +404,7 @@ namespace NadekoBot.Core.Services bool greetMsgEnabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); conf.ChannelGreetMessageText = message; greetMsgEnabled = conf.SendChannelGreetMessage; @@ -421,7 +421,7 @@ namespace NadekoBot.Core.Services bool enabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage; var toAdd = GreetSettings.Create(conf); @@ -437,7 +437,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); return conf.SendDmGreetMessage; } } @@ -446,7 +446,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); return conf.SendChannelGreetMessage; } } @@ -455,7 +455,7 @@ namespace NadekoBot.Core.Services { using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); return conf.SendChannelByeMessage; } } @@ -492,7 +492,7 @@ namespace NadekoBot.Core.Services bool greetMsgEnabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); conf.DmGreetMessageText = message; greetMsgEnabled = conf.SendDmGreetMessage; @@ -509,7 +509,7 @@ namespace NadekoBot.Core.Services bool enabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage; conf.ByeMessageChannelId = channelId; @@ -531,7 +531,7 @@ namespace NadekoBot.Core.Services bool byeMsgEnabled; using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); conf.ChannelByeMessageText = message; byeMsgEnabled = conf.SendChannelByeMessage; @@ -550,7 +550,7 @@ namespace NadekoBot.Core.Services using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(guildId, set => set); + var conf = uow.GuildConfigsForId(guildId, set => set); conf.AutoDeleteByeMessagesTimer = timer; var toAdd = GreetSettings.Create(conf); @@ -567,7 +567,7 @@ namespace NadekoBot.Core.Services using (var uow = _db.GetDbContext()) { - var conf = uow._context.GuildConfigsForId(id, set => set); + var conf = uow.GuildConfigsForId(id, set => set); conf.AutoDeleteGreetMessagesTimer = timer; var toAdd = GreetSettings.Create(conf); diff --git a/src/NadekoBot/Services/Impl/CurrencyService.cs b/src/NadekoBot/Services/Impl/CurrencyService.cs index bc36212cf..89c9c40ed 100644 --- a/src/NadekoBot/Services/Impl/CurrencyService.cs +++ b/src/NadekoBot/Services/Impl/CurrencyService.cs @@ -33,19 +33,19 @@ namespace NadekoBot.Core.Services }; private bool InternalChange(ulong userId, string userName, string discrim, string avatar, - string reason, long amount, bool gamble, IUnitOfWork uow) + string reason, long amount, bool gamble, NadekoContext uow) { - var result = uow._context.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount); + var result = uow.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount); if (result) { var t = GetCurrencyTransaction(userId, reason, amount); - uow._context.CurrencyTransactions.Add(t); + uow.CurrencyTransactions.Add(t); if (gamble) { var t2 = GetCurrencyTransaction(_bot.Id, reason, -amount); - uow._context.CurrencyTransactions.Add(t2); - uow._context.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true); + uow.CurrencyTransactions.Add(t2); + uow.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true); } } return result; diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index acb4a3da4..55055202b 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -56,7 +56,7 @@ namespace NadekoBot.Core.Services.Impl using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); gc.Locale = ci.Name; uow.SaveChanges(); } @@ -74,7 +74,7 @@ namespace NadekoBot.Core.Services.Impl { using (var uow = _db.GetDbContext()) { - var gc = uow._context.GuildConfigsForId(guildId, set => set); + var gc = uow.GuildConfigsForId(guildId, set => set); gc.Locale = null; uow.SaveChanges(); } diff --git a/src/NadekoBot/Services/NadekoBot.cs b/src/NadekoBot/Services/NadekoBot.cs index 2261c46cf..4e54415b3 100644 --- a/src/NadekoBot/Services/NadekoBot.cs +++ b/src/NadekoBot/Services/NadekoBot.cs @@ -136,7 +136,7 @@ namespace NadekoBot public IEnumerable GetCurrentGuildConfigs() { using var uow = _db.GetDbContext(); - return uow._context.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray(); + return uow.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray(); } private void AddServices() @@ -147,8 +147,8 @@ namespace NadekoBot using (var uow = _db.GetDbContext()) { - uow._context.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId); - AllGuildConfigs = uow._context.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); + uow.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId); + AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); } var s = new ServiceCollection() @@ -314,7 +314,7 @@ namespace NadekoBot GuildConfig gc; using (var uow = _db.GetDbContext()) { - gc = uow._context.GuildConfigsForId(arg.Id); + gc = uow.GuildConfigsForId(arg.Id); } await JoinedGuild.Invoke(gc).ConfigureAwait(false); }); diff --git a/src/NadekoBot/Services/Settings/BotConfigMigrator.cs b/src/NadekoBot/Services/Settings/BotConfigMigrator.cs index c15cc96b1..9a9f51e01 100644 --- a/src/NadekoBot/Services/Settings/BotConfigMigrator.cs +++ b/src/NadekoBot/Services/Settings/BotConfigMigrator.cs @@ -22,7 +22,7 @@ namespace NadekoBot.Core.Services public void EnsureMigrated() { using var uow = _db.GetDbContext(); - using var conn = uow._context.Database.GetDbConnection(); + using var conn = uow.Database.GetDbConnection(); // check if bot config exists using (var checkTableCommand = conn.CreateCommand()) diff --git a/src/NadekoBot/Services/Settings/GamblingConfigMigrator.cs b/src/NadekoBot/Services/Settings/GamblingConfigMigrator.cs index 51fb79b4e..5f83b57a1 100644 --- a/src/NadekoBot/Services/Settings/GamblingConfigMigrator.cs +++ b/src/NadekoBot/Services/Settings/GamblingConfigMigrator.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services public void EnsureMigrated() { using var uow = _db.GetDbContext(); - using var conn = uow._context.Database.GetDbConnection(); + using var conn = uow.Database.GetDbConnection(); Migrate(conn); }