UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow

This commit is contained in:
Kwoth
2021-06-19 05:16:27 +02:00
parent 51a4499809
commit c127dcd1e3
81 changed files with 404 additions and 512 deletions

View File

@@ -76,7 +76,7 @@ namespace NadekoBot.Core.Common.TypeReaders
long cur; long cur;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cur = uow._context.DiscordUser.GetUserCurrency(ctx.User.Id); cur = uow.DiscordUser.GetUserCurrency(ctx.User.Id);
uow.SaveChanges(); uow.SaveChanges();
} }
return cur; return cur;

View File

@@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, var conf = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.DelMsgOnCmdChannels)); set => set.Include(x => x.DelMsgOnCmdChannels));
return (conf.DeleteMessageOnCommand, conf.DelMsgOnCmdChannels); return (conf.DeleteMessageOnCommand, conf.DelMsgOnCmdChannels);
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = conf.DeleteMessageOnCommand = !conf.DeleteMessageOnCommand;
uow.SaveChanges(); uow.SaveChanges();
@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, var conf = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.DelMsgOnCmdChannels)); set => set.Include(x => x.DelMsgOnCmdChannels));
var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId); var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId);
@@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Administration.Services
if (!(old is null)) if (!(old is null))
{ {
conf.DelMsgOnCmdChannels.Remove(old); conf.DelMsgOnCmdChannels.Remove(old);
uow._context.Remove(old); uow.Remove(old);
} }
} }
else else

View File

@@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Administration.Services
public async Task<IReadOnlyList<ulong>> ToggleAarAsync(ulong guildId, ulong roleId) public async Task<IReadOnlyList<ulong>> ToggleAarAsync(ulong guildId, ulong roleId)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
var roles = gc.GetAutoAssignableRoles(); var roles = gc.GetAutoAssignableRoles();
if(!roles.Remove(roleId) && roles.Count < 3) if(!roles.Remove(roleId) && roles.Count < 3)
roles.Add(roleId); roles.Add(roleId);
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
await uow._context await uow
.GuildConfigs .GuildConfigs
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
@@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
gc.SetAutoAssignableRoles(newRoles); gc.SetAutoAssignableRoles(newRoles);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -46,7 +46,7 @@ DELETE FROM Clubs;";
int res; int res;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
res = await uow._context.Database.ExecuteSqlRawAsync(sql); res = await uow.Database.ExecuteSqlRawAsync(sql);
} }
return res; return res;
} }
@@ -67,7 +67,7 @@ DELETE FROM Clubs;";
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conn = uow._context.Database.GetDbConnection(); var conn = uow.Database.GetDbConnection();
using (var cmd = conn.CreateCommand()) using (var cmd = conn.CreateCommand())
{ {
cmd.CommandText = sql; cmd.CommandText = sql;
@@ -97,31 +97,31 @@ DELETE FROM Clubs;";
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
// get waifu info // get waifu info
var wi = await uow._context.Set<WaifuInfo>() var wi = await uow.Set<WaifuInfo>()
.FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId); .FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId);
// if it exists, delete waifu related things // if it exists, delete waifu related things
if (!(wi is null)) if (!(wi is null))
{ {
// remove updates which have new or old as this waifu // remove updates which have new or old as this waifu
await uow._context await uow
.WaifuUpdates .WaifuUpdates
.DeleteAsync(wu => wu.New.UserId == userId || wu.Old.UserId == userId); .DeleteAsync(wu => wu.New.UserId == userId || wu.Old.UserId == userId);
// delete all items this waifu owns // delete all items this waifu owns
await uow._context await uow
.Set<WaifuItem>() .Set<WaifuItem>()
.DeleteAsync(x => x.WaifuInfoId == wi.Id); .DeleteAsync(x => x.WaifuInfoId == wi.Id);
// all waifus this waifu claims are released // all waifus this waifu claims are released
await uow._context await uow
.Set<WaifuInfo>() .Set<WaifuInfo>()
.AsQueryable() .AsQueryable()
.Where(x => x.Claimer.UserId == userId) .Where(x => x.Claimer.UserId == userId)
.UpdateAsync(x => new WaifuInfo() {ClaimerId = null}); .UpdateAsync(x => new WaifuInfo() {ClaimerId = null});
// all affinities set to this waifu are reset // all affinities set to this waifu are reset
await uow._context await uow
.Set<WaifuInfo>() .Set<WaifuInfo>()
.AsQueryable() .AsQueryable()
.Where(x => x.Affinity.UserId == userId) .Where(x => x.Affinity.UserId == userId)
@@ -129,16 +129,16 @@ DELETE FROM Clubs;";
} }
// delete guild xp // delete guild xp
await uow._context await uow
.UserXpStats .UserXpStats
.DeleteAsync(x => x.UserId == userId); .DeleteAsync(x => x.UserId == userId);
// delete currency transactions // delete currency transactions
await uow._context.Set<CurrencyTransaction>() await uow.Set<CurrencyTransaction>()
.DeleteAsync(x => x.UserId == userId); .DeleteAsync(x => x.UserId == userId);
// delete user, currency, and clubs go away with it // delete user, currency, and clubs go away with it
await uow._context.DiscordUser await uow.DiscordUser
.DeleteAsync(u => u.UserId == userId); .DeleteAsync(u => u.UserId == userId);
} }
} }

View File

@@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration.Services
_db = db; _db = db;
_services = services; _services = services;
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
_overrides = uow._context.DiscordPermOverrides _overrides = uow.DiscordPermOverrides
.AsNoTracking() .AsNoTracking()
.AsEnumerable() .AsEnumerable()
.ToDictionary(o => (o.GuildId ?? 0, o.Command), o => o) .ToDictionary(o => (o.GuildId ?? 0, o.Command), o => o)
@@ -60,14 +60,14 @@ namespace NadekoBot.Modules.Administration.Services
commandName = commandName.ToLowerInvariant(); commandName = commandName.ToLowerInvariant();
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var over = await uow._context var over = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
.AsQueryable() .AsQueryable()
.FirstOrDefaultAsync(x => x.GuildId == guildId && commandName == x.Command); .FirstOrDefaultAsync(x => x.GuildId == guildId && commandName == x.Command);
if (over is null) if (over is null)
{ {
uow._context.Set<DiscordPermOverride>() uow.Set<DiscordPermOverride>()
.Add(over = new DiscordPermOverride() .Add(over = new DiscordPermOverride()
{ {
Command = commandName, Command = commandName,
@@ -90,14 +90,14 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var overrides = await uow._context var overrides = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
.AsQueryable() .AsQueryable()
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.ToListAsync(); .ToListAsync();
uow._context.RemoveRange(overrides); uow.RemoveRange(overrides);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
foreach (var over in overrides) foreach (var over in overrides)
@@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var over = await uow._context var over = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
.AsQueryable() .AsQueryable()
.AsNoTracking() .AsNoTracking()
@@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration.Services
if (over is null) if (over is null)
return; return;
uow._context.Remove(over); uow.Remove(over);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
_overrides.TryRemove((guildId, commandName), out _); _overrides.TryRemove((guildId, commandName), out _);
@@ -133,7 +133,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
return uow._context return uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
.AsQueryable() .AsQueryable()
.AsNoTracking() .AsNoTracking()

View File

@@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Administration.Services
ulong? id; ulong? id;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
if (gc.GameVoiceChannel == vchId) if (gc.GameVoiceChannel == vchId)
{ {

View File

@@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
gc.TimeZoneId = tz?.Id; gc.TimeZoneId = tz?.Id;
uow.SaveChanges(); uow.SaveChanges();

View File

@@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildIds = client.Guilds.Select(x => x.Id).ToList(); var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow._context var configs = uow
.Set<GuildConfig>() .Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(gc => gc.LogSetting) .Include(gc => gc.LogSetting)
@@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration.Services
int removed = 0; int removed = 0;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.LogSettingsFor(gid); var config = uow.LogSettingsFor(gid);
LogSetting logSetting = GuildLogSettings.GetOrAdd(gid, (id) => config.LogSetting); LogSetting logSetting = GuildLogSettings.GetOrAdd(gid, (id) => config.LogSetting);
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
config.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; LogSetting logSetting;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
logSetting = uow._context.LogSettingsFor(guildId).LogSetting; logSetting = uow.LogSettingsFor(guildId).LogSetting;
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting); GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
logSetting.LogOtherId = logSetting.LogOtherId =
logSetting.MessageUpdatedId = logSetting.MessageUpdatedId =
@@ -256,7 +256,7 @@ namespace NadekoBot.Modules.Administration.Services
ulong? channelId = null; ulong? channelId = null;
using (var uow = _db.GetDbContext()) 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); GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
switch (type) switch (type)
{ {
@@ -1220,7 +1220,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var newLogSetting = uow._context.LogSettingsFor(guildId).LogSetting; var newLogSetting = uow.LogSettingsFor(guildId).LogSetting;
switch (logChannelType) switch (logChannelType)
{ {
case LogType.Other: case LogType.Other:

View File

@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildIds = client.Guilds.Select(x => x.Id).ToList(); var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow._context.Set<GuildConfig>().AsQueryable() var configs = uow.Set<GuildConfig>().AsQueryable()
.Include(x => x.MutedUsers) .Include(x => x.MutedUsers)
.Include(x => x.UnbanTimer) .Include(x => x.UnbanTimer)
.Include(x => x.UnmuteTimers) .Include(x => x.UnmuteTimers)
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GuildConfigsForId(guildId, set => set); var config = uow.GuildConfigsForId(guildId, set => set);
config.MuteRoleName = name; config.MuteRoleName = name;
GuildMuteRoles.AddOrUpdate(guildId, name, (id, old) => name); GuildMuteRoles.AddOrUpdate(guildId, name, (id, old) => name);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Administration.Services
StopTimer(usr.GuildId, usr.Id, TimerType.Mute); StopTimer(usr.GuildId, usr.Id, TimerType.Mute);
using (var uow = _db.GetDbContext()) 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) set => set.Include(gc => gc.MutedUsers)
.Include(gc => gc.UnmuteTimers)); .Include(gc => gc.UnmuteTimers));
config.MutedUsers.Add(new MutedUserId() config.MutedUsers.Add(new MutedUserId()
@@ -231,7 +231,7 @@ namespace NadekoBot.Modules.Administration.Services
StopTimer(guildId, usrId, TimerType.Mute); StopTimer(guildId, usrId, TimerType.Mute);
using (var uow = _db.GetDbContext()) 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)); .Include(gc => gc.UnmuteTimers));
var match = new MutedUserId() var match = new MutedUserId()
{ {
@@ -240,7 +240,7 @@ namespace NadekoBot.Modules.Administration.Services
var toRemove = config.MutedUsers.FirstOrDefault(x => x.Equals(match)); var toRemove = config.MutedUsers.FirstOrDefault(x => x.Equals(match));
if (toRemove != null) if (toRemove != null)
{ {
uow._context.Remove(toRemove); uow.Remove(toRemove);
} }
if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet<ulong> muted)) if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet<ulong> muted))
muted.TryRemove(usrId); 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 await MuteUser(user, mod, muteType, reason).ConfigureAwait(false); // mute the user. This will also remove any previous unmute timers
using (var uow = _db.GetDbContext()) 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() config.UnmuteTimers.Add(new UnmuteTimer()
{ {
UserId = user.Id, UserId = user.Id,
@@ -343,7 +343,7 @@ namespace NadekoBot.Modules.Administration.Services
await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false); await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false);
using (var uow = _db.GetDbContext()) 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() config.UnbanTimer.Add(new UnbanTimer()
{ {
UserId = user.Id, UserId = user.Id,
@@ -360,7 +360,7 @@ namespace NadekoBot.Modules.Administration.Services
await user.AddRoleAsync(role).ConfigureAwait(false); await user.AddRoleAsync(role).ConfigureAwait(false);
using (var uow = _db.GetDbContext()) 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() config.UnroleTimer.Add(new UnroleTimer()
{ {
UserId = user.Id, UserId = user.Id,
@@ -458,17 +458,17 @@ namespace NadekoBot.Modules.Administration.Services
object toDelete; object toDelete;
if (type == TimerType.Mute) 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); toDelete = config.UnmuteTimers.FirstOrDefault(x => x.UserId == userId);
} }
else 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); toDelete = config.UnbanTimer.FirstOrDefault(x => x.UserId == userId);
} }
if (toDelete != null) if (toDelete != null)
{ {
uow._context.Remove(toDelete); uow.Remove(toDelete);
} }
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Administration.Services
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses; IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
rotatingStatuses = uow._context.RotatingStatus rotatingStatuses = uow.RotatingStatus
.AsNoTracking() .AsNoTracking()
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.ToList(); .ToList();
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toRemove = await uow._context.RotatingStatus var toRemove = await uow.RotatingStatus
.AsQueryable() .AsQueryable()
.AsNoTracking() .AsNoTracking()
.Skip(index) .Skip(index)
@@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Administration.Services
if (toRemove is null) if (toRemove is null)
return null; return null;
uow._context.Remove(toRemove); uow.Remove(toRemove);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
return toRemove.Status; return toRemove.Status;
} }
@@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toAdd = new RotatingPlayingStatus {Status = status, Type = t}; var toAdd = new RotatingPlayingStatus {Status = status, Type = t};
uow._context.Add(toAdd); uow.Add(toAdd);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Administration.Services
public IReadOnlyList<RotatingPlayingStatus> GetRotatingStatuses() public IReadOnlyList<RotatingPlayingStatus> GetRotatingStatuses()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context.RotatingStatus.AsNoTracking().ToList(); return uow.RotatingStatus.AsNoTracking().ToList();
} }
} }
} }

View File

@@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Administration.Services
var ids = client.GetGuildIds(); var ids = client.GetGuildIds();
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var configs = uow._context.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.AntiRaidSetting) .Include(x => x.AntiRaidSetting)
.Include(x => x.AntiSpamSetting) .Include(x => x.AntiSpamSetting)
@@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Administration.Services
private Task _bot_JoinedGuild(GuildConfig gc) private Task _bot_JoinedGuild(GuildConfig gc)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var gcWithData = uow._context.GuildConfigsForId(gc.GuildId, var gcWithData = uow.GuildConfigsForId(gc.GuildId,
set => set set => set
.Include(x => x.AntiRaidSetting) .Include(x => x.AntiRaidSetting)
.Include(x => x.AntiAltSetting) .Include(x => x.AntiAltSetting)
@@ -304,7 +304,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = _db.GetDbContext()) 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; gc.AntiRaidSetting = stats.AntiRaidSettings;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -319,7 +319,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) 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; gc.AntiRaidSetting = null;
uow.SaveChanges(); uow.SaveChanges();
@@ -336,7 +336,7 @@ namespace NadekoBot.Modules.Administration.Services
removed.UserStats.ForEach(x => x.Value.Dispose()); removed.UserStats.ForEach(x => x.Value.Dispose());
using (var uow = _db.GetDbContext()) 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)); .ThenInclude(x => x.IgnoredChannels));
gc.AntiSpamSetting = null; gc.AntiSpamSetting = null;
@@ -375,7 +375,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = _db.GetDbContext()) 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) if (gc.AntiSpamSetting != null)
{ {
@@ -402,7 +402,7 @@ namespace NadekoBot.Modules.Administration.Services
bool added; bool added;
using (var uow = _db.GetDbContext()) 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; var spam = gc.AntiSpamSetting;
if (spam is null) if (spam is null)
{ {
@@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Administration.Services
else else
{ {
var toRemove = spam.IgnoredChannels.First(x => x.ChannelId == channelId); var toRemove = spam.IgnoredChannels.First(x => x.ChannelId == channelId);
uow._context.Set<AntiSpamIgnore>().Remove(toRemove); // remove from db uow.Set<AntiSpamIgnore>().Remove(toRemove); // remove from db
if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
{ {
temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache
@@ -459,7 +459,7 @@ namespace NadekoBot.Modules.Administration.Services
int actionDurationMinutes = 0, ulong? roleId = null) int actionDurationMinutes = 0, ulong? roleId = null)
{ {
using var uow = _db.GetDbContext(); 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() gc.AntiAltSetting = new AntiAltSetting()
{ {
Action = action, Action = action,
@@ -478,7 +478,7 @@ namespace NadekoBot.Modules.Administration.Services
return false; return false;
using var uow = _db.GetDbContext(); 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; gc.AntiAltSetting = null;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
return true; return true;

View File

@@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(id, set => set var gc = uow.GuildConfigsForId(id, set => set
.Include(x => x.ReactionRoleMessages) .Include(x => x.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles)); .ThenInclude(x => x.ReactionRoles));
if (gc.ReactionRoleMessages.Count >= 10) if (gc.ReactionRoleMessages.Count >= 10)
@@ -174,10 +174,10 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(id, var gc = uow.GuildConfigsForId(id,
set => set.Include(x => x.ReactionRoleMessages) set => set.Include(x => x.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles)); .ThenInclude(x => x.ReactionRoles));
uow._context.Set<ReactionRole>() uow.Set<ReactionRole>()
.RemoveRange(gc.ReactionRoleMessages[index].ReactionRoles); .RemoveRange(gc.ReactionRoleMessages[index].ReactionRoles);
gc.ReactionRoleMessages.RemoveAt(index); gc.ReactionRoleMessages.RemoveAt(index);
_models.AddOrUpdate(id, _models.AddOrUpdate(id,

View File

@@ -43,13 +43,13 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) 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)) if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
{ {
return false; return false;
} }
uow._context.SelfAssignableRoles.Add(new SelfAssignedRole uow.SelfAssignableRoles.Add(new SelfAssignedRole
{ {
Group = group, Group = group,
RoleId = role.Id, RoleId = role.Id,
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration.Services
bool newval; bool newval;
using (var uow = _db.GetDbContext()) 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; newval = config.AutoDeleteSelfAssignedRoleMessages = !config.AutoDeleteSelfAssignedRoleMessages;
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Administration.Services
LevelStats userLevelData; LevelStats userLevelData;
using (var uow = _db.GetDbContext()) 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); userLevelData = new LevelStats(stats.Xp + stats.AwardedXp);
} }
@@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Administration.Services
bool set = false; bool set = false;
using (var uow = _db.GetDbContext()) 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); var toUpdate = gc.SelfAssignableRoleGroupNames.FirstOrDefault(x => x.Number == group);
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
@@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Administration.Services
bool success; bool success;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
success = uow._context.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId); success = uow.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId);
uow.SaveChanges(); uow.SaveChanges();
} }
return success; return success;
@@ -207,10 +207,10 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) 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 autoDelete = gc.AutoDeleteSelfAssignedRoleMessages;
var exclusive = gc.ExclusiveSelfAssignedRoles; var exclusive = gc.ExclusiveSelfAssignedRoles;
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId); var roles = uow.SelfAssignableRoles.GetFromGuild(guildId);
return (autoDelete, exclusive, roles); return (autoDelete, exclusive, roles);
} }
@@ -220,7 +220,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) 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); var sar = roles.FirstOrDefault(x => x.RoleId == role.Id);
if (sar != null) if (sar != null)
{ {
@@ -241,7 +241,7 @@ namespace NadekoBot.Modules.Administration.Services
bool areExclusive; bool areExclusive;
using (var uow = _db.GetDbContext()) 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; areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
uow.SaveChanges(); uow.SaveChanges();
@@ -257,13 +257,13 @@ namespace NadekoBot.Modules.Administration.Services
IDictionary<int, string> groupNames; IDictionary<int, string> groupNames;
using (var uow = _db.GetDbContext()) 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; exclusive = gc.ExclusiveSelfAssignedRoles;
groupNames = gc.SelfAssignableRoleGroupNames.ToDictionary(x => x.Number, x => x.Name); 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 roles = roleModels
.Select(x => (Model: x, Role: guild.GetRole(x.RoleId))); .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(); uow.SaveChanges();
} }

View File

@@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
_autoCommands = uow._context _autoCommands = uow
.AutoCommands .AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval >= 5) .Where(x => x.Interval >= 5)
@@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration.Services
.ToConcurrent()) .ToConcurrent())
.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) foreach (var cmd in startupCommands)
{ {
try try
@@ -163,7 +163,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.AutoCommands.Add(cmd); uow.AutoCommands.Add(cmd);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -181,7 +181,7 @@ namespace NadekoBot.Modules.Administration.Services
public IEnumerable<AutoCommand> GetStartupCommands() public IEnumerable<AutoCommand> GetStartupCommands()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context return uow
.AutoCommands .AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval == 0) .Where(x => x.Interval == 0)
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Administration.Services
public IEnumerable<AutoCommand> GetAutoCommands() public IEnumerable<AutoCommand> GetAutoCommands()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context return uow
.AutoCommands .AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval >= 5) .Where(x => x.Interval >= 5)
@@ -297,7 +297,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cmd = uow._context.AutoCommands cmd = uow.AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval == 0) .Where(x => x.Interval == 0)
.Skip(index) .Skip(index)
@@ -305,7 +305,7 @@ namespace NadekoBot.Modules.Administration.Services
if (cmd != null) if (cmd != null)
{ {
uow._context.Remove(cmd); uow.Remove(cmd);
uow.SaveChanges(); uow.SaveChanges();
return true; return true;
} }
@@ -318,7 +318,7 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cmd = uow._context.AutoCommands cmd = uow.AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval >= 5) .Where(x => x.Interval >= 5)
.Skip(index) .Skip(index)
@@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Administration.Services
if (cmd != null) if (cmd != null)
{ {
uow._context.Remove(cmd); uow.Remove(cmd);
if (_autoCommands.TryGetValue(cmd.GuildId, out var autos)) if (_autoCommands.TryGetValue(cmd.GuildId, out var autos))
if (autos.TryRemove(cmd.Id, out var timer)) if (autos.TryRemove(cmd.Id, out var timer))
timer.Change(Timeout.Infinite, Timeout.Infinite); timer.Change(Timeout.Infinite, Timeout.Infinite);
@@ -369,12 +369,12 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var toRemove = uow._context var toRemove = uow
.AutoCommands .AutoCommands
.AsNoTracking() .AsNoTracking()
.Where(x => x.Interval == 0); .Where(x => x.Interval == 0);
uow._context.AutoCommands.RemoveRange(toRemove); uow.AutoCommands.RemoveRange(toRemove);
uow.SaveChanges(); uow.SaveChanges();
} }
} }

View File

@@ -61,16 +61,16 @@ namespace NadekoBot.Modules.Administration.Services
List<WarningPunishment> ps; List<WarningPunishment> ps;
using (var uow = _db.GetDbContext()) 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; .WarnPunishments;
warnings += uow._context warnings += uow
.Warnings .Warnings
.ForId(guildId, userId) .ForId(guildId, userId)
.Where(w => !w.Forgiven && w.UserId == userId) .Where(w => !w.Forgiven && w.UserId == userId)
.Count(); .Count();
uow._context.Warnings.Add(warn); uow.Warnings.Add(warn);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -169,14 +169,14 @@ namespace NadekoBot.Modules.Administration.Services
{ {
using (var uow = _db.GetDbContext()) 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, SET Forgiven = 1,
ForgivenBy = 'Expiry' ForgivenBy = 'Expiry'
WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 0) WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 0)
AND Forgiven = 0 AND Forgiven = 0
AND DateAdded < datetime('now', (SELECT '-' || WarnExpireHours || ' hours' FROM GuildConfigs as gc WHERE gc.GuildId = Warnings.GuildId));"); 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) 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));"); 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()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GuildConfigsForId(guildId, inc => inc); var config = uow.GuildConfigsForId(guildId, inc => inc);
if (config.WarnExpireHours == 0) if (config.WarnExpireHours == 0)
return; return;
@@ -199,7 +199,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND
var hours = $"{-config.WarnExpireHours} hours"; var hours = $"{-config.WarnExpireHours} hours";
if (config.WarnExpireAction == WarnExpireAction.Clear) if (config.WarnExpireAction == WarnExpireAction.Clear)
{ {
await uow._context.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings await uow.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings
SET Forgiven = 1, SET Forgiven = 1,
ForgivenBy = 'Expiry' ForgivenBy = 'Expiry'
WHERE GuildId={guildId} WHERE GuildId={guildId}
@@ -208,7 +208,7 @@ WHERE GuildId={guildId}
} }
else if (config.WarnExpireAction == WarnExpireAction.Delete) else if (config.WarnExpireAction == WarnExpireAction.Delete)
{ {
await uow._context.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings await uow.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings
WHERE GuildId={guildId} WHERE GuildId={guildId}
AND DateAdded < datetime('now', {hours})"); AND DateAdded < datetime('now', {hours})");
} }
@@ -220,7 +220,7 @@ WHERE GuildId={guildId}
public Task<int> GetWarnExpire(ulong guildId) public Task<int> GetWarnExpire(ulong guildId)
{ {
using var uow = _db.GetDbContext(); 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); return Task.FromResult(config.WarnExpireHours / 24);
} }
@@ -228,7 +228,7 @@ WHERE GuildId={guildId}
{ {
using (var uow = _db.GetDbContext()) 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.WarnExpireHours = days * 24;
config.WarnExpireAction = delete ? WarnExpireAction.Delete : WarnExpireAction.Clear; config.WarnExpireAction = delete ? WarnExpireAction.Delete : WarnExpireAction.Clear;
@@ -246,7 +246,7 @@ WHERE GuildId={guildId}
{ {
using (var uow = _db.GetDbContext()) 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()) 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) if (index == 0)
{ {
await uow._context.Warnings.ForgiveAll(guildId, userId, moderator); await uow.Warnings.ForgiveAll(guildId, userId, moderator);
} }
else else
{ {
toReturn = uow._context.Warnings.Forgive(guildId, userId, moderator, index - 1); toReturn = uow.Warnings.Forgive(guildId, userId, moderator, index - 1);
} }
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -286,10 +286,10 @@ WHERE GuildId={guildId}
using (var uow = _db.GetDbContext()) 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); var toDelete = ps.Where(x => x.Count == number);
uow._context.RemoveRange(toDelete); uow.RemoveRange(toDelete);
ps.Add(new WarningPunishment() ps.Add(new WarningPunishment()
{ {
@@ -310,12 +310,12 @@ WHERE GuildId={guildId}
using (var uow = _db.GetDbContext()) 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); var p = ps.FirstOrDefault(x => x.Count == number);
if (p != null) if (p != null)
{ {
uow._context.Remove(p); uow.Remove(p);
uow.SaveChanges(); uow.SaveChanges();
} }
} }
@@ -326,7 +326,7 @@ WHERE GuildId={guildId}
{ {
using (var uow = _db.GetDbContext()) 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 .WarnPunishments
.OrderBy(x => x.Count) .OrderBy(x => x.Count)
.ToArray(); .ToArray();
@@ -374,7 +374,7 @@ WHERE GuildId={guildId}
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var template = uow._context.BanTemplates var template = uow.BanTemplates
.AsQueryable() .AsQueryable()
.FirstOrDefault(x => x.GuildId == guildId); .FirstOrDefault(x => x.GuildId == guildId);
return template?.Text; return template?.Text;
@@ -385,7 +385,7 @@ WHERE GuildId={guildId}
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var template = uow._context.BanTemplates var template = uow.BanTemplates
.AsQueryable() .AsQueryable()
.FirstOrDefault(x => x.GuildId == guildId); .FirstOrDefault(x => x.GuildId == guildId);
@@ -394,11 +394,11 @@ WHERE GuildId={guildId}
if (template is null) if (template is null)
return; return;
uow._context.Remove(template); uow.Remove(template);
} }
else if (template == null) else if (template == null)
{ {
uow._context.BanTemplates.Add(new BanTemplate() uow.BanTemplates.Add(new BanTemplate()
{ {
GuildId = guildId, GuildId = guildId,
Text = text, Text = text,

View File

@@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildIds = client.Guilds.Select(x => x.Id).ToList(); var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow._context.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.VcRoleInfos) .Include(x => x.VcRoleInfos)
.Where(x => guildIds.Contains(x.GuildId)) .Where(x => guildIds.Contains(x.GuildId))
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
// need to load new guildconfig with vc role included // need to load new guildconfig with vc role included
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var configWithVcRole = uow._context.GuildConfigsForId( var configWithVcRole = uow.GuildConfigsForId(
arg.GuildId, arg.GuildId,
set => set.Include(x => x.VcRoleInfos) set => set.Include(x => x.VcRoleInfos)
); );
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}"); Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}");
uow._context.RemoveRange(missingRoles); uow.RemoveRange(missingRoles);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
} }
@@ -144,11 +144,11 @@ namespace NadekoBot.Modules.Administration.Services
guildVcRoles.AddOrUpdate(vcId, role, (key, old) => role); guildVcRoles.AddOrUpdate(vcId, role, (key, old) => role);
using (var uow = _db.GetDbContext()) 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 var toDelete = conf.VcRoleInfos.FirstOrDefault(x => x.VoiceChannelId == vcId); // remove old one
if(toDelete != null) if(toDelete != null)
{ {
uow._context.Remove(toDelete); uow.Remove(toDelete);
} }
conf.VcRoleInfos.Add(new VcRoleInfo() conf.VcRoleInfos.Add(new VcRoleInfo()
{ {
@@ -169,9 +169,9 @@ namespace NadekoBot.Modules.Administration.Services
using (var uow = _db.GetDbContext()) 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(); var toRemove = conf.VcRoleInfos.Where(x => x.VoiceChannelId == vcId).ToList();
uow._context.RemoveRange(toRemove); uow.RemoveRange(toRemove);
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -90,7 +90,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds) private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var guildItems = await uow._context.CustomReactions var guildItems = await uow.CustomReactions
.AsNoTracking() .AsNoTracking()
.Where(x => allGuildIds.Contains(x.GuildId.Value)) .Where(x => allGuildIds.Contains(x.GuildId.Value))
.ToListAsync(); .ToListAsync();
@@ -107,7 +107,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
lock (_gcrWriteLock) lock (_gcrWriteLock)
{ {
var globalItems = uow._context var globalItems = uow
.CustomReactions .CustomReactions
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == null || x.GuildId == 0) .Where(x => x.GuildId == null || x.GuildId == 0)
@@ -195,7 +195,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
private async Task OnJoinedGuild(GuildConfig gc) private async Task OnJoinedGuild(GuildConfig gc)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var crs = await uow._context var crs = await uow
.CustomReactions .CustomReactions
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == gc.GuildId) .Where(x => x.GuildId == gc.GuildId)
@@ -223,7 +223,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.CustomReactions.Add(cr); uow.CustomReactions.Add(cr);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -235,7 +235,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
public async Task<CustomReaction> EditAsync(ulong? guildId, int id, string message) public async Task<CustomReaction> EditAsync(ulong? guildId, int id, string message)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var cr = uow._context.CustomReactions.GetById(id); var cr = uow.CustomReactions.GetById(id);
if (cr == null || cr.GuildId != guildId) if (cr == null || cr.GuildId != guildId)
return null; return null;
@@ -263,14 +263,14 @@ namespace NadekoBot.Modules.CustomReactions.Services
public async Task<CustomReaction> DeleteAsync(ulong? guildId, int id) public async Task<CustomReaction> DeleteAsync(ulong? guildId, int id)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toDelete = uow._context.CustomReactions.GetById(id); var toDelete = uow.CustomReactions.GetById(id);
if (toDelete is null) if (toDelete is null)
return null; return null;
if ((toDelete.IsGlobal() && guildId == null) || (guildId == toDelete.GuildId)) if ((toDelete.IsGlobal() && guildId == null) || (guildId == toDelete.GuildId))
{ {
uow._context.CustomReactions.Remove(toDelete); uow.CustomReactions.Remove(toDelete);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
await DeleteInternalAsync(guildId, id); await DeleteInternalAsync(guildId, id);
return toDelete; return toDelete;
@@ -469,7 +469,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
{ {
CustomReaction cr; CustomReaction cr;
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
cr = uow._context.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
return; return;
@@ -587,7 +587,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
CustomReaction cr; CustomReaction cr;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cr = uow._context.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
return; return;
@@ -605,7 +605,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
CustomReaction cr; CustomReaction cr;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cr = uow._context.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
return (false, false); return (false, false);
if (field == CrField.AutoDelete) if (field == CrField.AutoDelete)
@@ -628,7 +628,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
public CustomReaction GetCustomReaction(ulong? guildId, int id) public CustomReaction GetCustomReaction(ulong? guildId, int id)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var cr = uow._context.CustomReactions.GetById(id); var cr = uow.CustomReactions.GetById(id);
if (cr == null || cr.GuildId != guildId) if (cr == null || cr.GuildId != guildId)
return null; return null;
@@ -638,7 +638,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
public int DeleteAllCustomReactions(ulong guildId) public int DeleteAllCustomReactions(ulong guildId)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var count = uow._context.CustomReactions.ClearFromGuild(guildId); var count = uow.CustomReactions.ClearFromGuild(guildId);
uow.SaveChanges(); uow.SaveChanges();
_newGuildReactions.TryRemove(guildId, out _); _newGuildReactions.TryRemove(guildId, out _);
@@ -649,7 +649,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
public bool ReactionExists(ulong? guildId, string input) public bool ReactionExists(ulong? guildId, string input)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var cr = uow._context.CustomReactions.GetByGuildIdAndInput(guildId, input); var cr = uow.CustomReactions.GetByGuildIdAndInput(guildId, input);
return cr != null; return cr != null;
} }
@@ -705,7 +705,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
foreach (var entry in data) foreach (var entry in data)
{ {
var trigger = entry.Key; var trigger = entry.Key;
await uow._context.CustomReactions.AddRangeAsync(entry.Value await uow.CustomReactions.AddRangeAsync(entry.Value
.Where(cr => !string.IsNullOrWhiteSpace(cr.Res)) .Where(cr => !string.IsNullOrWhiteSpace(cr.Res))
.Select(cr => new CustomReaction() .Select(cr => new CustomReaction()
{ {

View File

@@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Gambling
{ {
using (var uow = _db.GetDbContext()) 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<CurrencyTransaction>(); var trs = new List<CurrencyTransaction>();
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
trs = uow._context.CurrencyTransactions.GetPageFor(userId, page); trs = uow.CurrencyTransactions.GetPageFor(userId, page);
} }
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
@@ -522,7 +522,7 @@ namespace NadekoBot.Modules.Gambling
using (var uow = _db.GetDbContext()) 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); await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
@@ -536,7 +536,7 @@ namespace NadekoBot.Modules.Gambling
{ {
using (var uow = _db.GetDbContext()) 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()) 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 else

View File

@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Gambling.Services
if (maxDecay == 0) if (maxDecay == 0)
maxDecay = int.MaxValue; maxDecay = int.MaxValue;
uow._context.Database.ExecuteSqlInterpolated($@" uow.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser UPDATE DiscordUser
SET CurrencyAmount= SET CurrencyAmount=
CASE WHEN CASE WHEN
@@ -80,32 +80,6 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
} }
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); }, 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<Stake>()
// .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<Stake>().RemoveRange(stakes);
// uow.Complete();
// Log.Information("Refunded {0} users' stakes.", stakes.Length);
//}
} }
public struct EconomyResult public struct EconomyResult
@@ -136,11 +110,11 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
cash = uow._context.DiscordUser.GetTotalCurrency(); cash = uow.DiscordUser.GetTotalCurrency();
onePercent = uow._context.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id); onePercent = uow.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id);
planted = uow._context.PlantedCurrency.AsQueryable().Sum(x => x.Amount); planted = uow.PlantedCurrency.AsQueryable().Sum(x => x.Amount);
waifus = uow._context.WaifuInfo.GetTotalValue(); waifus = uow.WaifuInfo.GetTotalValue();
bot = uow._context.DiscordUser.GetUserCurrency(_client.CurrentUser.Id); bot = uow.DiscordUser.GetUserCurrency(_client.CurrentUser.Id);
} }
var result = new EconomyResult var result = new EconomyResult

View File

@@ -19,8 +19,8 @@ namespace NadekoBot.Modules.Gambling.Services
_db = db; _db = db;
} }
private IndexedCollection<ShopEntry> GetEntriesInternal(IUnitOfWork uow, ulong guildId) => private IndexedCollection<ShopEntry> GetEntriesInternal(NadekoContext uow, ulong guildId) =>
uow._context.GuildConfigsForId( uow.GuildConfigsForId(
guildId, guildId,
set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items) set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items)
) )

View File

@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Gambling.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildIds = client.Guilds.Select(x => x.Id).ToList(); var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow._context.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.GenerateCurrencyChannelIds) .Include(x => x.GenerateCurrencyChannelIds)
.Where(x => guildIds.Contains(x.GuildId)) .Where(x => guildIds.Contains(x.GuildId))
@@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Gambling.Services
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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 }; var toAdd = new GCChannelId() { ChannelId = cid };
if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd)) if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
@@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Gambling.Services
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd)); var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
if (toDelete != null) if (toDelete != null)
{ {
uow._context.Remove(toDelete); uow.Remove(toDelete);
} }
_generationChannels.TryRemove(cid); _generationChannels.TryRemove(cid);
enabled = false; enabled = false;
@@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Gambling.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var chs = uow._context.GuildConfigs.GetGeneratingChannels(); var chs = uow.GuildConfigs.GetGeneratingChannels();
return chs; return chs;
} }
} }
@@ -270,7 +270,7 @@ namespace NadekoBot.Modules.Gambling.Services
pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant(); pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant();
// gets all plants in this channel with the same password // gets all plants in this channel with the same password
var entries = uow._context.PlantedCurrency var entries = uow.PlantedCurrency
.AsQueryable() .AsQueryable()
.Where(x => x.ChannelId == ch.Id && pass == x.Password) .Where(x => x.ChannelId == ch.Id && pass == x.Password)
.ToList(); .ToList();
@@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Gambling.Services
amount = entries.Sum(x => x.Amount); amount = entries.Sum(x => x.Amount);
ids = entries.Select(x => x.MessageId).ToArray(); ids = entries.Select(x => x.MessageId).ToArray();
// remove them from the database // remove them from the database
uow._context.RemoveRange(entries); uow.RemoveRange(entries);
if (amount > 0) if (amount > 0)
@@ -369,7 +369,7 @@ namespace NadekoBot.Modules.Gambling.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.PlantedCurrency.Add(new PlantedCurrency uow.PlantedCurrency.Add(new PlantedCurrency
{ {
Amount = amount, Amount = amount,
GuildId = gid, GuildId = gid,

View File

@@ -46,8 +46,8 @@ namespace NadekoBot.Modules.Gambling.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var waifu = uow._context.WaifuInfo.ByWaifuUserId(waifuId); var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow._context.GetOrCreateUser(owner); var ownerUser = uow.GetOrCreateUser(owner);
// owner has to be the owner of the waifu // owner has to be the owner of the waifu
if (waifu == null || waifu.ClaimerId != ownerUser.Id) 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 //new claimerId is the id of the new owner
var newOwnerUser = uow._context.GetOrCreateUser(newOwner); var newOwnerUser = uow.GetOrCreateUser(newOwner);
waifu.ClaimerId = newOwnerUser.Id; waifu.ClaimerId = newOwnerUser.Id;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -96,16 +96,16 @@ namespace NadekoBot.Modules.Gambling.Services
var settings = _gss.Data; var settings = _gss.Data;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id); var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
if (waifu == null) if (waifu == null)
return settings.Waifu.MinPrice; 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.Old.UserId == user.Id &&
x.UpdateType == WaifuUpdateType.Claimed && x.UpdateType == WaifuUpdateType.Claimed &&
x.New == null); x.New == null);
var affs = uow._context.WaifuUpdates var affs = uow.WaifuUpdates
.AsQueryable() .AsQueryable()
.Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged && .Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged &&
w.New != null) w.New != null)
@@ -126,13 +126,13 @@ namespace NadekoBot.Modules.Gambling.Services
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true)) if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
return false; return false;
var affs = uow._context.WaifuUpdates var affs = uow.WaifuUpdates
.AsQueryable() .AsQueryable()
.Where(w => w.User.UserId == user.Id .Where(w => w.User.UserId == user.Id
&& w.UpdateType == WaifuUpdateType.AffinityChanged && w.UpdateType == WaifuUpdateType.AffinityChanged
&& w.New != null); && w.New != null);
var divorces = uow._context.WaifuUpdates var divorces = uow.WaifuUpdates
.AsQueryable() .AsQueryable()
.Where(x => x.Old != null && .Where(x => x.Old != null &&
x.Old.UserId == user.Id && x.Old.UserId == user.Id &&
@@ -140,10 +140,10 @@ namespace NadekoBot.Modules.Gambling.Services
x.New == null); x.New == null);
//reset changes of heart to 0 //reset changes of heart to 0
uow._context.WaifuUpdates.RemoveRange(affs); uow.WaifuUpdates.RemoveRange(affs);
//reset divorces to 0 //reset divorces to 0
uow._context.WaifuUpdates.RemoveRange(divorces); uow.WaifuUpdates.RemoveRange(divorces);
var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id); var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
//reset price, remove items //reset price, remove items
//remove owner, remove affinity //remove owner, remove affinity
waifu.Price = 50; waifu.Price = 50;
@@ -167,26 +167,26 @@ namespace NadekoBot.Modules.Gambling.Services
bool isAffinity; bool isAffinity;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
w = uow._context.WaifuInfo.ByWaifuUserId(target.Id); w = uow.WaifuInfo.ByWaifuUserId(target.Id);
isAffinity = (w?.Affinity?.UserId == user.Id); isAffinity = (w?.Affinity?.UserId == user.Id);
if (w == null) if (w == null)
{ {
var claimer = uow._context.GetOrCreateUser(user); var claimer = uow.GetOrCreateUser(user);
var waifu = uow._context.GetOrCreateUser(target); var waifu = uow.GetOrCreateUser(target);
if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true)) if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
{ {
result = WaifuClaimResult.NotEnoughFunds; result = WaifuClaimResult.NotEnoughFunds;
} }
else else
{ {
uow._context.WaifuInfo.Add(w = new WaifuInfo() uow.WaifuInfo.Add(w = new WaifuInfo()
{ {
Waifu = waifu, Waifu = waifu,
Claimer = claimer, Claimer = claimer,
Affinity = null, Affinity = null,
Price = amount Price = amount
}); });
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = waifu, User = waifu,
Old = null, Old = null,
@@ -205,11 +205,11 @@ namespace NadekoBot.Modules.Gambling.Services
else else
{ {
var oldClaimer = w.Claimer; var oldClaimer = w.Claimer;
w.Claimer = uow._context.GetOrCreateUser(user); w.Claimer = uow.GetOrCreateUser(user);
w.Price = amount + (amount / 4); w.Price = amount + (amount / 4);
result = WaifuClaimResult.Success; result = WaifuClaimResult.Success;
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = w.Waifu, User = w.Waifu,
Old = oldClaimer, Old = oldClaimer,
@@ -227,11 +227,11 @@ namespace NadekoBot.Modules.Gambling.Services
else else
{ {
var oldClaimer = w.Claimer; var oldClaimer = w.Claimer;
w.Claimer = uow._context.GetOrCreateUser(user); w.Claimer = uow.GetOrCreateUser(user);
w.Price = amount; w.Price = amount;
result = WaifuClaimResult.Success; result = WaifuClaimResult.Success;
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = w.Waifu, User = w.Waifu,
Old = oldClaimer, Old = oldClaimer,
@@ -257,8 +257,8 @@ namespace NadekoBot.Modules.Gambling.Services
TimeSpan? remaining = null; TimeSpan? remaining = null;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var w = uow._context.WaifuInfo.ByWaifuUserId(user.Id); var w = uow.WaifuInfo.ByWaifuUserId(user.Id);
var newAff = target == null ? null : uow._context.GetOrCreateUser(target); var newAff = target == null ? null : uow.GetOrCreateUser(target);
if (w?.Affinity?.UserId == target?.Id) if (w?.Affinity?.UserId == target?.Id)
{ {
} }
@@ -267,8 +267,8 @@ namespace NadekoBot.Modules.Gambling.Services
} }
else if (w == null) else if (w == null)
{ {
var thisUser = uow._context.GetOrCreateUser(user); var thisUser = uow.GetOrCreateUser(user);
uow._context.WaifuInfo.Add(new WaifuInfo() uow.WaifuInfo.Add(new WaifuInfo()
{ {
Affinity = newAff, Affinity = newAff,
Waifu = thisUser, Waifu = thisUser,
@@ -277,7 +277,7 @@ namespace NadekoBot.Modules.Gambling.Services
}); });
success = true; success = true;
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = thisUser, User = thisUser,
Old = null, Old = null,
@@ -292,7 +292,7 @@ namespace NadekoBot.Modules.Gambling.Services
w.Affinity = newAff; w.Affinity = newAff;
success = true; success = true;
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = w.Waifu, User = w.Waifu,
Old = oldAff, Old = oldAff,
@@ -311,14 +311,14 @@ namespace NadekoBot.Modules.Gambling.Services
{ {
using (var uow = _db.GetDbContext()) 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) public ulong GetWaifuUserId(ulong ownerId, string name)
{ {
using var uow = _db.GetDbContext(); 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) public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId)
@@ -329,7 +329,7 @@ namespace NadekoBot.Modules.Gambling.Services
WaifuInfo w = null; WaifuInfo w = null;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
w = uow._context.WaifuInfo.ByWaifuUserId(targetId); w = uow.WaifuInfo.ByWaifuUserId(targetId);
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
if (w?.Claimer == null || w.Claimer.UserId != user.Id) if (w?.Claimer == null || w.Claimer.UserId != user.Id)
result = DivorceResult.NotYourWife; result = DivorceResult.NotYourWife;
@@ -357,7 +357,7 @@ namespace NadekoBot.Modules.Gambling.Services
var oldClaimer = w.Claimer; var oldClaimer = w.Claimer;
w.Claimer = null; w.Claimer = null;
uow._context.WaifuUpdates.Add(new WaifuUpdate() uow.WaifuUpdates.Add(new WaifuUpdate()
{ {
User = w.Waifu, User = w.Waifu,
Old = oldClaimer, Old = oldClaimer,
@@ -381,17 +381,17 @@ namespace NadekoBot.Modules.Gambling.Services
using (var uow = _db.GetDbContext()) 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) set => set.Include(x => x.Items)
.Include(x => x.Claimer)); .Include(x => x.Claimer));
if (w == null) if (w == null)
{ {
uow._context.WaifuInfo.Add(w = new WaifuInfo() uow.WaifuInfo.Add(w = new WaifuInfo()
{ {
Affinity = null, Affinity = null,
Claimer = null, Claimer = null,
Price = 1, 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()) using (var uow = _db.GetDbContext())
{ {
var wi = uow._context.GetWaifuInfo(targetId); var wi = uow.GetWaifuInfo(targetId);
if (wi is null) if (wi is null)
{ {
wi = new WaifuInfoStats wi = new WaifuInfoStats
@@ -445,7 +445,7 @@ namespace NadekoBot.Modules.Gambling.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var du = uow._context.GetOrCreateUser(target); var du = uow.GetOrCreateUser(target);
return GetFullWaifuInfoAsync(target.Id); return GetFullWaifuInfoAsync(target.Id);
} }

View File

@@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Gambling
throw new ArgumentOutOfRangeException(nameof(page)); throw new ArgumentOutOfRangeException(nameof(page));
using var uow = _db.GetDbContext(); 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) set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries .ThenInclude(x => x.Items)).ShopEntries
.ToIndexed(); .ToIndexed();
@@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Gambling
ShopEntry entry; ShopEntry entry;
using (var uow = _db.GetDbContext()) 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) .Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)); .ThenInclude(x => x.Items));
var entries = new IndexedCollection<ShopEntry>(config.ShopEntries); var entries = new IndexedCollection<ShopEntry>(config.ShopEntries);
@@ -165,7 +165,7 @@ namespace NadekoBot.Modules.Gambling
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var x = uow._context.Set<ShopEntryItem>().Remove(item); var x = uow.Set<ShopEntryItem>().Remove(item);
uow.SaveChanges(); uow.SaveChanges();
} }
try try
@@ -189,7 +189,7 @@ namespace NadekoBot.Modules.Gambling
entry.Price).ConfigureAwait(false); entry.Price).ConfigureAwait(false);
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries); .ThenInclude(x => x.Items)).ShopEntries);
entry = entries.ElementAtOrDefault(index); entry = entries.ElementAtOrDefault(index);
@@ -235,13 +235,13 @@ namespace NadekoBot.Modules.Gambling
}; };
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries) .ThenInclude(x => x.Items)).ShopEntries)
{ {
entry entry
}; };
uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
uow.SaveChanges(); uow.SaveChanges();
} }
await ctx.Channel.EmbedAsync(EntryToEmbed(entry) await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
@@ -263,13 +263,13 @@ namespace NadekoBot.Modules.Gambling
}; };
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries) .ThenInclude(x => x.Items)).ShopEntries)
{ {
entry entry
}; };
uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
uow.SaveChanges(); uow.SaveChanges();
} }
await ctx.Channel.EmbedAsync(EntryToEmbed(entry) await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
@@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Gambling
bool added = false; bool added = false;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries); .ThenInclude(x => x.Items)).ShopEntries);
entry = entries.ElementAtOrDefault(index); entry = entries.ElementAtOrDefault(index);
@@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Gambling
ShopEntry removed; ShopEntry removed;
using (var uow = _db.GetDbContext()) 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) .Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)); .ThenInclude(x => x.Items));
@@ -334,8 +334,8 @@ namespace NadekoBot.Modules.Gambling
removed = entries.ElementAtOrDefault(index); removed = entries.ElementAtOrDefault(index);
if (removed != null) if (removed != null)
{ {
uow._context.RemoveRange(removed.Items); uow.RemoveRange(removed.Items);
uow._context.Remove(removed); uow.Remove(removed);
uow.SaveChanges(); uow.SaveChanges();
} }
} }

View File

@@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false); uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
await ReplyConfirmLocalizedAsync("cleverbot_disabled").ConfigureAwait(false); await ReplyConfirmLocalizedAsync("cleverbot_disabled").ConfigureAwait(false);
@@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Games
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true); uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }

View File

@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Games.Common
finally { _locker.Release(); } finally { _locker.Release(); }
using (var uow = _db.GetDbContext()) 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); trackedPoll.Votes.Add(voteObj);
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Games.Services
// public void EnsureMigrated() // public void EnsureMigrated()
// { // {
// using var uow = _db.GetDbContext(); // using var uow = _db.GetDbContext();
// using var conn = uow._context.Database.GetDbConnection(); // using var conn = uow.Database.GetDbConnection();
// MigrateRaceAnimals(conn); // MigrateRaceAnimals(conn);
// MigrateEightBall(conn); // MigrateEightBall(conn);
// } // }

View File

@@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Games.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
ActivePolls = uow._context.Poll.GetAllPolls() ActivePolls = uow.Poll.GetAllPolls()
.ToDictionary(x => x.GuildId, x => .ToDictionary(x => x.GuildId, x =>
{ {
var pr = new PollRunner(db, x); var pr = new PollRunner(db, x);
@@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Games.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.Poll.Add(p); uow.Poll.Add(p);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Games.Services
pr.OnVoted -= Pr_OnVoted; pr.OnVoted -= Pr_OnVoted;
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
uow._context.RemovePoll(pr.Poll.Id); uow.RemovePoll(pr.Poll.Id);
uow.SaveChanges(); uow.SaveChanges();
return pr.Poll; return pr.Poll;

View File

@@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Music
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
playlists = uow._context.MusicPlaylists.GetPlaylistsOnPage(num); playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
} }
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
@@ -78,13 +78,13 @@ namespace NadekoBot.Modules.Music
{ {
using (var uow = _db.GetDbContext()) 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 (pl != null)
{ {
if (_creds.IsOwner(ctx.User) || pl.AuthorId == ctx.User.Id) if (_creds.IsOwner(ctx.User) || pl.AuthorId == ctx.User.Id)
{ {
uow._context.MusicPlaylists.Remove(pl); uow.MusicPlaylists.Remove(pl);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
success = true; success = true;
} }
@@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Music
MusicPlaylist mpl; MusicPlaylist mpl;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
mpl = uow._context.MusicPlaylists.GetWithSongs(id); mpl = uow.MusicPlaylists.GetWithSongs(id);
} }
await ctx.SendPaginatedConfirmAsync(page, (cur) => await ctx.SendPaginatedConfirmAsync(page, (cur) =>
@@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Music
AuthorId = ctx.User.Id, AuthorId = ctx.User.Id,
Songs = songs.ToList(), Songs = songs.ToList(),
}; };
uow._context.MusicPlaylists.Add(playlist); uow.MusicPlaylists.Add(playlist);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Music
MusicPlaylist mpl; MusicPlaylist mpl;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
mpl = uow._context.MusicPlaylists.GetWithSongs(id); mpl = uow.MusicPlaylists.GetWithSongs(id);
} }
if (mpl == null) if (mpl == null)

View File

@@ -13,7 +13,6 @@ using NadekoBot.Core.Services.Database.Repositories.Impl;
using NadekoBot.Modules.Music; using NadekoBot.Modules.Music;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Repositories.Impl;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using Serilog; using Serilog;
@@ -352,7 +351,7 @@ namespace NadekoBot.Modules.Music.Services
return settings; return settings;
using var uow = _db.GetDbContext(); 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(); await uow.SaveChangesAsync();
return toReturn; return toReturn;
@@ -364,7 +363,7 @@ namespace NadekoBot.Modules.Music.Services
TState state) TState state)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var ms = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId); var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
action(ms, state); action(ms, state);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
_settings[guildId] = ms; _settings[guildId] = ms;
@@ -444,7 +443,7 @@ namespace NadekoBot.Modules.Music.Services
public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId) public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var settings = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId); var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
return settings.QualityPreset; return settings.QualityPreset;
} }

View File

@@ -82,7 +82,7 @@
// { // {
// using (var uow = _db.GetDbContext()) // 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; // bool val;
// using (var uow = _db.GetDbContext()) // 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; // val = gc.AutoDcFromVc = !gc.AutoDcFromVc;
// uow.SaveChanges(); // uow.SaveChanges();
// } // }
@@ -278,7 +278,7 @@
// { // {
// using (var uow = _db.GetDbContext()) // 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; // ms.MusicChannelId = cid;
// uow.SaveChanges(); // uow.SaveChanges();
// } // }
@@ -288,7 +288,7 @@
// { // {
// using (var uow = _db.GetDbContext()) // 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; // ms.SongAutoDelete = val;
// uow.SaveChanges(); // uow.SaveChanges();
// } // }

View File

@@ -395,7 +395,7 @@
// } // }
// using (var uow = _db.GetDbContext()) // 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(); // uow.SaveChanges();
// } // }
// await ReplyConfirmLocalizedAsync("defvol_set", val).ConfigureAwait(false); // await ReplyConfirmLocalizedAsync("defvol_set", val).ConfigureAwait(false);

View File

@@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Permissions
var name = command.Name.ToLowerInvariant(); var name = command.Name.ToLowerInvariant();
using (var uow = _db.GetDbContext()) 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<CommandCooldown>()); var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CommandCooldown>());
var toDelete = config.CommandCooldowns.FirstOrDefault(cc => cc.CommandName == name); var toDelete = config.CommandCooldowns.FirstOrDefault(cc => cc.CommandName == name);
if (toDelete != null) if (toDelete != null)
uow._context.Set<CommandCooldown>().Remove(toDelete); uow.Set<CommandCooldown>().Remove(toDelete);
localSet.RemoveWhere(cc => cc.CommandName == name); localSet.RemoveWhere(cc => cc.CommandName == name);
if (secs != 0) if (secs != 0)
{ {

View File

@@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Permissions
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = config.FilterInvites = !config.FilterInvites;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -69,7 +69,7 @@ namespace NadekoBot.Modules.Permissions
FilterChannelId removed; FilterChannelId removed;
using (var uow = _db.GetDbContext()) 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() var match = new FilterChannelId()
{ {
ChannelId = channel.Id ChannelId = channel.Id
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions
} }
else else
{ {
uow._context.Remove(removed); uow.Remove(removed);
} }
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Permissions
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = config.FilterLinks = !config.FilterLinks;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Permissions
FilterLinksChannelId removed; FilterLinksChannelId removed;
using (var uow = _db.GetDbContext()) 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() var match = new FilterLinksChannelId()
{ {
ChannelId = channel.Id ChannelId = channel.Id
@@ -147,7 +147,7 @@ namespace NadekoBot.Modules.Permissions
} }
else else
{ {
uow._context.Remove(removed); uow.Remove(removed);
} }
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Permissions
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = config.FilterWords = !config.FilterWords;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -199,7 +199,7 @@ namespace NadekoBot.Modules.Permissions
FilterChannelId removed; FilterChannelId removed;
using (var uow = _db.GetDbContext()) 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() var match = new FilterChannelId()
{ {
@@ -212,7 +212,7 @@ namespace NadekoBot.Modules.Permissions
} }
else else
{ {
uow._context.Remove(removed); uow.Remove(removed);
} }
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -243,7 +243,7 @@ namespace NadekoBot.Modules.Permissions
FilteredWord removed; FilteredWord removed;
using (var uow = _db.GetDbContext()) 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); 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 }); config.FilteredWords.Add(new FilteredWord() { Word = word });
else else
{ {
uow._context.Remove(removed); uow.Remove(removed);
} }
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Permissions
{ {
using (var uow = _db.GetDbContext()) 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. if (action == null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle.
config.VerbosePermissions = action.Value; config.VerbosePermissions = action.Value;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Permissions
using (var uow = _db.GetDbContext()) 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(); config.PermissionRole = role.Id.ToString();
uow.SaveChanges(); uow.SaveChanges();
_service.UpdateCache(config); _service.UpdateCache(config);
@@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Permissions
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
config.PermissionRole = null; config.PermissionRole = null;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
_service.UpdateCache(config); _service.UpdateCache(config);
@@ -148,11 +148,11 @@ namespace NadekoBot.Modules.Permissions
Permissionv2 p; Permissionv2 p;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions); var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
p = permsCol[index]; p = permsCol[index];
permsCol.RemoveAt(index); permsCol.RemoveAt(index);
uow._context.Remove(p); uow.Remove(p);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
_service.UpdateCache(config); _service.UpdateCache(config);
} }
@@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Permissions
Permissionv2 fromPerm; Permissionv2 fromPerm;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions); var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
var fromFound = from < permsCol.Count; var fromFound = from < permsCol.Count;

View File

@@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Permissions.Services
public void Reload(bool publish = true) public void Reload(bool publish = true)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toPublish = uow._context.Blacklist.AsNoTracking().ToArray(); var toPublish = uow.Blacklist.AsNoTracking().ToArray();
_blacklist = toPublish; _blacklist = toPublish;
if (publish) if (publish)
{ {
@@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Permissions.Services
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var item = new BlacklistEntry { ItemId = id, Type = type }; var item = new BlacklistEntry { ItemId = id, Type = type };
uow._context.Blacklist.Add(item); uow.Blacklist.Add(item);
uow.SaveChanges(); uow.SaveChanges();
Reload(true); Reload(true);
@@ -85,11 +85,11 @@ namespace NadekoBot.Modules.Permissions.Services
public void UnBlacklist(BlacklistType type, ulong id) public void UnBlacklist(BlacklistType type, ulong id)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toRemove = uow._context.Blacklist var toRemove = uow.Blacklist
.FirstOrDefault(bi => bi.ItemId == id && bi.Type == type); .FirstOrDefault(bi => bi.ItemId == id && bi.Type == type);
if (!(toRemove is null)) if (!(toRemove is null))
uow._context.Blacklist.Remove(toRemove); uow.Blacklist.Remove(toRemove);
uow.SaveChanges(); uow.SaveChanges();
@@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Permissions.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var bc = uow._context.Blacklist; var bc = uow.Blacklist;
//blacklist the users //blacklist the users
bc.AddRange(toBlacklist.Select(x => bc.AddRange(toBlacklist.Select(x =>
new BlacklistEntry new BlacklistEntry
@@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Permissions.Services
})); }));
//clear their currencies //clear their currencies
uow._context.DiscordUser.RemoveFromMany(toBlacklist); uow.DiscordUser.RemoveFromMany(toBlacklist);
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Permissions.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, var gc = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.FilteredWords) set => set.Include(x => x.FilteredWords)
.Include(x => x.FilterWordsChannelIds)); .Include(x => x.FilterWordsChannelIds));
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions.Services
using(var uow = db.GetDbContext()) using(var uow = db.GetDbContext())
{ {
var ids = client.GetGuildIds(); var ids = client.GetGuildIds();
var configs = uow._context.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.FilteredWords) .Include(x => x.FilteredWords)
.Include(x => x.FilterLinksChannelIds) .Include(x => x.FilterLinksChannelIds)

View File

@@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Permissions.Services
using (var uow = _db.GetDbContext()) 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() Cache.TryAdd(x.GuildId, new PermissionCache()
{ {
@@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Permissions.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GuildConfigsForId(guildId, var config = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.Permissions)); set => set.Include(x => x.Permissions));
UpdateCache(config); UpdateCache(config);
} }
@@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Permissions.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GcWithPermissionsv2For(guildId); var config = uow.GcWithPermissionsv2For(guildId);
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions); //var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest
foreach (var perm in perms) foreach (var perm in perms)
@@ -175,7 +175,7 @@ namespace NadekoBot.Modules.Permissions.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var config = uow._context.GcWithPermissionsv2For(guildId); var config = uow.GcWithPermissionsv2For(guildId);
config.Permissions = Permissionv2.GetDefaultPermlist; config.Permissions = Permissionv2.GetDefaultPermlist;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
UpdateCache(config); UpdateCache(config);

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildConfigIds = bot.AllGuildConfigs.Select(x => x.Id).ToList(); var guildConfigIds = bot.AllGuildConfigs.Select(x => x.Id).ToList();
_subs = uow._context.GuildConfigs _subs = uow.GuildConfigs
.AsQueryable() .AsQueryable()
.Where(x => guildConfigIds.Contains(x.Id)) .Where(x => guildConfigIds.Contains(x.Id))
.Include(x => x.FeedSubs) .Include(x => x.FeedSubs)
@@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Searches.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
return uow._context.GuildConfigsForId(guildId, return uow.GuildConfigsForId(guildId,
set => set.Include(x => x.FeedSubs) set => set.Include(x => x.FeedSubs)
.ThenInclude(x => x.GuildConfig)) .ThenInclude(x => x.GuildConfig))
.FeedSubs .FeedSubs
@@ -188,7 +188,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, var gc = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.FeedSubs) set => set.Include(x => x.FeedSubs)
.ThenInclude(x => x.GuildConfig)); .ThenInclude(x => x.GuildConfig));
@@ -224,7 +224,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = _db.GetDbContext()) 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 .FeedSubs
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.ToList(); .ToList();
@@ -237,7 +237,7 @@ namespace NadekoBot.Modules.Searches.Services
old.Remove(toRemove); old.Remove(toRemove);
return old; return old;
}); });
uow._context.Remove(toRemove); uow.Remove(toRemove);
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -410,7 +410,7 @@ namespace NadekoBot.Modules.Searches.Services
bool added; bool added;
using (var uow = _db.GetDbContext()) 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)) if (gc.NsfwBlacklistedTags.Add(tagObj))
added = true; added = true;
else else
@@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Searches.Services
gc.NsfwBlacklistedTags.Remove(tagObj); gc.NsfwBlacklistedTags.Remove(tagObj);
var toRemove = gc.NsfwBlacklistedTags.FirstOrDefault(x => x.Equals(tagObj)); var toRemove = gc.NsfwBlacklistedTags.FirstOrDefault(x => x.Equals(tagObj));
if (toRemove != null) if (toRemove != null)
uow._context.Remove(toRemove); uow.Remove(toRemove);
added = false; added = false;
} }
var newTags = new HashSet<string>(gc.NsfwBlacklistedTags.Select(x => x.Tag)); var newTags = new HashSet<string>(gc.NsfwBlacklistedTags.Select(x => x.Tag));

View File

@@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var ids = client.GetGuildIds(); var ids = client.GetGuildIds();
var guildConfigs = uow._context.Set<GuildConfig>() var guildConfigs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.FollowedStreams) .Include(x => x.FollowedStreams)
.Where(x => ids.Contains(x.GuildId)) .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 // shard 0 will keep track of when there are no more guilds which track a stream
if (client.ShardId == 0) if (client.ShardId == 0)
{ {
var allFollowedStreams = uow._context.Set<FollowedStream>() var allFollowedStreams = uow.Set<FollowedStream>()
.AsQueryable() .AsQueryable()
.ToList(); .ToList();
@@ -132,12 +132,12 @@ namespace NadekoBot.Modules.Searches.Services
Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " + Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " +
$"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}"); $"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}");
var toDelete = uow._context.Set<FollowedStream>() var toDelete = uow.Set<FollowedStream>()
.AsQueryable() .AsQueryable()
.Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username)) .Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username))
.ToList(); .ToList();
uow._context.RemoveRange(toDelete); uow.RemoveRange(toDelete);
uow.SaveChanges(); uow.SaveChanges();
foreach(var loginToDelete in kvp.Value) foreach(var loginToDelete in kvp.Value)
@@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Searches.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigs var gc = uow.GuildConfigs
.AsQueryable() .AsQueryable()
.Include(x => x.FollowedStreams) .Include(x => x.FollowedStreams)
.FirstOrDefault(x => x.GuildId == guildConfig.GuildId); .FirstOrDefault(x => x.GuildId == guildConfig.GuildId);
@@ -320,7 +320,7 @@ namespace NadekoBot.Modules.Searches.Services
{ {
using (var uow = _db.GetDbContext()) 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); _offlineNotificationServers.TryRemove(gc.GuildId);
@@ -342,7 +342,7 @@ namespace NadekoBot.Modules.Searches.Services
int count; int count;
using (var uow = _db.GetDbContext()) 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; count = gc.FollowedStreams.Count;
gc.FollowedStreams.Clear(); gc.FollowedStreams.Clear();
uow.SaveChanges(); uow.SaveChanges();
@@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Searches.Services
FollowedStream fs; FollowedStream fs;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var fss = uow._context.Set<FollowedStream>() var fss = uow.Set<FollowedStream>()
.AsQueryable() .AsQueryable()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
@@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Searches.Services
return null; return null;
fs = fss[index]; fs = fss[index];
uow._context.Remove(fs); uow.Remove(fs);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -411,7 +411,7 @@ namespace NadekoBot.Modules.Searches.Services
FollowedStream fs; FollowedStream fs;
using (var uow = _db.GetDbContext()) 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 // add it to the database
fs = new FollowedStream() fs = new FollowedStream()
@@ -481,7 +481,7 @@ namespace NadekoBot.Modules.Searches.Services
bool newValue; bool newValue;
using (var uow = _db.GetDbContext()) 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; newValue = gc.NotifyStreamOffline = !gc.NotifyStreamOffline;
uow.SaveChanges(); uow.SaveChanges();
@@ -530,7 +530,7 @@ namespace NadekoBot.Modules.Searches.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var fss = uow._context.Set<FollowedStream>() var fss = uow.Set<FollowedStream>()
.AsQueryable() .AsQueryable()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
@@ -564,7 +564,7 @@ namespace NadekoBot.Modules.Searches.Services
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var all = uow._context.Set<FollowedStream>() var all = uow.Set<FollowedStream>()
.ToList(); .ToList();
if (all.Count == 0) if (all.Count == 0)

View File

@@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Searches.Services
// //
// using(var uow = _db.GetDbContext()) // 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 // // see if this yt channel was already followed on this discord channel
// var oldObj = gc.YtFollowedChannels // var oldObj = gc.YtFollowedChannels

View File

@@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Searches
List<FollowedStream> streams = new List<FollowedStream>(); List<FollowedStream> streams = new List<FollowedStream>();
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var all = uow._context var all = uow
.GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) .GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams))
.FollowedStreams .FollowedStreams
.OrderBy(x => x.Id) .OrderBy(x => x.Id)

View File

@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext()) 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() var toAdd = new CommandAlias()
{ {
Mapping = mapping, Mapping = mapping,
@@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Utility
}; };
var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger); var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger);
if (tr != null) if (tr != null)
uow._context.Set<CommandAlias>().Remove(tr); uow.Set<CommandAlias>().Remove(tr);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Utility
{ {
using (var uow = _db.GetDbContext()) 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() config.CommandAliases.Add(new CommandAlias()
{ {
Mapping = mapping, Mapping = mapping,
@@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Utility
{ {
using (var uow = _db.GetDbContext()) 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() var toAdd = new CommandAlias()
{ {
Mapping = mapping, Mapping = mapping,
@@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Utility
}; };
var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger); var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger);
if (toRemove.Any()) if (toRemove.Any())
uow._context.RemoveRange(toRemove.ToArray()); uow.RemoveRange(toRemove.ToArray());
config.CommandAliases.Add(toAdd); config.CommandAliases.Add(toAdd);
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -12,7 +12,6 @@ using System.Threading.Tasks;
using NadekoBot.Core.Services; using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models; using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Core.Services.Database.Repositories.Impl; using NadekoBot.Core.Services.Database.Repositories.Impl;
using NadekoBot.Services.Database.Repositories.Impl;
using NadekoBot.Db; using NadekoBot.Db;
namespace NadekoBot.Modules.Utility namespace NadekoBot.Modules.Utility
@@ -47,7 +46,7 @@ namespace NadekoBot.Modules.Utility
IEnumerable<Quote> quotes; IEnumerable<Quote> quotes;
using (var uow = _db.GetDbContext()) 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()) if (quotes.Any())
@@ -70,7 +69,7 @@ namespace NadekoBot.Modules.Utility
Quote quote; Quote quote;
using (var uow = _db.GetDbContext()) 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) //if (quote != null)
//{ //{
// quote.UseCount += 1; // quote.UseCount += 1;
@@ -102,7 +101,7 @@ namespace NadekoBot.Modules.Utility
Quote quote; Quote quote;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
quote = uow._context.Quotes.GetById(id); quote = uow.Quotes.GetById(id);
if (quote.GuildId != Context.Guild.Id) if (quote.GuildId != Context.Guild.Id)
quote = null; quote = null;
} }
@@ -141,7 +140,7 @@ namespace NadekoBot.Modules.Utility
Quote keywordquote; Quote keywordquote;
using (var uow = _db.GetDbContext()) 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) if (keywordquote == null)
@@ -166,7 +165,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext()) 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) if (quote is null || quote.GuildId != ctx.Guild.Id)
@@ -203,7 +202,7 @@ namespace NadekoBot.Modules.Utility
Quote q; Quote q;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.Quotes.Add(q = new Quote uow.Quotes.Add(q = new Quote
{ {
AuthorId = ctx.Message.Author.Id, AuthorId = ctx.Message.Author.Id,
AuthorName = ctx.Message.Author.Username, AuthorName = ctx.Message.Author.Username,
@@ -226,7 +225,7 @@ namespace NadekoBot.Modules.Utility
string response; string response;
using (var uow = _db.GetDbContext()) 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)) if ((q?.GuildId != ctx.Guild.Id) || (!isAdmin && q.AuthorId != ctx.Message.Author.Id))
{ {
@@ -234,7 +233,7 @@ namespace NadekoBot.Modules.Utility
} }
else else
{ {
uow._context.Quotes.Remove(q); uow.Quotes.Remove(q);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
success = true; success = true;
response = GetText("quote_deleted", id); response = GetText("quote_deleted", id);
@@ -258,7 +257,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext()) 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(); await uow.SaveChangesAsync();
} }

View File

@@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Utility
List<Reminder> rems; List<Reminder> rems;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
rems = uow._context.Reminders.RemindersFor(ctx.User.Id, page) rems = uow.Reminders.RemindersFor(ctx.User.Id, page)
.ToList(); .ToList();
} }
@@ -133,13 +133,13 @@ namespace NadekoBot.Modules.Utility
Reminder rem = null; Reminder rem = null;
using (var uow = _db.GetDbContext()) 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(); .ToList();
var pageIndex = index % 10; var pageIndex = index % 10;
if (rems.Count > pageIndex) if (rems.Count > pageIndex)
{ {
rem = rems[pageIndex]; rem = rems[pageIndex];
uow._context.Reminders.Remove(rem); uow.Reminders.Remove(rem);
uow.SaveChanges(); uow.SaveChanges();
} }
} }
@@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.Reminders.Add(rem); uow.Reminders.Add(rem);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Utility.Services
using (var uow = db.GetDbContext()) using (var uow = db.GetDbContext())
{ {
var guildIds = client.Guilds.Select(x => x.Id).ToList(); var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow._context.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.Include(gc => gc.CommandAliases) .Include(gc => gc.CommandAliases)
.Where(x => guildIds.Contains(x.GuildId)) .Where(x => guildIds.Contains(x.GuildId))
.ToList(); .ToList();
@@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Utility.Services
int count; int count;
using (var uow = _db.GetDbContext()) 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; count = gc.CommandAliases.Count;
gc.CommandAliases.Clear(); gc.CommandAliases.Clear();
uow.SaveChanges(); uow.SaveChanges();

View File

@@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Utility.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var users = uow._context.Set<RewardedUser>(); var users = uow.Set<RewardedUser>();
var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id); var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id);
if (usr == null) if (usr == null)

View File

@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.Set<Reminder>() uow.Set<Reminder>()
.RemoveRange(reminders); .RemoveRange(reminders);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Utility.Services
{ {
using (var uow = _db.GetDbContext()) 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};") .FromSqlInterpolated($"select * from reminders where ((serverid >> 22) % {_creds.TotalShards}) == {_client.ShardId} and \"when\" < {now};")
.ToListAsync(); .ToListAsync();
} }

View File

@@ -40,8 +40,7 @@ namespace NadekoBot.Modules.Utility.Services
_client = client; _client = client;
var uow = _db.GetDbContext(); var uow = _db.GetDbContext();
var shardRepeaters = uow var shardRepeaters = uow
._context
.Set<Repeater>() .Set<Repeater>()
.FromSqlInterpolated($@"select * from repeaters .FromSqlInterpolated($@"select * from repeaters
where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
@@ -133,7 +132,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toTrigger = await uow._context.Repeaters var toTrigger = await uow.Repeaters
.AsNoTracking() .AsNoTracking()
.Skip(index) .Skip(index)
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId); .FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
@@ -290,7 +289,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
_noRedundant.TryRemove(r.Id); _noRedundant.TryRemove(r.Id);
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
await uow._context await uow
.Repeaters .Repeaters
.DeleteAsync(x => x.Id == r.Id); .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) private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
await uow._context.Repeaters await uow.Repeaters
.AsQueryable() .AsQueryable()
.Where(x => x.Id == repeaterId) .Where(x => x.Id == repeaterId)
.UpdateAsync(rep => new Repeater() .UpdateAsync(rep => new Repeater()
@@ -345,8 +344,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
if (await uow._context.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS) if (await uow.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS)
uow._context.Repeaters.Add(rep); uow.Repeaters.Add(rep);
else else
return null; return null;
@@ -365,7 +364,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toRemove = await uow._context.Repeaters var toRemove = await uow.Repeaters
.AsNoTracking() .AsNoTracking()
.Skip(index) .Skip(index)
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId); .FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
@@ -380,7 +379,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
return null; return null;
_noRedundant.TryRemove(toRemove.Id); _noRedundant.TryRemove(toRemove.Id);
uow._context.Repeaters.Remove(toRemove); uow.Repeaters.Remove(toRemove);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
return removed; return removed;
} }
@@ -396,7 +395,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index) public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var toToggle = await uow._context var toToggle = await uow
.Repeaters .Repeaters
.AsQueryable() .AsQueryable()
.Skip(index) .Skip(index)

View File

@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Utility.Services
bool success = false; bool success = false;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
if (listType == StreamRoleListType.Whitelist) if (listType == StreamRoleListType.Whitelist)
{ {
@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Utility.Services
var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj)); var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj));
if (toDelete != null) if (toDelete != null)
{ {
uow._context.Remove(toDelete); uow.Remove(toDelete);
success = true; success = true;
} }
} }
@@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Utility.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
streamRoleSettings.Keyword = keyword; streamRoleSettings.Keyword = keyword;
UpdateCache(guild.Id, streamRoleSettings); UpdateCache(guild.Id, streamRoleSettings);
@@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Utility.Services
StreamRoleSettings setting; StreamRoleSettings setting;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
setting = uow._context.GetStreamRoleSettings(guildId); setting = uow.GetStreamRoleSettings(guildId);
} }
UpdateCache(guildId, setting); UpdateCache(guildId, setting);
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility.Services
StreamRoleSettings setting; StreamRoleSettings setting;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow._context.GetStreamRoleSettings(fromRole.Guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id);
streamRoleSettings.Enabled = true; streamRoleSettings.Enabled = true;
streamRoleSettings.AddRoleId = addRole.Id; streamRoleSettings.AddRoleId = addRole.Id;
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Utility.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
streamRoleSettings.Enabled = false; streamRoleSettings.Enabled = false;
streamRoleSettings.AddRoleId = 0; streamRoleSettings.AddRoleId = 0;
streamRoleSettings.FromRoleId = 0; streamRoleSettings.FromRoleId = 0;

View File

@@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Utility.Services
{ {
using (var uow = _db.GetDbContext()) 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 if (enabled==null) enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition
else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it. else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.

View File

@@ -29,8 +29,8 @@ namespace NadekoBot.Modules.Xp.Services
club = null; club = null;
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var du = uow._context.GetOrCreateUser(user); var du = uow.GetOrCreateUser(user);
uow._context.SaveChanges(); uow.SaveChanges();
var xp = new LevelStats(du.TotalXp); var xp = new LevelStats(du.TotalXp);
if (xp.Level >= 5 && du.Club == null) if (xp.Level >= 5 && du.Club == null)
@@ -39,17 +39,17 @@ namespace NadekoBot.Modules.Xp.Services
du.Club = new ClubInfo() du.Club = new ClubInfo()
{ {
Name = clubName, Name = clubName,
Discrim = uow._context.Clubs.GetNextDiscrim(clubName), Discrim = uow.Clubs.GetNextDiscrim(clubName),
Owner = du, Owner = du,
}; };
uow._context.Clubs.Add(du.Club); uow.Clubs.Add(du.Club);
uow._context.SaveChanges(); uow.SaveChanges();
} }
else else
return false; return false;
uow._context.Set<ClubApplicants>() uow.Set<ClubApplicants>()
.RemoveRange(uow._context.Set<ClubApplicants>() .RemoveRange(uow.Set<ClubApplicants>()
.AsQueryable() .AsQueryable()
.Where(x => x.UserId == du.Id)); .Where(x => x.UserId == du.Id));
club = du.Club; club = du.Club;
@@ -63,8 +63,8 @@ namespace NadekoBot.Modules.Xp.Services
ClubInfo club; ClubInfo club;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByOwner(from.Id); club = uow.Clubs.GetByOwner(from.Id);
var newOwnerUser = uow._context.GetOrCreateUser(newOwner); var newOwnerUser = uow.GetOrCreateUser(newOwner);
if (club == null || if (club == null ||
club.Owner.UserId != from.Id || club.Owner.UserId != from.Id ||
@@ -84,8 +84,8 @@ namespace NadekoBot.Modules.Xp.Services
bool newState; bool newState;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var club = uow._context.Clubs.GetByOwner(owner.Id); var club = uow.Clubs.GetByOwner(owner.Id);
var adminUser = uow._context.GetOrCreateUser(toAdmin); var adminUser = uow.GetOrCreateUser(toAdmin);
if (club == null || club.Owner.UserId != owner.Id || if (club == null || club.Owner.UserId != owner.Id ||
!club.Users.Contains(adminUser)) !club.Users.Contains(adminUser))
@@ -103,7 +103,7 @@ namespace NadekoBot.Modules.Xp.Services
public ClubInfo GetClubByMember(IUser user) public ClubInfo GetClubByMember(IUser user)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var member = uow._context.Clubs.GetByMember(user.Id); var member = uow.Clubs.GetByMember(user.Id);
return member; return member;
} }
@@ -121,7 +121,7 @@ namespace NadekoBot.Modules.Xp.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var club = uow._context.Clubs.GetByOwner(ownerUserId); var club = uow.Clubs.GetByOwner(ownerUserId);
if (club == null) if (club == null)
return false; return false;
@@ -148,7 +148,7 @@ namespace NadekoBot.Modules.Xp.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByName(name, discrim); club = uow.Clubs.GetByName(name, discrim);
if (club == null) if (club == null)
return false; return false;
else else
@@ -160,8 +160,8 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var du = uow._context.GetOrCreateUser(user); var du = uow.GetOrCreateUser(user);
uow._context.SaveChanges(); uow.SaveChanges();
if (du.Club != null if (du.Club != null
|| new LevelStats(du.TotalXp).Level < club.MinimumLevelReq || new LevelStats(du.TotalXp).Level < club.MinimumLevelReq
@@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Xp.Services
UserId = du.Id, UserId = du.Id,
}; };
uow._context.Set<ClubApplicants>().Add(app); uow.Set<ClubApplicants>().Add(app);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Xp.Services
discordUser = null; discordUser = null;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var club = uow._context.Clubs.GetByOwnerOrAdmin(clubOwnerUserId); var club = uow.Clubs.GetByOwnerOrAdmin(clubOwnerUserId);
if (club == null) if (club == null)
return false; return false;
@@ -204,8 +204,8 @@ namespace NadekoBot.Modules.Xp.Services
club.Applicants.Remove(applicant); club.Applicants.Remove(applicant);
//remove that user's all other applications //remove that user's all other applications
uow._context.Set<ClubApplicants>() uow.Set<ClubApplicants>()
.RemoveRange(uow._context.Set<ClubApplicants>() .RemoveRange(uow.Set<ClubApplicants>()
.AsQueryable() .AsQueryable()
.Where(x => x.UserId == applicant.User.Id)); .Where(x => x.UserId == applicant.User.Id));
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) 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()) 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) if (du.Club == null || du.Club.OwnerId == du.Id)
return false; return false;
@@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Xp.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var club = uow._context.Clubs.GetByOwner(userId); var club = uow.Clubs.GetByOwner(userId);
if (club == null) if (club == null)
return false; return false;
@@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var club = uow._context.Clubs.GetByOwner(userId); var club = uow.Clubs.GetByOwner(userId);
if (club == null) if (club == null)
return false; return false;
@@ -275,11 +275,11 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByOwner(userId); club = uow.Clubs.GetByOwner(userId);
if (club == null) if (club == null)
return false; return false;
uow._context.Clubs.Remove(club); uow.Clubs.Remove(club);
uow.SaveChanges(); uow.SaveChanges();
} }
return true; return true;
@@ -289,7 +289,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByOwnerOrAdmin(bannerId); club = uow.Clubs.GetByOwnerOrAdmin(bannerId);
if (club == null) if (club == null)
return false; return false;
@@ -322,7 +322,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByOwnerOrAdmin(ownerUserId); club = uow.Clubs.GetByOwnerOrAdmin(ownerUserId);
if (club == null) if (club == null)
return false; return false;
@@ -341,7 +341,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
club = uow._context.Clubs.GetByOwnerOrAdmin(kickerId); club = uow.Clubs.GetByOwnerOrAdmin(kickerId);
if (club == null) if (club == null)
return false; return false;
@@ -368,7 +368,7 @@ namespace NadekoBot.Modules.Xp.Services
throw new ArgumentOutOfRangeException(nameof(page)); throw new ArgumentOutOfRangeException(nameof(page));
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context.Clubs.GetClubLeaderboardPage(page); return uow.Clubs.GetClubLeaderboardPage(page);
} }
} }
} }

View File

@@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Xp.Services
public void EnsureMigrated() public void EnsureMigrated()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
using var conn = uow._context.Database.GetDbConnection(); using var conn = uow.Database.GetDbConnection();
Migrate(conn); Migrate(conn);
} }

View File

@@ -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 //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) // amounts for every user (in order to give rewards)
var usr = uow._context.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id); var usr = uow.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id);
var du = uow._context.GetOrCreateUser(item.Key.User); var du = uow.GetOrCreateUser(item.Key.User);
var globalXp = du.TotalXp; var globalXp = du.TotalXp;
var oldGlobalLevelData = new LevelStats(globalXp); var oldGlobalLevelData = new LevelStats(globalXp);
@@ -201,13 +201,13 @@ namespace NadekoBot.Modules.Xp.Services
//give role //give role
if (!roleRewards.TryGetValue(usr.GuildId, out var rrews)) 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); roleRewards.Add(usr.GuildId, rrews);
} }
if (!curRewards.TryGetValue(usr.GuildId, out var crews)) 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); curRewards.Add(usr.GuildId, crews);
} }
@@ -317,14 +317,14 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var settings = uow._context.XpSettingsFor(guildId); var settings = uow.XpSettingsFor(guildId);
if (amount <= 0) if (amount <= 0)
{ {
var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level); var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
if (toRemove != null) if (toRemove != null)
{ {
uow._context.Remove(toRemove); uow.Remove(toRemove);
settings.CurrencyRewards.Remove(toRemove); settings.CurrencyRewards.Remove(toRemove);
} }
} }
@@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
return uow._context.XpSettingsFor(id) return uow.XpSettingsFor(id)
.CurrencyRewards .CurrencyRewards
.ToArray(); .ToArray();
} }
@@ -359,7 +359,7 @@ namespace NadekoBot.Modules.Xp.Services
public IEnumerable<XpRoleReward> GetRoleRewards(ulong id) public IEnumerable<XpRoleReward> GetRoleRewards(ulong id)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context.XpSettingsFor(id) return uow.XpSettingsFor(id)
.RoleRewards .RoleRewards
.ToArray(); .ToArray();
} }
@@ -367,12 +367,12 @@ namespace NadekoBot.Modules.Xp.Services
public void ResetRoleReward(ulong guildId, int level) public void ResetRoleReward(ulong guildId, int level)
{ {
using var uow = _db.GetDbContext(); 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); var toRemove = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
if (toRemove != null) if (toRemove != null)
{ {
uow._context.Remove(toRemove); uow.Remove(toRemove);
settings.RoleRewards.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) public void SetRoleReward(ulong guildId, int level, ulong roleId, bool remove)
{ {
using var uow = _db.GetDbContext(); 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); var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
@@ -409,7 +409,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) 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()) 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()) 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()) using (var uow = _db.GetDbContext())
{ {
var user = uow._context.GetOrCreateUserXpStats(guildId, userId); var user = uow.GetOrCreateUserXpStats(guildId, userId);
user.NotifyOnLevelUp = type; user.NotifyOnLevelUp = type;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -443,7 +443,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var user = uow._context.GetOrCreateUserXpStats(guildId, userId); var user = uow.GetOrCreateUserXpStats(guildId, userId);
return user.NotifyOnLevelUp; return user.NotifyOnLevelUp;
} }
} }
@@ -452,7 +452,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) 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()) using (var uow = _db.GetDbContext())
{ {
var du = uow._context.GetOrCreateUser(user); var du = uow.GetOrCreateUser(user);
du.NotifyOnLevelUp = type; du.NotifyOnLevelUp = type;
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -657,7 +657,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var usr = uow._context.GetOrCreateUserXpStats(guildId, userId); var usr = uow.GetOrCreateUserXpStats(guildId, userId);
usr.AwardedXp += amount; usr.AwardedXp += amount;
@@ -706,11 +706,11 @@ namespace NadekoBot.Modules.Xp.Services
int guildRank; int guildRank;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
du = uow._context.GetOrCreateUser(user); du = uow.GetOrCreateUser(user);
totalXp = du.TotalXp; totalXp = du.TotalXp;
globalRank = uow._context.DiscordUser.GetUserGlobalRank(user.Id); globalRank = uow.DiscordUser.GetUserGlobalRank(user.Id);
guildRank = uow._context.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId); guildRank = uow.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId);
stats = uow._context.GetOrCreateUserXpStats(user.GuildId, user.Id); stats = uow.GetOrCreateUserXpStats(user.GuildId, user.Id);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
@@ -747,7 +747,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var xpSetting = uow._context.XpSettingsFor(id); var xpSetting = uow.XpSettingsFor(id);
if (_excludedServers.Add(id)) if (_excludedServers.Add(id))
{ {
xpSetting.ServerExcluded = true; xpSetting.ServerExcluded = true;
@@ -767,7 +767,7 @@ namespace NadekoBot.Modules.Xp.Services
var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>()); var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>());
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var xpSetting = uow._context.XpSettingsFor(guildId); var xpSetting = uow.XpSettingsFor(guildId);
var excludeObj = new ExcludedItem var excludeObj = new ExcludedItem
{ {
ItemId = rId, ItemId = rId,
@@ -790,7 +790,7 @@ namespace NadekoBot.Modules.Xp.Services
var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj)); var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj));
if (toDelete != null) if (toDelete != null)
{ {
uow._context.Remove(toDelete); uow.Remove(toDelete);
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -804,7 +804,7 @@ namespace NadekoBot.Modules.Xp.Services
var channels = _excludedChannels.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>()); var channels = _excludedChannels.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>());
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var xpSetting = uow._context.XpSettingsFor(guildId); var xpSetting = uow.XpSettingsFor(guildId);
var excludeObj = new ExcludedItem var excludeObj = new ExcludedItem
{ {
ItemId = chId, ItemId = chId,
@@ -1200,7 +1200,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.UserXpStats.ResetGuildUserXp(userId, guildId); uow.UserXpStats.ResetGuildUserXp(userId, guildId);
uow.SaveChanges(); uow.SaveChanges();
} }
} }
@@ -1209,7 +1209,7 @@ namespace NadekoBot.Modules.Xp.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.UserXpStats.ResetGuildXp(guildId); uow.UserXpStats.ResetGuildXp(guildId);
uow.SaveChanges(); uow.SaveChanges();
} }
} }
@@ -1217,15 +1217,15 @@ namespace NadekoBot.Modules.Xp.Services
public async Task ResetXpRewards(ulong guildId) public async Task ResetXpRewards(ulong guildId)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
var guildConfig = uow._context.GuildConfigsForId(guildId, var guildConfig = uow.GuildConfigsForId(guildId,
set => set set => set
.Include(x => x.XpSettings) .Include(x => x.XpSettings)
.ThenInclude(x => x.CurrencyRewards) .ThenInclude(x => x.CurrencyRewards)
.Include(x => x.XpSettings) .Include(x => x.XpSettings)
.ThenInclude(x => x.RoleRewards)); .ThenInclude(x => x.RoleRewards));
uow._context.RemoveRange(guildConfig.XpSettings.RoleRewards); uow.RemoveRange(guildConfig.XpSettings.RoleRewards);
uow._context.RemoveRange(guildConfig.XpSettings.CurrencyRewards); uow.RemoveRange(guildConfig.XpSettings.CurrencyRewards);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
} }

View File

@@ -108,7 +108,7 @@ namespace NadekoBot.Core.Services
using (var uow = _db.GetDbContext()) 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; gc.Prefix = prefix;
uow.SaveChanges(); uow.SaveChanges();
} }

View File

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

View File

@@ -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<T> where T : DbEntity
{
void Add(T obj);
}
}

View File

@@ -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<T> : IRepository<T> where T : DbEntity
{
protected DbContext _context { get; set; }
protected DbSet<T> _set { get; set; }
public Repository(DbContext context)
{
_context = context;
_set = context.Set<T>();
}
public void Add(T obj) =>
_set.Add(obj);
}
}

View File

@@ -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<int> SaveChangesAsync() =>
_context.SaveChangesAsync();
public void Dispose()
{
_context.Dispose();
GC.SuppressFinalize(this);
}
}
}

View File

@@ -57,6 +57,6 @@ namespace NadekoBot.Core.Services
return context; return context;
} }
public IUnitOfWork GetDbContext() => new UnitOfWork(GetDbContextInternal()); public NadekoContext GetDbContext() => GetDbContextInternal();
} }
} }

View File

@@ -107,7 +107,7 @@ namespace NadekoBot.Core.Services
{ {
using (var uow = _db.GetDbContext()) 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()) 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()) 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()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
settings = GreetSettings.Create(gc); settings = GreetSettings.Create(gc);
} }
@@ -351,7 +351,7 @@ namespace NadekoBot.Core.Services
using (var uow = _db.GetDbContext()) 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.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions();
conf.ChannelGreetMessageText = settings.ChannelGreetMessageText?.SanitizeMentions(); conf.ChannelGreetMessageText = settings.ChannelGreetMessageText?.SanitizeMentions();
conf.ChannelByeMessageText = settings.ChannelByeMessageText?.SanitizeMentions(); conf.ChannelByeMessageText = settings.ChannelByeMessageText?.SanitizeMentions();
@@ -382,7 +382,7 @@ namespace NadekoBot.Core.Services
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage;
conf.GreetMessageChannelId = channelId; conf.GreetMessageChannelId = channelId;
@@ -404,7 +404,7 @@ namespace NadekoBot.Core.Services
bool greetMsgEnabled; bool greetMsgEnabled;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.ChannelGreetMessageText = message; conf.ChannelGreetMessageText = message;
greetMsgEnabled = conf.SendChannelGreetMessage; greetMsgEnabled = conf.SendChannelGreetMessage;
@@ -421,7 +421,7 @@ namespace NadekoBot.Core.Services
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage;
var toAdd = GreetSettings.Create(conf); var toAdd = GreetSettings.Create(conf);
@@ -437,7 +437,7 @@ namespace NadekoBot.Core.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
return conf.SendDmGreetMessage; return conf.SendDmGreetMessage;
} }
} }
@@ -446,7 +446,7 @@ namespace NadekoBot.Core.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
return conf.SendChannelGreetMessage; return conf.SendChannelGreetMessage;
} }
} }
@@ -455,7 +455,7 @@ namespace NadekoBot.Core.Services
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
return conf.SendChannelByeMessage; return conf.SendChannelByeMessage;
} }
} }
@@ -492,7 +492,7 @@ namespace NadekoBot.Core.Services
bool greetMsgEnabled; bool greetMsgEnabled;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.DmGreetMessageText = message; conf.DmGreetMessageText = message;
greetMsgEnabled = conf.SendDmGreetMessage; greetMsgEnabled = conf.SendDmGreetMessage;
@@ -509,7 +509,7 @@ namespace NadekoBot.Core.Services
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) 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; enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage;
conf.ByeMessageChannelId = channelId; conf.ByeMessageChannelId = channelId;
@@ -531,7 +531,7 @@ namespace NadekoBot.Core.Services
bool byeMsgEnabled; bool byeMsgEnabled;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.ChannelByeMessageText = message; conf.ChannelByeMessageText = message;
byeMsgEnabled = conf.SendChannelByeMessage; byeMsgEnabled = conf.SendChannelByeMessage;
@@ -550,7 +550,7 @@ namespace NadekoBot.Core.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.AutoDeleteByeMessagesTimer = timer; conf.AutoDeleteByeMessagesTimer = timer;
var toAdd = GreetSettings.Create(conf); var toAdd = GreetSettings.Create(conf);
@@ -567,7 +567,7 @@ namespace NadekoBot.Core.Services
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var conf = uow._context.GuildConfigsForId(id, set => set); var conf = uow.GuildConfigsForId(id, set => set);
conf.AutoDeleteGreetMessagesTimer = timer; conf.AutoDeleteGreetMessagesTimer = timer;
var toAdd = GreetSettings.Create(conf); var toAdd = GreetSettings.Create(conf);

View File

@@ -33,19 +33,19 @@ namespace NadekoBot.Core.Services
}; };
private bool InternalChange(ulong userId, string userName, string discrim, string avatar, 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) if (result)
{ {
var t = GetCurrencyTransaction(userId, reason, amount); var t = GetCurrencyTransaction(userId, reason, amount);
uow._context.CurrencyTransactions.Add(t); uow.CurrencyTransactions.Add(t);
if (gamble) if (gamble)
{ {
var t2 = GetCurrencyTransaction(_bot.Id, reason, -amount); var t2 = GetCurrencyTransaction(_bot.Id, reason, -amount);
uow._context.CurrencyTransactions.Add(t2); uow.CurrencyTransactions.Add(t2);
uow._context.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true); uow.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true);
} }
} }
return result; return result;

View File

@@ -56,7 +56,7 @@ namespace NadekoBot.Core.Services.Impl
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
gc.Locale = ci.Name; gc.Locale = ci.Name;
uow.SaveChanges(); uow.SaveChanges();
} }
@@ -74,7 +74,7 @@ namespace NadekoBot.Core.Services.Impl
{ {
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
var gc = uow._context.GuildConfigsForId(guildId, set => set); var gc = uow.GuildConfigsForId(guildId, set => set);
gc.Locale = null; gc.Locale = null;
uow.SaveChanges(); uow.SaveChanges();
} }

View File

@@ -136,7 +136,7 @@ namespace NadekoBot
public IEnumerable<GuildConfig> GetCurrentGuildConfigs() public IEnumerable<GuildConfig> GetCurrentGuildConfigs()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow._context.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray(); return uow.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray();
} }
private void AddServices() private void AddServices()
@@ -147,8 +147,8 @@ namespace NadekoBot
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
uow._context.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId); uow.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId);
AllGuildConfigs = uow._context.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
} }
var s = new ServiceCollection() var s = new ServiceCollection()
@@ -314,7 +314,7 @@ namespace NadekoBot
GuildConfig gc; GuildConfig gc;
using (var uow = _db.GetDbContext()) using (var uow = _db.GetDbContext())
{ {
gc = uow._context.GuildConfigsForId(arg.Id); gc = uow.GuildConfigsForId(arg.Id);
} }
await JoinedGuild.Invoke(gc).ConfigureAwait(false); await JoinedGuild.Invoke(gc).ConfigureAwait(false);
}); });

View File

@@ -22,7 +22,7 @@ namespace NadekoBot.Core.Services
public void EnsureMigrated() public void EnsureMigrated()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
using var conn = uow._context.Database.GetDbConnection(); using var conn = uow.Database.GetDbConnection();
// check if bot config exists // check if bot config exists
using (var checkTableCommand = conn.CreateCommand()) using (var checkTableCommand = conn.CreateCommand())

View File

@@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services
public void EnsureMigrated() public void EnsureMigrated()
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
using var conn = uow._context.Database.GetDbConnection(); using var conn = uow.Database.GetDbConnection();
Migrate(conn); Migrate(conn);
} }