mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow
This commit is contained in:
@@ -76,7 +76,7 @@ namespace NadekoBot.Core.Common.TypeReaders
|
||||
long cur;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cur = uow._context.DiscordUser.GetUserCurrency(ctx.User.Id);
|
||||
cur = uow.DiscordUser.GetUserCurrency(ctx.User.Id);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
return cur;
|
||||
|
@@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId,
|
||||
var conf = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.DelMsgOnCmdChannels));
|
||||
|
||||
return (conf.DeleteMessageOnCommand, conf.DelMsgOnCmdChannels);
|
||||
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
enabled = conf.DeleteMessageOnCommand = !conf.DeleteMessageOnCommand;
|
||||
|
||||
uow.SaveChanges();
|
||||
@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId,
|
||||
var conf = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.DelMsgOnCmdChannels));
|
||||
|
||||
var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId);
|
||||
@@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
if (!(old is null))
|
||||
{
|
||||
conf.DelMsgOnCmdChannels.Remove(old);
|
||||
uow._context.Remove(old);
|
||||
uow.Remove(old);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
public async Task<IReadOnlyList<ulong>> ToggleAarAsync(ulong guildId, ulong roleId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
var roles = gc.GetAutoAssignableRoles();
|
||||
if(!roles.Remove(roleId) && roles.Count < 3)
|
||||
roles.Add(roleId);
|
||||
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
await uow._context
|
||||
await uow
|
||||
.GuildConfigs
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
@@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
gc.SetAutoAssignableRoles(newRoles);
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
@@ -46,7 +46,7 @@ DELETE FROM Clubs;";
|
||||
int res;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
res = await uow._context.Database.ExecuteSqlRawAsync(sql);
|
||||
res = await uow.Database.ExecuteSqlRawAsync(sql);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ DELETE FROM Clubs;";
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conn = uow._context.Database.GetDbConnection();
|
||||
var conn = uow.Database.GetDbConnection();
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
@@ -97,31 +97,31 @@ DELETE FROM Clubs;";
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
// get waifu info
|
||||
var wi = await uow._context.Set<WaifuInfo>()
|
||||
var wi = await uow.Set<WaifuInfo>()
|
||||
.FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId);
|
||||
|
||||
// if it exists, delete waifu related things
|
||||
if (!(wi is null))
|
||||
{
|
||||
// remove updates which have new or old as this waifu
|
||||
await uow._context
|
||||
await uow
|
||||
.WaifuUpdates
|
||||
.DeleteAsync(wu => wu.New.UserId == userId || wu.Old.UserId == userId);
|
||||
|
||||
// delete all items this waifu owns
|
||||
await uow._context
|
||||
await uow
|
||||
.Set<WaifuItem>()
|
||||
.DeleteAsync(x => x.WaifuInfoId == wi.Id);
|
||||
|
||||
// all waifus this waifu claims are released
|
||||
await uow._context
|
||||
await uow
|
||||
.Set<WaifuInfo>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Claimer.UserId == userId)
|
||||
.UpdateAsync(x => new WaifuInfo() {ClaimerId = null});
|
||||
|
||||
// all affinities set to this waifu are reset
|
||||
await uow._context
|
||||
await uow
|
||||
.Set<WaifuInfo>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Affinity.UserId == userId)
|
||||
@@ -129,16 +129,16 @@ DELETE FROM Clubs;";
|
||||
}
|
||||
|
||||
// delete guild xp
|
||||
await uow._context
|
||||
await uow
|
||||
.UserXpStats
|
||||
.DeleteAsync(x => x.UserId == userId);
|
||||
|
||||
// delete currency transactions
|
||||
await uow._context.Set<CurrencyTransaction>()
|
||||
await uow.Set<CurrencyTransaction>()
|
||||
.DeleteAsync(x => x.UserId == userId);
|
||||
|
||||
// delete user, currency, and clubs go away with it
|
||||
await uow._context.DiscordUser
|
||||
await uow.DiscordUser
|
||||
.DeleteAsync(u => u.UserId == userId);
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_db = db;
|
||||
_services = services;
|
||||
using var uow = _db.GetDbContext();
|
||||
_overrides = uow._context.DiscordPermOverrides
|
||||
_overrides = uow.DiscordPermOverrides
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.ToDictionary(o => (o.GuildId ?? 0, o.Command), o => o)
|
||||
@@ -60,14 +60,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
commandName = commandName.ToLowerInvariant();
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var over = await uow._context
|
||||
var over = await uow
|
||||
.Set<DiscordPermOverride>()
|
||||
.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.GuildId == guildId && commandName == x.Command);
|
||||
|
||||
if (over is null)
|
||||
{
|
||||
uow._context.Set<DiscordPermOverride>()
|
||||
uow.Set<DiscordPermOverride>()
|
||||
.Add(over = new DiscordPermOverride()
|
||||
{
|
||||
Command = commandName,
|
||||
@@ -90,14 +90,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var overrides = await uow._context
|
||||
var overrides = await uow
|
||||
.Set<DiscordPermOverride>()
|
||||
.AsQueryable()
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.ToListAsync();
|
||||
|
||||
uow._context.RemoveRange(overrides);
|
||||
uow.RemoveRange(overrides);
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
foreach (var over in overrides)
|
||||
@@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var over = await uow._context
|
||||
var over = await uow
|
||||
.Set<DiscordPermOverride>()
|
||||
.AsQueryable()
|
||||
.AsNoTracking()
|
||||
@@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
if (over is null)
|
||||
return;
|
||||
|
||||
uow._context.Remove(over);
|
||||
uow.Remove(over);
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
_overrides.TryRemove((guildId, commandName), out _);
|
||||
@@ -133,7 +133,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context
|
||||
return uow
|
||||
.Set<DiscordPermOverride>()
|
||||
.AsQueryable()
|
||||
.AsNoTracking()
|
||||
|
@@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
ulong? id;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
||||
if (gc.GameVoiceChannel == vchId)
|
||||
{
|
||||
|
@@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
||||
gc.TimeZoneId = tz?.Id;
|
||||
uow.SaveChanges();
|
||||
|
@@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context
|
||||
var configs = uow
|
||||
.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(gc => gc.LogSetting)
|
||||
@@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
int removed = 0;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.LogSettingsFor(gid);
|
||||
var config = uow.LogSettingsFor(gid);
|
||||
LogSetting logSetting = GuildLogSettings.GetOrAdd(gid, (id) => config.LogSetting);
|
||||
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
|
||||
config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
|
||||
@@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
LogSetting logSetting;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
logSetting = uow._context.LogSettingsFor(guildId).LogSetting;
|
||||
logSetting = uow.LogSettingsFor(guildId).LogSetting;
|
||||
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
|
||||
logSetting.LogOtherId =
|
||||
logSetting.MessageUpdatedId =
|
||||
@@ -256,7 +256,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
ulong? channelId = null;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var logSetting = uow._context.LogSettingsFor(gid).LogSetting;
|
||||
var logSetting = uow.LogSettingsFor(gid).LogSetting;
|
||||
GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
|
||||
switch (type)
|
||||
{
|
||||
@@ -1220,7 +1220,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var newLogSetting = uow._context.LogSettingsFor(guildId).LogSetting;
|
||||
var newLogSetting = uow.LogSettingsFor(guildId).LogSetting;
|
||||
switch (logChannelType)
|
||||
{
|
||||
case LogType.Other:
|
||||
|
@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context.Set<GuildConfig>().AsQueryable()
|
||||
var configs = uow.Set<GuildConfig>().AsQueryable()
|
||||
.Include(x => x.MutedUsers)
|
||||
.Include(x => x.UnbanTimer)
|
||||
.Include(x => x.UnmuteTimers)
|
||||
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var config = uow.GuildConfigsForId(guildId, set => set);
|
||||
config.MuteRoleName = name;
|
||||
GuildMuteRoles.AddOrUpdate(guildId, name, (id, old) => name);
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
StopTimer(usr.GuildId, usr.Id, TimerType.Mute);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(usr.Guild.Id,
|
||||
var config = uow.GuildConfigsForId(usr.Guild.Id,
|
||||
set => set.Include(gc => gc.MutedUsers)
|
||||
.Include(gc => gc.UnmuteTimers));
|
||||
config.MutedUsers.Add(new MutedUserId()
|
||||
@@ -231,7 +231,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
StopTimer(guildId, usrId, TimerType.Mute);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers)
|
||||
var config = uow.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers)
|
||||
.Include(gc => gc.UnmuteTimers));
|
||||
var match = new MutedUserId()
|
||||
{
|
||||
@@ -240,7 +240,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
var toRemove = config.MutedUsers.FirstOrDefault(x => x.Equals(match));
|
||||
if (toRemove != null)
|
||||
{
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
}
|
||||
if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet<ulong> muted))
|
||||
muted.TryRemove(usrId);
|
||||
@@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
await MuteUser(user, mod, muteType, reason).ConfigureAwait(false); // mute the user. This will also remove any previous unmute timers
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
|
||||
config.UnmuteTimers.Add(new UnmuteTimer()
|
||||
{
|
||||
UserId = user.Id,
|
||||
@@ -343,7 +343,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
||||
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
||||
config.UnbanTimer.Add(new UnbanTimer()
|
||||
{
|
||||
UserId = user.Id,
|
||||
@@ -360,7 +360,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
await user.AddRoleAsync(role).ConfigureAwait(false);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
|
||||
config.UnroleTimer.Add(new UnroleTimer()
|
||||
{
|
||||
UserId = user.Id,
|
||||
@@ -458,17 +458,17 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
object toDelete;
|
||||
if (type == TimerType.Mute)
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.UnmuteTimers));
|
||||
var config = uow.GuildConfigsForId(guildId, set => set.Include(x => x.UnmuteTimers));
|
||||
toDelete = config.UnmuteTimers.FirstOrDefault(x => x.UserId == userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.UnbanTimer));
|
||||
var config = uow.GuildConfigsForId(guildId, set => set.Include(x => x.UnbanTimer));
|
||||
toDelete = config.UnbanTimer.FirstOrDefault(x => x.UserId == userId);
|
||||
}
|
||||
if (toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
}
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
rotatingStatuses = uow._context.RotatingStatus
|
||||
rotatingStatuses = uow.RotatingStatus
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Id)
|
||||
.ToList();
|
||||
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var toRemove = await uow._context.RotatingStatus
|
||||
var toRemove = await uow.RotatingStatus
|
||||
.AsQueryable()
|
||||
.AsNoTracking()
|
||||
.Skip(index)
|
||||
@@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
if (toRemove is null)
|
||||
return null;
|
||||
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
await uow.SaveChangesAsync();
|
||||
return toRemove.Status;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toAdd = new RotatingPlayingStatus {Status = status, Type = t};
|
||||
uow._context.Add(toAdd);
|
||||
uow.Add(toAdd);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
public IReadOnlyList<RotatingPlayingStatus> GetRotatingStatuses()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context.RotatingStatus.AsNoTracking().ToList();
|
||||
return uow.RotatingStatus.AsNoTracking().ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
var ids = client.GetGuildIds();
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.AntiRaidSetting)
|
||||
.Include(x => x.AntiSpamSetting)
|
||||
@@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private Task _bot_JoinedGuild(GuildConfig gc)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var gcWithData = uow._context.GuildConfigsForId(gc.GuildId,
|
||||
var gcWithData = uow.GuildConfigsForId(gc.GuildId,
|
||||
set => set
|
||||
.Include(x => x.AntiRaidSetting)
|
||||
.Include(x => x.AntiAltSetting)
|
||||
@@ -304,7 +304,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting));
|
||||
|
||||
gc.AntiRaidSetting = stats.AntiRaidSettings;
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -319,7 +319,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting));
|
||||
|
||||
gc.AntiRaidSetting = null;
|
||||
uow.SaveChanges();
|
||||
@@ -336,7 +336,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
removed.UserStats.ForEach(x => x.Value.Dispose());
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)
|
||||
.ThenInclude(x => x.IgnoredChannels));
|
||||
|
||||
gc.AntiSpamSetting = null;
|
||||
@@ -375,7 +375,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting));
|
||||
|
||||
if (gc.AntiSpamSetting != null)
|
||||
{
|
||||
@@ -402,7 +402,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool added;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels));
|
||||
var spam = gc.AntiSpamSetting;
|
||||
if (spam is null)
|
||||
{
|
||||
@@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
else
|
||||
{
|
||||
var toRemove = spam.IgnoredChannels.First(x => x.ChannelId == channelId);
|
||||
uow._context.Set<AntiSpamIgnore>().Remove(toRemove); // remove from db
|
||||
uow.Set<AntiSpamIgnore>().Remove(toRemove); // remove from db
|
||||
if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
|
||||
{
|
||||
temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache
|
||||
@@ -459,7 +459,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
int actionDurationMinutes = 0, ulong? roleId = null)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
|
||||
gc.AntiAltSetting = new AntiAltSetting()
|
||||
{
|
||||
Action = action,
|
||||
@@ -478,7 +478,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
return false;
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
|
||||
gc.AntiAltSetting = null;
|
||||
await uow.SaveChangesAsync();
|
||||
return true;
|
||||
|
@@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(id, set => set
|
||||
var gc = uow.GuildConfigsForId(id, set => set
|
||||
.Include(x => x.ReactionRoleMessages)
|
||||
.ThenInclude(x => x.ReactionRoles));
|
||||
if (gc.ReactionRoleMessages.Count >= 10)
|
||||
@@ -174,10 +174,10 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(id,
|
||||
var gc = uow.GuildConfigsForId(id,
|
||||
set => set.Include(x => x.ReactionRoleMessages)
|
||||
.ThenInclude(x => x.ReactionRoles));
|
||||
uow._context.Set<ReactionRole>()
|
||||
uow.Set<ReactionRole>()
|
||||
.RemoveRange(gc.ReactionRoleMessages[index].ReactionRoles);
|
||||
gc.ReactionRoleMessages.RemoveAt(index);
|
||||
_models.AddOrUpdate(id,
|
||||
|
@@ -43,13 +43,13 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
var roles = uow.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uow._context.SelfAssignableRoles.Add(new SelfAssignedRole
|
||||
uow.SelfAssignableRoles.Add(new SelfAssignedRole
|
||||
{
|
||||
Group = group,
|
||||
RoleId = role.Id,
|
||||
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool newval;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var config = uow.GuildConfigsForId(guildId, set => set);
|
||||
newval = config.AutoDeleteSelfAssignedRoleMessages = !config.AutoDeleteSelfAssignedRoleMessages;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
LevelStats userLevelData;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var stats = uow._context.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id);
|
||||
var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id);
|
||||
userLevelData = new LevelStats(stats.Xp + stats.AwardedXp);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool set = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames));
|
||||
var gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames));
|
||||
var toUpdate = gc.SelfAssignableRoleGroupNames.FirstOrDefault(x => x.Number == group);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
@@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool success;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
success = uow._context.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
||||
success = uow.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
return success;
|
||||
@@ -207,10 +207,10 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
var autoDelete = gc.AutoDeleteSelfAssignedRoleMessages;
|
||||
var exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
var roles = uow.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
|
||||
return (autoDelete, exclusive, roles);
|
||||
}
|
||||
@@ -220,7 +220,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
var roles = uow.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
var sar = roles.FirstOrDefault(x => x.RoleId == role.Id);
|
||||
if (sar != null)
|
||||
{
|
||||
@@ -241,7 +241,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
bool areExclusive;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var config = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
||||
areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
|
||||
uow.SaveChanges();
|
||||
@@ -257,13 +257,13 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
IDictionary<int, string> groupNames;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames));
|
||||
var gc = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames));
|
||||
exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||
groupNames = gc.SelfAssignableRoleGroupNames.ToDictionary(x => x.Number, x => x.Name);
|
||||
var roleModels = uow._context.SelfAssignableRoles.GetFromGuild(guild.Id);
|
||||
var roleModels = uow.SelfAssignableRoles.GetFromGuild(guild.Id);
|
||||
roles = roleModels
|
||||
.Select(x => (Model: x, Role: guild.GetRole(x.RoleId)));
|
||||
uow._context.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray());
|
||||
uow.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray());
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
|
@@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
_autoCommands = uow._context
|
||||
_autoCommands = uow
|
||||
.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval >= 5)
|
||||
@@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
.ToConcurrent())
|
||||
.ToConcurrent();
|
||||
|
||||
var startupCommands = uow._context.AutoCommands.AsNoTracking().Where(x => x.Interval == 0);
|
||||
var startupCommands = uow.AutoCommands.AsNoTracking().Where(x => x.Interval == 0);
|
||||
foreach (var cmd in startupCommands)
|
||||
{
|
||||
try
|
||||
@@ -163,7 +163,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.AutoCommands.Add(cmd);
|
||||
uow.AutoCommands.Add(cmd);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
public IEnumerable<AutoCommand> GetStartupCommands()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context
|
||||
return uow
|
||||
.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval == 0)
|
||||
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
public IEnumerable<AutoCommand> GetAutoCommands()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context
|
||||
return uow
|
||||
.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval >= 5)
|
||||
@@ -297,7 +297,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cmd = uow._context.AutoCommands
|
||||
cmd = uow.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval == 0)
|
||||
.Skip(index)
|
||||
@@ -305,7 +305,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
if (cmd != null)
|
||||
{
|
||||
uow._context.Remove(cmd);
|
||||
uow.Remove(cmd);
|
||||
uow.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
@@ -318,7 +318,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cmd = uow._context.AutoCommands
|
||||
cmd = uow.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval >= 5)
|
||||
.Skip(index)
|
||||
@@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
if (cmd != null)
|
||||
{
|
||||
uow._context.Remove(cmd);
|
||||
uow.Remove(cmd);
|
||||
if (_autoCommands.TryGetValue(cmd.GuildId, out var autos))
|
||||
if (autos.TryRemove(cmd.Id, out var timer))
|
||||
timer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
@@ -369,12 +369,12 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var toRemove = uow._context
|
||||
var toRemove = uow
|
||||
.AutoCommands
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Interval == 0);
|
||||
|
||||
uow._context.AutoCommands.RemoveRange(toRemove);
|
||||
uow.AutoCommands.RemoveRange(toRemove);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
@@ -61,16 +61,16 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
List<WarningPunishment> ps;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments))
|
||||
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments))
|
||||
.WarnPunishments;
|
||||
|
||||
warnings += uow._context
|
||||
warnings += uow
|
||||
.Warnings
|
||||
.ForId(guildId, userId)
|
||||
.Where(w => !w.Forgiven && w.UserId == userId)
|
||||
.Count();
|
||||
|
||||
uow._context.Warnings.Add(warn);
|
||||
uow.Warnings.Add(warn);
|
||||
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -169,14 +169,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var cleared = await uow._context.Database.ExecuteSqlRawAsync($@"UPDATE Warnings
|
||||
var cleared = await uow.Database.ExecuteSqlRawAsync($@"UPDATE Warnings
|
||||
SET Forgiven = 1,
|
||||
ForgivenBy = 'Expiry'
|
||||
WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 0)
|
||||
AND Forgiven = 0
|
||||
AND DateAdded < datetime('now', (SELECT '-' || WarnExpireHours || ' hours' FROM GuildConfigs as gc WHERE gc.GuildId = Warnings.GuildId));");
|
||||
|
||||
var deleted = await uow._context.Database.ExecuteSqlRawAsync($@"DELETE FROM Warnings
|
||||
var deleted = await uow.Database.ExecuteSqlRawAsync($@"DELETE FROM Warnings
|
||||
WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND WarnExpireAction = 1)
|
||||
AND DateAdded < datetime('now', (SELECT '-' || WarnExpireHours || ' hours' FROM GuildConfigs as gc WHERE gc.GuildId = Warnings.GuildId));");
|
||||
|
||||
@@ -191,7 +191,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, inc => inc);
|
||||
var config = uow.GuildConfigsForId(guildId, inc => inc);
|
||||
|
||||
if (config.WarnExpireHours == 0)
|
||||
return;
|
||||
@@ -199,7 +199,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND
|
||||
var hours = $"{-config.WarnExpireHours} hours";
|
||||
if (config.WarnExpireAction == WarnExpireAction.Clear)
|
||||
{
|
||||
await uow._context.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings
|
||||
await uow.Database.ExecuteSqlInterpolatedAsync($@"UPDATE warnings
|
||||
SET Forgiven = 1,
|
||||
ForgivenBy = 'Expiry'
|
||||
WHERE GuildId={guildId}
|
||||
@@ -208,7 +208,7 @@ WHERE GuildId={guildId}
|
||||
}
|
||||
else if (config.WarnExpireAction == WarnExpireAction.Delete)
|
||||
{
|
||||
await uow._context.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings
|
||||
await uow.Database.ExecuteSqlInterpolatedAsync($@"DELETE FROM warnings
|
||||
WHERE GuildId={guildId}
|
||||
AND DateAdded < datetime('now', {hours})");
|
||||
}
|
||||
@@ -220,7 +220,7 @@ WHERE GuildId={guildId}
|
||||
public Task<int> GetWarnExpire(ulong guildId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var config = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var config = uow.GuildConfigsForId(guildId, set => set);
|
||||
return Task.FromResult(config.WarnExpireHours / 24);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId, inc => inc);
|
||||
var config = uow.GuildConfigsForId(guildId, inc => inc);
|
||||
|
||||
config.WarnExpireHours = days * 24;
|
||||
config.WarnExpireAction = delete ? WarnExpireAction.Delete : WarnExpireAction.Clear;
|
||||
@@ -246,7 +246,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.Warnings.GetForGuild(gid).GroupBy(x => x.UserId).ToArray();
|
||||
return uow.Warnings.GetForGuild(gid).GroupBy(x => x.UserId).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.Warnings.ForId(gid, userId);
|
||||
return uow.Warnings.ForId(gid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,11 +265,11 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
await uow._context.Warnings.ForgiveAll(guildId, userId, moderator);
|
||||
await uow.Warnings.ForgiveAll(guildId, userId, moderator);
|
||||
}
|
||||
else
|
||||
{
|
||||
toReturn = uow._context.Warnings.Forgive(guildId, userId, moderator, index - 1);
|
||||
toReturn = uow.Warnings.Forgive(guildId, userId, moderator, index - 1);
|
||||
}
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -286,10 +286,10 @@ WHERE GuildId={guildId}
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
||||
var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
||||
var toDelete = ps.Where(x => x.Count == number);
|
||||
|
||||
uow._context.RemoveRange(toDelete);
|
||||
uow.RemoveRange(toDelete);
|
||||
|
||||
ps.Add(new WarningPunishment()
|
||||
{
|
||||
@@ -310,12 +310,12 @@ WHERE GuildId={guildId}
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var ps = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
||||
var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
||||
var p = ps.FirstOrDefault(x => x.Count == number);
|
||||
|
||||
if (p != null)
|
||||
{
|
||||
uow._context.Remove(p);
|
||||
uow.Remove(p);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -326,7 +326,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GuildConfigsForId(guildId, gc => gc.Include(x => x.WarnPunishments))
|
||||
return uow.GuildConfigsForId(guildId, gc => gc.Include(x => x.WarnPunishments))
|
||||
.WarnPunishments
|
||||
.OrderBy(x => x.Count)
|
||||
.ToArray();
|
||||
@@ -374,7 +374,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var template = uow._context.BanTemplates
|
||||
var template = uow.BanTemplates
|
||||
.AsQueryable()
|
||||
.FirstOrDefault(x => x.GuildId == guildId);
|
||||
return template?.Text;
|
||||
@@ -385,7 +385,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var template = uow._context.BanTemplates
|
||||
var template = uow.BanTemplates
|
||||
.AsQueryable()
|
||||
.FirstOrDefault(x => x.GuildId == guildId);
|
||||
|
||||
@@ -394,11 +394,11 @@ WHERE GuildId={guildId}
|
||||
if (template is null)
|
||||
return;
|
||||
|
||||
uow._context.Remove(template);
|
||||
uow.Remove(template);
|
||||
}
|
||||
else if (template == null)
|
||||
{
|
||||
uow._context.BanTemplates.Add(new BanTemplate()
|
||||
uow.BanTemplates.Add(new BanTemplate()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Text = text,
|
||||
|
@@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.VcRoleInfos)
|
||||
.Where(x => guildIds.Contains(x.GuildId))
|
||||
@@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
// need to load new guildconfig with vc role included
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var configWithVcRole = uow._context.GuildConfigsForId(
|
||||
var configWithVcRole = uow.GuildConfigsForId(
|
||||
arg.GuildId,
|
||||
set => set.Include(x => x.VcRoleInfos)
|
||||
);
|
||||
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}");
|
||||
uow._context.RemoveRange(missingRoles);
|
||||
uow.RemoveRange(missingRoles);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@@ -144,11 +144,11 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
guildVcRoles.AddOrUpdate(vcId, role, (key, old) => role);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos));
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos));
|
||||
var toDelete = conf.VcRoleInfos.FirstOrDefault(x => x.VoiceChannelId == vcId); // remove old one
|
||||
if(toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
}
|
||||
conf.VcRoleInfos.Add(new VcRoleInfo()
|
||||
{
|
||||
@@ -169,9 +169,9 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos));
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos));
|
||||
var toRemove = conf.VcRoleInfos.Where(x => x.VoiceChannelId == vcId).ToList();
|
||||
uow._context.RemoveRange(toRemove);
|
||||
uow.RemoveRange(toRemove);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
|
@@ -90,7 +90,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var guildItems = await uow._context.CustomReactions
|
||||
var guildItems = await uow.CustomReactions
|
||||
.AsNoTracking()
|
||||
.Where(x => allGuildIds.Contains(x.GuildId.Value))
|
||||
.ToListAsync();
|
||||
@@ -107,7 +107,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
|
||||
lock (_gcrWriteLock)
|
||||
{
|
||||
var globalItems = uow._context
|
||||
var globalItems = uow
|
||||
.CustomReactions
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId == null || x.GuildId == 0)
|
||||
@@ -195,7 +195,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
private async Task OnJoinedGuild(GuildConfig gc)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var crs = await uow._context
|
||||
var crs = await uow
|
||||
.CustomReactions
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId == gc.GuildId)
|
||||
@@ -223,7 +223,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.CustomReactions.Add(cr);
|
||||
uow.CustomReactions.Add(cr);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
public async Task<CustomReaction> EditAsync(ulong? guildId, int id, string message)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var cr = uow._context.CustomReactions.GetById(id);
|
||||
var cr = uow.CustomReactions.GetById(id);
|
||||
|
||||
if (cr == null || cr.GuildId != guildId)
|
||||
return null;
|
||||
@@ -263,14 +263,14 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
public async Task<CustomReaction> DeleteAsync(ulong? guildId, int id)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toDelete = uow._context.CustomReactions.GetById(id);
|
||||
var toDelete = uow.CustomReactions.GetById(id);
|
||||
|
||||
if (toDelete is null)
|
||||
return null;
|
||||
|
||||
if ((toDelete.IsGlobal() && guildId == null) || (guildId == toDelete.GuildId))
|
||||
{
|
||||
uow._context.CustomReactions.Remove(toDelete);
|
||||
uow.CustomReactions.Remove(toDelete);
|
||||
await uow.SaveChangesAsync();
|
||||
await DeleteInternalAsync(guildId, id);
|
||||
return toDelete;
|
||||
@@ -469,7 +469,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
{
|
||||
CustomReaction cr;
|
||||
using var uow = _db.GetDbContext();
|
||||
cr = uow._context.CustomReactions.GetById(id);
|
||||
cr = uow.CustomReactions.GetById(id);
|
||||
if (cr is null)
|
||||
return;
|
||||
|
||||
@@ -587,7 +587,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
CustomReaction cr;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cr = uow._context.CustomReactions.GetById(id);
|
||||
cr = uow.CustomReactions.GetById(id);
|
||||
if (cr is null)
|
||||
return;
|
||||
|
||||
@@ -605,7 +605,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
CustomReaction cr;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cr = uow._context.CustomReactions.GetById(id);
|
||||
cr = uow.CustomReactions.GetById(id);
|
||||
if (cr is null)
|
||||
return (false, false);
|
||||
if (field == CrField.AutoDelete)
|
||||
@@ -628,7 +628,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
public CustomReaction GetCustomReaction(ulong? guildId, int id)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var cr = uow._context.CustomReactions.GetById(id);
|
||||
var cr = uow.CustomReactions.GetById(id);
|
||||
if (cr == null || cr.GuildId != guildId)
|
||||
return null;
|
||||
|
||||
@@ -638,7 +638,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
public int DeleteAllCustomReactions(ulong guildId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var count = uow._context.CustomReactions.ClearFromGuild(guildId);
|
||||
var count = uow.CustomReactions.ClearFromGuild(guildId);
|
||||
uow.SaveChanges();
|
||||
|
||||
_newGuildReactions.TryRemove(guildId, out _);
|
||||
@@ -649,7 +649,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
public bool ReactionExists(ulong? guildId, string input)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var cr = uow._context.CustomReactions.GetByGuildIdAndInput(guildId, input);
|
||||
var cr = uow.CustomReactions.GetByGuildIdAndInput(guildId, input);
|
||||
return cr != null;
|
||||
}
|
||||
|
||||
@@ -705,7 +705,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
foreach (var entry in data)
|
||||
{
|
||||
var trigger = entry.Key;
|
||||
await uow._context.CustomReactions.AddRangeAsync(entry.Value
|
||||
await uow.CustomReactions.AddRangeAsync(entry.Value
|
||||
.Where(cr => !string.IsNullOrWhiteSpace(cr.Res))
|
||||
.Select(cr => new CustomReaction()
|
||||
{
|
||||
|
@@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return n(uow._context.DiscordUser.GetUserCurrency(id));
|
||||
return n(uow.DiscordUser.GetUserCurrency(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var trs = new List<CurrencyTransaction>();
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
trs = uow._context.CurrencyTransactions.GetPageFor(userId, page);
|
||||
trs = uow.CurrencyTransactions.GetPageFor(userId, page);
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
@@ -522,7 +522,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cleanRichest = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000);
|
||||
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000);
|
||||
}
|
||||
|
||||
await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||
@@ -536,7 +536,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cleanRichest = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
|
||||
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
toSend = uow._context.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage);
|
||||
toSend = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
if (maxDecay == 0)
|
||||
maxDecay = int.MaxValue;
|
||||
|
||||
uow._context.Database.ExecuteSqlInterpolated($@"
|
||||
uow.Database.ExecuteSqlInterpolated($@"
|
||||
UPDATE DiscordUser
|
||||
SET CurrencyAmount=
|
||||
CASE WHEN
|
||||
@@ -80,32 +80,6 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
|
||||
}
|
||||
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
||||
}
|
||||
|
||||
//using (var uow = _db.UnitOfWork)
|
||||
//{
|
||||
// //refund all of the currency users had at stake in gambling games
|
||||
// //at the time bot was restarted
|
||||
|
||||
// var stakes = uow._context.Set<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
|
||||
@@ -136,11 +110,11 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
cash = uow._context.DiscordUser.GetTotalCurrency();
|
||||
onePercent = uow._context.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id);
|
||||
planted = uow._context.PlantedCurrency.AsQueryable().Sum(x => x.Amount);
|
||||
waifus = uow._context.WaifuInfo.GetTotalValue();
|
||||
bot = uow._context.DiscordUser.GetUserCurrency(_client.CurrentUser.Id);
|
||||
cash = uow.DiscordUser.GetTotalCurrency();
|
||||
onePercent = uow.DiscordUser.GetTopOnePercentCurrency(_client.CurrentUser.Id);
|
||||
planted = uow.PlantedCurrency.AsQueryable().Sum(x => x.Amount);
|
||||
waifus = uow.WaifuInfo.GetTotalValue();
|
||||
bot = uow.DiscordUser.GetUserCurrency(_client.CurrentUser.Id);
|
||||
}
|
||||
|
||||
var result = new EconomyResult
|
||||
|
@@ -19,8 +19,8 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
_db = db;
|
||||
}
|
||||
|
||||
private IndexedCollection<ShopEntry> GetEntriesInternal(IUnitOfWork uow, ulong guildId) =>
|
||||
uow._context.GuildConfigsForId(
|
||||
private IndexedCollection<ShopEntry> GetEntriesInternal(NadekoContext uow, ulong guildId) =>
|
||||
uow.GuildConfigsForId(
|
||||
guildId,
|
||||
set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items)
|
||||
)
|
||||
|
@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.GenerateCurrencyChannelIds)
|
||||
.Where(x => guildIds.Contains(x.GuildId))
|
||||
@@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var guildConfig = uow._context.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds));
|
||||
var guildConfig = uow.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds));
|
||||
|
||||
var toAdd = new GCChannelId() { ChannelId = cid };
|
||||
if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
|
||||
@@ -93,7 +93,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
|
||||
if (toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
}
|
||||
_generationChannels.TryRemove(cid);
|
||||
enabled = false;
|
||||
@@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var chs = uow._context.GuildConfigs.GetGeneratingChannels();
|
||||
var chs = uow.GuildConfigs.GetGeneratingChannels();
|
||||
return chs;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
|
||||
pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant();
|
||||
// gets all plants in this channel with the same password
|
||||
var entries = uow._context.PlantedCurrency
|
||||
var entries = uow.PlantedCurrency
|
||||
.AsQueryable()
|
||||
.Where(x => x.ChannelId == ch.Id && pass == x.Password)
|
||||
.ToList();
|
||||
@@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
amount = entries.Sum(x => x.Amount);
|
||||
ids = entries.Select(x => x.MessageId).ToArray();
|
||||
// remove them from the database
|
||||
uow._context.RemoveRange(entries);
|
||||
uow.RemoveRange(entries);
|
||||
|
||||
|
||||
if (amount > 0)
|
||||
@@ -369,7 +369,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.PlantedCurrency.Add(new PlantedCurrency
|
||||
uow.PlantedCurrency.Add(new PlantedCurrency
|
||||
{
|
||||
Amount = amount,
|
||||
GuildId = gid,
|
||||
|
@@ -46,8 +46,8 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var waifu = uow._context.WaifuInfo.ByWaifuUserId(waifuId);
|
||||
var ownerUser = uow._context.GetOrCreateUser(owner);
|
||||
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
|
||||
var ownerUser = uow.GetOrCreateUser(owner);
|
||||
|
||||
// owner has to be the owner of the waifu
|
||||
if (waifu == null || waifu.ClaimerId != ownerUser.Id)
|
||||
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
}
|
||||
|
||||
//new claimerId is the id of the new owner
|
||||
var newOwnerUser = uow._context.GetOrCreateUser(newOwner);
|
||||
var newOwnerUser = uow.GetOrCreateUser(newOwner);
|
||||
waifu.ClaimerId = newOwnerUser.Id;
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -96,16 +96,16 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
var settings = _gss.Data;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
|
||||
if (waifu == null)
|
||||
return settings.Waifu.MinPrice;
|
||||
|
||||
var divorces = uow._context.WaifuUpdates.Count(x => x.Old != null &&
|
||||
var divorces = uow.WaifuUpdates.Count(x => x.Old != null &&
|
||||
x.Old.UserId == user.Id &&
|
||||
x.UpdateType == WaifuUpdateType.Claimed &&
|
||||
x.New == null);
|
||||
var affs = uow._context.WaifuUpdates
|
||||
var affs = uow.WaifuUpdates
|
||||
.AsQueryable()
|
||||
.Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged &&
|
||||
w.New != null)
|
||||
@@ -126,13 +126,13 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
|
||||
return false;
|
||||
|
||||
var affs = uow._context.WaifuUpdates
|
||||
var affs = uow.WaifuUpdates
|
||||
.AsQueryable()
|
||||
.Where(w => w.User.UserId == user.Id
|
||||
&& w.UpdateType == WaifuUpdateType.AffinityChanged
|
||||
&& w.New != null);
|
||||
|
||||
var divorces = uow._context.WaifuUpdates
|
||||
var divorces = uow.WaifuUpdates
|
||||
.AsQueryable()
|
||||
.Where(x => x.Old != null &&
|
||||
x.Old.UserId == user.Id &&
|
||||
@@ -140,10 +140,10 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
x.New == null);
|
||||
|
||||
//reset changes of heart to 0
|
||||
uow._context.WaifuUpdates.RemoveRange(affs);
|
||||
uow.WaifuUpdates.RemoveRange(affs);
|
||||
//reset divorces to 0
|
||||
uow._context.WaifuUpdates.RemoveRange(divorces);
|
||||
var waifu = uow._context.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
uow.WaifuUpdates.RemoveRange(divorces);
|
||||
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
//reset price, remove items
|
||||
//remove owner, remove affinity
|
||||
waifu.Price = 50;
|
||||
@@ -167,26 +167,26 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
bool isAffinity;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
w = uow._context.WaifuInfo.ByWaifuUserId(target.Id);
|
||||
w = uow.WaifuInfo.ByWaifuUserId(target.Id);
|
||||
isAffinity = (w?.Affinity?.UserId == user.Id);
|
||||
if (w == null)
|
||||
{
|
||||
var claimer = uow._context.GetOrCreateUser(user);
|
||||
var waifu = uow._context.GetOrCreateUser(target);
|
||||
var claimer = uow.GetOrCreateUser(user);
|
||||
var waifu = uow.GetOrCreateUser(target);
|
||||
if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
|
||||
{
|
||||
result = WaifuClaimResult.NotEnoughFunds;
|
||||
}
|
||||
else
|
||||
{
|
||||
uow._context.WaifuInfo.Add(w = new WaifuInfo()
|
||||
uow.WaifuInfo.Add(w = new WaifuInfo()
|
||||
{
|
||||
Waifu = waifu,
|
||||
Claimer = claimer,
|
||||
Affinity = null,
|
||||
Price = amount
|
||||
});
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = waifu,
|
||||
Old = null,
|
||||
@@ -205,11 +205,11 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
else
|
||||
{
|
||||
var oldClaimer = w.Claimer;
|
||||
w.Claimer = uow._context.GetOrCreateUser(user);
|
||||
w.Claimer = uow.GetOrCreateUser(user);
|
||||
w.Price = amount + (amount / 4);
|
||||
result = WaifuClaimResult.Success;
|
||||
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = w.Waifu,
|
||||
Old = oldClaimer,
|
||||
@@ -227,11 +227,11 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
else
|
||||
{
|
||||
var oldClaimer = w.Claimer;
|
||||
w.Claimer = uow._context.GetOrCreateUser(user);
|
||||
w.Claimer = uow.GetOrCreateUser(user);
|
||||
w.Price = amount;
|
||||
result = WaifuClaimResult.Success;
|
||||
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = w.Waifu,
|
||||
Old = oldClaimer,
|
||||
@@ -257,8 +257,8 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
TimeSpan? remaining = null;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var w = uow._context.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
var newAff = target == null ? null : uow._context.GetOrCreateUser(target);
|
||||
var w = uow.WaifuInfo.ByWaifuUserId(user.Id);
|
||||
var newAff = target == null ? null : uow.GetOrCreateUser(target);
|
||||
if (w?.Affinity?.UserId == target?.Id)
|
||||
{
|
||||
}
|
||||
@@ -267,8 +267,8 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
}
|
||||
else if (w == null)
|
||||
{
|
||||
var thisUser = uow._context.GetOrCreateUser(user);
|
||||
uow._context.WaifuInfo.Add(new WaifuInfo()
|
||||
var thisUser = uow.GetOrCreateUser(user);
|
||||
uow.WaifuInfo.Add(new WaifuInfo()
|
||||
{
|
||||
Affinity = newAff,
|
||||
Waifu = thisUser,
|
||||
@@ -277,7 +277,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
});
|
||||
success = true;
|
||||
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = thisUser,
|
||||
Old = null,
|
||||
@@ -292,7 +292,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
w.Affinity = newAff;
|
||||
success = true;
|
||||
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = w.Waifu,
|
||||
Old = oldAff,
|
||||
@@ -311,14 +311,14 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.WaifuInfo.GetTop(9, page * 9);
|
||||
return uow.WaifuInfo.GetTop(9, page * 9);
|
||||
}
|
||||
}
|
||||
|
||||
public ulong GetWaifuUserId(ulong ownerId, string name)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context.WaifuInfo.GetWaifuUserId(ownerId, name);
|
||||
return uow.WaifuInfo.GetWaifuUserId(ownerId, name);
|
||||
}
|
||||
|
||||
public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId)
|
||||
@@ -329,7 +329,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
WaifuInfo w = null;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
w = uow._context.WaifuInfo.ByWaifuUserId(targetId);
|
||||
w = uow.WaifuInfo.ByWaifuUserId(targetId);
|
||||
var now = DateTime.UtcNow;
|
||||
if (w?.Claimer == null || w.Claimer.UserId != user.Id)
|
||||
result = DivorceResult.NotYourWife;
|
||||
@@ -357,7 +357,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
var oldClaimer = w.Claimer;
|
||||
w.Claimer = null;
|
||||
|
||||
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
||||
uow.WaifuUpdates.Add(new WaifuUpdate()
|
||||
{
|
||||
User = w.Waifu,
|
||||
Old = oldClaimer,
|
||||
@@ -381,17 +381,17 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var w = uow._context.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
|
||||
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
|
||||
set => set.Include(x => x.Items)
|
||||
.Include(x => x.Claimer));
|
||||
if (w == null)
|
||||
{
|
||||
uow._context.WaifuInfo.Add(w = new WaifuInfo()
|
||||
uow.WaifuInfo.Add(w = new WaifuInfo()
|
||||
{
|
||||
Affinity = null,
|
||||
Claimer = null,
|
||||
Price = 1,
|
||||
Waifu = uow._context.GetOrCreateUser(giftedWaifu),
|
||||
Waifu = uow.GetOrCreateUser(giftedWaifu),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var wi = uow._context.GetWaifuInfo(targetId);
|
||||
var wi = uow.GetWaifuInfo(targetId);
|
||||
if (wi is null)
|
||||
{
|
||||
wi = new WaifuInfoStats
|
||||
@@ -445,7 +445,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var du = uow._context.GetOrCreateUser(target);
|
||||
var du = uow.GetOrCreateUser(target);
|
||||
|
||||
return GetFullWaifuInfoAsync(target.Id);
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
throw new ArgumentOutOfRangeException(nameof(page));
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var entries = uow._context.GuildConfigsForId(ctx.Guild.Id,
|
||||
var entries = uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
set => set.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items)).ShopEntries
|
||||
.ToIndexed();
|
||||
@@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
ShopEntry entry;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
|
||||
.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items));
|
||||
var entries = new IndexedCollection<ShopEntry>(config.ShopEntries);
|
||||
@@ -165,7 +165,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var x = uow._context.Set<ShopEntryItem>().Remove(item);
|
||||
var x = uow.Set<ShopEntryItem>().Remove(item);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
try
|
||||
@@ -189,7 +189,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
entry.Price).ConfigureAwait(false);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id,
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
set => set.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items)).ShopEntries);
|
||||
entry = entries.ElementAtOrDefault(index);
|
||||
@@ -235,13 +235,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
};
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id,
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
set => set.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items)).ShopEntries)
|
||||
{
|
||||
entry
|
||||
};
|
||||
uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
|
||||
uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
|
||||
@@ -263,13 +263,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
};
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id,
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
set => set.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items)).ShopEntries)
|
||||
{
|
||||
entry
|
||||
};
|
||||
uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
|
||||
uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
|
||||
@@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
bool added = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow._context.GuildConfigsForId(ctx.Guild.Id,
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
set => set.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items)).ShopEntries);
|
||||
entry = entries.ElementAtOrDefault(index);
|
||||
@@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
ShopEntry removed;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
|
||||
.Include(x => x.ShopEntries)
|
||||
.ThenInclude(x => x.Items));
|
||||
|
||||
@@ -334,8 +334,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
removed = entries.ElementAtOrDefault(index);
|
||||
if (removed != null)
|
||||
{
|
||||
uow._context.RemoveRange(removed.Items);
|
||||
uow._context.Remove(removed);
|
||||
uow.RemoveRange(removed.Items);
|
||||
uow.Remove(removed);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false);
|
||||
uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
await ReplyConfirmLocalizedAsync("cleverbot_disabled").ConfigureAwait(false);
|
||||
@@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Games
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true);
|
||||
uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
finally { _locker.Release(); }
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var trackedPoll = uow._context.Poll.FirstOrDefault(x => x.Id == Poll.Id);
|
||||
var trackedPoll = uow.Poll.FirstOrDefault(x => x.Id == Poll.Id);
|
||||
trackedPoll.Votes.Add(voteObj);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
// public void EnsureMigrated()
|
||||
// {
|
||||
// using var uow = _db.GetDbContext();
|
||||
// using var conn = uow._context.Database.GetDbConnection();
|
||||
// using var conn = uow.Database.GetDbConnection();
|
||||
// MigrateRaceAnimals(conn);
|
||||
// MigrateEightBall(conn);
|
||||
// }
|
||||
|
@@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
ActivePolls = uow._context.Poll.GetAllPolls()
|
||||
ActivePolls = uow.Poll.GetAllPolls()
|
||||
.ToDictionary(x => x.GuildId, x =>
|
||||
{
|
||||
var pr = new PollRunner(db, x);
|
||||
@@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Poll.Add(p);
|
||||
uow.Poll.Add(p);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
pr.OnVoted -= Pr_OnVoted;
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
uow._context.RemovePoll(pr.Poll.Id);
|
||||
uow.RemovePoll(pr.Poll.Id);
|
||||
uow.SaveChanges();
|
||||
|
||||
return pr.Poll;
|
||||
|
@@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
playlists = uow._context.MusicPlaylists.GetPlaylistsOnPage(num);
|
||||
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
@@ -78,13 +78,13 @@ namespace NadekoBot.Modules.Music
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var pl = uow._context.MusicPlaylists.FirstOrDefault(x => x.Id == id);
|
||||
var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
if (pl != null)
|
||||
{
|
||||
if (_creds.IsOwner(ctx.User) || pl.AuthorId == ctx.User.Id)
|
||||
{
|
||||
uow._context.MusicPlaylists.Remove(pl);
|
||||
uow.MusicPlaylists.Remove(pl);
|
||||
await uow.SaveChangesAsync();
|
||||
success = true;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Music
|
||||
MusicPlaylist mpl;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
mpl = uow._context.MusicPlaylists.GetWithSongs(id);
|
||||
mpl = uow.MusicPlaylists.GetWithSongs(id);
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
|
||||
@@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Music
|
||||
AuthorId = ctx.User.Id,
|
||||
Songs = songs.ToList(),
|
||||
};
|
||||
uow._context.MusicPlaylists.Add(playlist);
|
||||
uow.MusicPlaylists.Add(playlist);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Music
|
||||
MusicPlaylist mpl;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
mpl = uow._context.MusicPlaylists.GetWithSongs(id);
|
||||
mpl = uow.MusicPlaylists.GetWithSongs(id);
|
||||
}
|
||||
|
||||
if (mpl == null)
|
||||
|
@@ -13,7 +13,6 @@ using NadekoBot.Core.Services.Database.Repositories.Impl;
|
||||
using NadekoBot.Modules.Music;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Database.Repositories.Impl;
|
||||
using NadekoBot.Extensions;
|
||||
using Serilog;
|
||||
|
||||
@@ -352,7 +351,7 @@ namespace NadekoBot.Modules.Music.Services
|
||||
return settings;
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var toReturn = _settings[guildId] = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
return toReturn;
|
||||
@@ -364,7 +363,7 @@ namespace NadekoBot.Modules.Music.Services
|
||||
TState state)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var ms = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
action(ms, state);
|
||||
await uow.SaveChangesAsync();
|
||||
_settings[guildId] = ms;
|
||||
@@ -444,7 +443,7 @@ namespace NadekoBot.Modules.Music.Services
|
||||
public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var settings = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
|
||||
return settings.QualityPreset;
|
||||
}
|
||||
|
||||
|
@@ -82,7 +82,7 @@
|
||||
// {
|
||||
// using (var uow = _db.GetDbContext())
|
||||
// {
|
||||
// return uow._context.GuildConfigsForId(guildId, set => set).DefaultMusicVolume;
|
||||
// return uow.GuildConfigsForId(guildId, set => set).DefaultMusicVolume;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@@ -256,7 +256,7 @@
|
||||
// bool val;
|
||||
// using (var uow = _db.GetDbContext())
|
||||
// {
|
||||
// var gc = uow._context.GuildConfigsForId(id, set => set);
|
||||
// var gc = uow.GuildConfigsForId(id, set => set);
|
||||
// val = gc.AutoDcFromVc = !gc.AutoDcFromVc;
|
||||
// uow.SaveChanges();
|
||||
// }
|
||||
@@ -278,7 +278,7 @@
|
||||
// {
|
||||
// using (var uow = _db.GetDbContext())
|
||||
// {
|
||||
// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
|
||||
// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
|
||||
// ms.MusicChannelId = cid;
|
||||
// uow.SaveChanges();
|
||||
// }
|
||||
@@ -288,7 +288,7 @@
|
||||
// {
|
||||
// using (var uow = _db.GetDbContext())
|
||||
// {
|
||||
// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
|
||||
// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
|
||||
// ms.SongAutoDelete = val;
|
||||
// uow.SaveChanges();
|
||||
// }
|
||||
|
@@ -395,7 +395,7 @@
|
||||
// }
|
||||
// using (var uow = _db.GetDbContext())
|
||||
// {
|
||||
// uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
|
||||
// uow.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
|
||||
// uow.SaveChanges();
|
||||
// }
|
||||
// await ReplyConfirmLocalizedAsync("defvol_set", val).ConfigureAwait(false);
|
||||
|
@@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Permissions
|
||||
var name = command.Name.ToLowerInvariant();
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns));
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns));
|
||||
var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CommandCooldown>());
|
||||
|
||||
var toDelete = config.CommandCooldowns.FirstOrDefault(cc => cc.CommandName == name);
|
||||
if (toDelete != null)
|
||||
uow._context.Set<CommandCooldown>().Remove(toDelete);
|
||||
uow.Set<CommandCooldown>().Remove(toDelete);
|
||||
localSet.RemoveWhere(cc => cc.CommandName == name);
|
||||
if (secs != 0)
|
||||
{
|
||||
|
@@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
enabled = config.FilterInvites = !config.FilterInvites;
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
FilterChannelId removed;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds));
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds));
|
||||
var match = new FilterChannelId()
|
||||
{
|
||||
ChannelId = channel.Id
|
||||
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
uow._context.Remove(removed);
|
||||
uow.Remove(removed);
|
||||
}
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
enabled = config.FilterLinks = !config.FilterLinks;
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
FilterLinksChannelId removed;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds));
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds));
|
||||
var match = new FilterLinksChannelId()
|
||||
{
|
||||
ChannelId = channel.Id
|
||||
@@ -147,7 +147,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
uow._context.Remove(removed);
|
||||
uow.Remove(removed);
|
||||
}
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
|
||||
enabled = config.FilterWords = !config.FilterWords;
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -199,7 +199,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
FilterChannelId removed;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds));
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds));
|
||||
|
||||
var match = new FilterChannelId()
|
||||
{
|
||||
@@ -212,7 +212,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
uow._context.Remove(removed);
|
||||
uow.Remove(removed);
|
||||
}
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
FilteredWord removed;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords));
|
||||
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords));
|
||||
|
||||
removed = config.FilteredWords.FirstOrDefault(fw => fw.Word.Trim().ToLowerInvariant() == word);
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
config.FilteredWords.Add(new FilteredWord() { Word = word });
|
||||
else
|
||||
{
|
||||
uow._context.Remove(removed);
|
||||
uow.Remove(removed);
|
||||
}
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
@@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
if (action == null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle.
|
||||
config.VerbosePermissions = action.Value;
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
config.PermissionRole = role.Id.ToString();
|
||||
uow.SaveChanges();
|
||||
_service.UpdateCache(config);
|
||||
@@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
config.PermissionRole = null;
|
||||
await uow.SaveChangesAsync();
|
||||
_service.UpdateCache(config);
|
||||
@@ -148,11 +148,11 @@ namespace NadekoBot.Modules.Permissions
|
||||
Permissionv2 p;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||
p = permsCol[index];
|
||||
permsCol.RemoveAt(index);
|
||||
uow._context.Remove(p);
|
||||
uow.Remove(p);
|
||||
await uow.SaveChangesAsync();
|
||||
_service.UpdateCache(config);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
Permissionv2 fromPerm;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
||||
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||
|
||||
var fromFound = from < permsCol.Count;
|
||||
|
@@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
public void Reload(bool publish = true)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toPublish = uow._context.Blacklist.AsNoTracking().ToArray();
|
||||
var toPublish = uow.Blacklist.AsNoTracking().ToArray();
|
||||
_blacklist = toPublish;
|
||||
if (publish)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var item = new BlacklistEntry { ItemId = id, Type = type };
|
||||
uow._context.Blacklist.Add(item);
|
||||
uow.Blacklist.Add(item);
|
||||
uow.SaveChanges();
|
||||
|
||||
Reload(true);
|
||||
@@ -85,11 +85,11 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
public void UnBlacklist(BlacklistType type, ulong id)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toRemove = uow._context.Blacklist
|
||||
var toRemove = uow.Blacklist
|
||||
.FirstOrDefault(bi => bi.ItemId == id && bi.Type == type);
|
||||
|
||||
if (!(toRemove is null))
|
||||
uow._context.Blacklist.Remove(toRemove);
|
||||
uow.Blacklist.Remove(toRemove);
|
||||
|
||||
uow.SaveChanges();
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var bc = uow._context.Blacklist;
|
||||
var bc = uow.Blacklist;
|
||||
//blacklist the users
|
||||
bc.AddRange(toBlacklist.Select(x =>
|
||||
new BlacklistEntry
|
||||
@@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
}));
|
||||
|
||||
//clear their currencies
|
||||
uow._context.DiscordUser.RemoveFromMany(toBlacklist);
|
||||
uow.DiscordUser.RemoveFromMany(toBlacklist);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId,
|
||||
var gc = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.FilteredWords)
|
||||
.Include(x => x.FilterWordsChannelIds));
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
using(var uow = db.GetDbContext())
|
||||
{
|
||||
var ids = client.GetGuildIds();
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.FilteredWords)
|
||||
.Include(x => x.FilterLinksChannelIds)
|
||||
|
@@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
foreach (var x in uow._context.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList()))
|
||||
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList()))
|
||||
{
|
||||
Cache.TryAdd(x.GuildId, new PermissionCache()
|
||||
{
|
||||
@@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(guildId,
|
||||
var config = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.Permissions));
|
||||
UpdateCache(config);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(guildId);
|
||||
var config = uow.GcWithPermissionsv2For(guildId);
|
||||
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||
var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest
|
||||
foreach (var perm in perms)
|
||||
@@ -175,7 +175,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GcWithPermissionsv2For(guildId);
|
||||
var config = uow.GcWithPermissionsv2For(guildId);
|
||||
config.Permissions = Permissionv2.GetDefaultPermlist;
|
||||
await uow.SaveChangesAsync();
|
||||
UpdateCache(config);
|
||||
|
@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildConfigIds = bot.AllGuildConfigs.Select(x => x.Id).ToList();
|
||||
_subs = uow._context.GuildConfigs
|
||||
_subs = uow.GuildConfigs
|
||||
.AsQueryable()
|
||||
.Where(x => guildConfigIds.Contains(x.Id))
|
||||
.Include(x => x.FeedSubs)
|
||||
@@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GuildConfigsForId(guildId,
|
||||
return uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.FeedSubs)
|
||||
.ThenInclude(x => x.GuildConfig))
|
||||
.FeedSubs
|
||||
@@ -188,7 +188,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId,
|
||||
var gc = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.FeedSubs)
|
||||
.ThenInclude(x => x.GuildConfig));
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var items = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs))
|
||||
var items = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs))
|
||||
.FeedSubs
|
||||
.OrderBy(x => x.Id)
|
||||
.ToList();
|
||||
@@ -237,7 +237,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
old.Remove(toRemove);
|
||||
return old;
|
||||
});
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
|
@@ -410,7 +410,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
bool added;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags));
|
||||
if (gc.NsfwBlacklistedTags.Add(tagObj))
|
||||
added = true;
|
||||
else
|
||||
@@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
gc.NsfwBlacklistedTags.Remove(tagObj);
|
||||
var toRemove = gc.NsfwBlacklistedTags.FirstOrDefault(x => x.Equals(tagObj));
|
||||
if (toRemove != null)
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
added = false;
|
||||
}
|
||||
var newTags = new HashSet<string>(gc.NsfwBlacklistedTags.Select(x => x.Tag));
|
||||
|
@@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var ids = client.GetGuildIds();
|
||||
var guildConfigs = uow._context.Set<GuildConfig>()
|
||||
var guildConfigs = uow.Set<GuildConfig>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.FollowedStreams)
|
||||
.Where(x => ids.Contains(x.GuildId))
|
||||
@@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
// shard 0 will keep track of when there are no more guilds which track a stream
|
||||
if (client.ShardId == 0)
|
||||
{
|
||||
var allFollowedStreams = uow._context.Set<FollowedStream>()
|
||||
var allFollowedStreams = uow.Set<FollowedStream>()
|
||||
.AsQueryable()
|
||||
.ToList();
|
||||
|
||||
@@ -132,12 +132,12 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " +
|
||||
$"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}");
|
||||
|
||||
var toDelete = uow._context.Set<FollowedStream>()
|
||||
var toDelete = uow.Set<FollowedStream>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username))
|
||||
.ToList();
|
||||
|
||||
uow._context.RemoveRange(toDelete);
|
||||
uow.RemoveRange(toDelete);
|
||||
uow.SaveChanges();
|
||||
|
||||
foreach(var loginToDelete in kvp.Value)
|
||||
@@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigs
|
||||
var gc = uow.GuildConfigs
|
||||
.AsQueryable()
|
||||
.Include(x => x.FollowedStreams)
|
||||
.FirstOrDefault(x => x.GuildId == guildConfig.GuildId);
|
||||
@@ -320,7 +320,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams));
|
||||
var gc = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams));
|
||||
|
||||
_offlineNotificationServers.TryRemove(gc.GuildId);
|
||||
|
||||
@@ -342,7 +342,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
int count;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
|
||||
count = gc.FollowedStreams.Count;
|
||||
gc.FollowedStreams.Clear();
|
||||
uow.SaveChanges();
|
||||
@@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
FollowedStream fs;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var fss = uow._context.Set<FollowedStream>()
|
||||
var fss = uow.Set<FollowedStream>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.OrderBy(x => x.Id)
|
||||
@@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
return null;
|
||||
|
||||
fs = fss[index];
|
||||
uow._context.Remove(fs);
|
||||
uow.Remove(fs);
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
@@ -411,7 +411,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
FollowedStream fs;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
|
||||
|
||||
// add it to the database
|
||||
fs = new FollowedStream()
|
||||
@@ -481,7 +481,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
bool newValue;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
newValue = gc.NotifyStreamOffline = !gc.NotifyStreamOffline;
|
||||
uow.SaveChanges();
|
||||
|
||||
@@ -530,7 +530,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var fss = uow._context.Set<FollowedStream>()
|
||||
var fss = uow.Set<FollowedStream>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.OrderBy(x => x.Id)
|
||||
@@ -564,7 +564,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
var all = uow._context.Set<FollowedStream>()
|
||||
var all = uow.Set<FollowedStream>()
|
||||
.ToList();
|
||||
|
||||
if (all.Count == 0)
|
||||
|
@@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
//
|
||||
// using(var uow = _db.GetDbContext())
|
||||
// {
|
||||
// var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels));
|
||||
// var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels));
|
||||
//
|
||||
// // see if this yt channel was already followed on this discord channel
|
||||
// var oldObj = gc.YtFollowedChannels
|
||||
|
@@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Searches
|
||||
List<FollowedStream> streams = new List<FollowedStream>();
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var all = uow._context
|
||||
var all = uow
|
||||
.GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams))
|
||||
.FollowedStreams
|
||||
.OrderBy(x => x.Id)
|
||||
|
@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var toAdd = new CommandAlias()
|
||||
{
|
||||
Mapping = mapping,
|
||||
@@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Utility
|
||||
};
|
||||
var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger);
|
||||
if (tr != null)
|
||||
uow._context.Set<CommandAlias>().Remove(tr);
|
||||
uow.Set<CommandAlias>().Remove(tr);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
config.CommandAliases.Add(new CommandAlias()
|
||||
{
|
||||
Mapping = mapping,
|
||||
@@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var toAdd = new CommandAlias()
|
||||
{
|
||||
Mapping = mapping,
|
||||
@@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Utility
|
||||
};
|
||||
var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger);
|
||||
if (toRemove.Any())
|
||||
uow._context.RemoveRange(toRemove.ToArray());
|
||||
uow.RemoveRange(toRemove.ToArray());
|
||||
config.CommandAliases.Add(toAdd);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@ using System.Threading.Tasks;
|
||||
using NadekoBot.Core.Services;
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using NadekoBot.Core.Services.Database.Repositories.Impl;
|
||||
using NadekoBot.Services.Database.Repositories.Impl;
|
||||
using NadekoBot.Db;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
@@ -47,7 +46,7 @@ namespace NadekoBot.Modules.Utility
|
||||
IEnumerable<Quote> quotes;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
quotes = uow._context.Quotes.GetGroup(ctx.Guild.Id, page, order);
|
||||
quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order);
|
||||
}
|
||||
|
||||
if (quotes.Any())
|
||||
@@ -70,7 +69,7 @@ namespace NadekoBot.Modules.Utility
|
||||
Quote quote;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
quote = await uow._context.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
|
||||
quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
|
||||
//if (quote != null)
|
||||
//{
|
||||
// quote.UseCount += 1;
|
||||
@@ -102,7 +101,7 @@ namespace NadekoBot.Modules.Utility
|
||||
Quote quote;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
quote = uow._context.Quotes.GetById(id);
|
||||
quote = uow.Quotes.GetById(id);
|
||||
if (quote.GuildId != Context.Guild.Id)
|
||||
quote = null;
|
||||
}
|
||||
@@ -141,7 +140,7 @@ namespace NadekoBot.Modules.Utility
|
||||
Quote keywordquote;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
keywordquote = await uow._context.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text);
|
||||
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text);
|
||||
}
|
||||
|
||||
if (keywordquote == null)
|
||||
@@ -166,7 +165,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
quote = uow._context.Quotes.GetById(id);
|
||||
quote = uow.Quotes.GetById(id);
|
||||
}
|
||||
|
||||
if (quote is null || quote.GuildId != ctx.Guild.Id)
|
||||
@@ -203,7 +202,7 @@ namespace NadekoBot.Modules.Utility
|
||||
Quote q;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Quotes.Add(q = new Quote
|
||||
uow.Quotes.Add(q = new Quote
|
||||
{
|
||||
AuthorId = ctx.Message.Author.Id,
|
||||
AuthorName = ctx.Message.Author.Username,
|
||||
@@ -226,7 +225,7 @@ namespace NadekoBot.Modules.Utility
|
||||
string response;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var q = uow._context.Quotes.GetById(id);
|
||||
var q = uow.Quotes.GetById(id);
|
||||
|
||||
if ((q?.GuildId != ctx.Guild.Id) || (!isAdmin && q.AuthorId != ctx.Message.Author.Id))
|
||||
{
|
||||
@@ -234,7 +233,7 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
else
|
||||
{
|
||||
uow._context.Quotes.Remove(q);
|
||||
uow.Quotes.Remove(q);
|
||||
await uow.SaveChangesAsync();
|
||||
success = true;
|
||||
response = GetText("quote_deleted", id);
|
||||
@@ -258,7 +257,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant());
|
||||
uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant());
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Utility
|
||||
List<Reminder> rems;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
rems = uow._context.Reminders.RemindersFor(ctx.User.Id, page)
|
||||
rems = uow.Reminders.RemindersFor(ctx.User.Id, page)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ namespace NadekoBot.Modules.Utility
|
||||
Reminder rem = null;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var rems = uow._context.Reminders.RemindersFor(ctx.User.Id, index / 10)
|
||||
var rems = uow.Reminders.RemindersFor(ctx.User.Id, index / 10)
|
||||
.ToList();
|
||||
var pageIndex = index % 10;
|
||||
if (rems.Count > pageIndex)
|
||||
{
|
||||
rem = rems[pageIndex];
|
||||
uow._context.Reminders.Remove(rem);
|
||||
uow.Reminders.Remove(rem);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Reminders.Add(rem);
|
||||
uow.Reminders.Add(rem);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.Include(gc => gc.CommandAliases)
|
||||
.Where(x => guildIds.Contains(x.GuildId))
|
||||
.ToList();
|
||||
@@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
int count;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases));
|
||||
count = gc.CommandAliases.Count;
|
||||
gc.CommandAliases.Clear();
|
||||
uow.SaveChanges();
|
||||
|
@@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
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);
|
||||
|
||||
if (usr == null)
|
||||
|
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Set<Reminder>()
|
||||
uow.Set<Reminder>()
|
||||
.RemoveRange(reminders);
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.Reminders
|
||||
return uow.Reminders
|
||||
.FromSqlInterpolated($"select * from reminders where ((serverid >> 22) % {_creds.TotalShards}) == {_client.ShardId} and \"when\" < {now};")
|
||||
.ToListAsync();
|
||||
}
|
||||
|
@@ -41,7 +41,6 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
var uow = _db.GetDbContext();
|
||||
var shardRepeaters = uow
|
||||
._context
|
||||
.Set<Repeater>()
|
||||
.FromSqlInterpolated($@"select * from repeaters
|
||||
where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
@@ -133,7 +132,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
var toTrigger = await uow._context.Repeaters
|
||||
var toTrigger = await uow.Repeaters
|
||||
.AsNoTracking()
|
||||
.Skip(index)
|
||||
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
|
||||
@@ -290,7 +289,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
_noRedundant.TryRemove(r.Id);
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
await uow._context
|
||||
await uow
|
||||
.Repeaters
|
||||
.DeleteAsync(x => x.Id == r.Id);
|
||||
|
||||
@@ -313,7 +312,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
await uow._context.Repeaters
|
||||
await uow.Repeaters
|
||||
.AsQueryable()
|
||||
.Where(x => x.Id == repeaterId)
|
||||
.UpdateAsync(rep => new Repeater()
|
||||
@@ -345,8 +344,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
if (await uow._context.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS)
|
||||
uow._context.Repeaters.Add(rep);
|
||||
if (await uow.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS)
|
||||
uow.Repeaters.Add(rep);
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -365,7 +364,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var toRemove = await uow._context.Repeaters
|
||||
var toRemove = await uow.Repeaters
|
||||
.AsNoTracking()
|
||||
.Skip(index)
|
||||
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
|
||||
@@ -380,7 +379,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
return null;
|
||||
|
||||
_noRedundant.TryRemove(toRemove.Id);
|
||||
uow._context.Repeaters.Remove(toRemove);
|
||||
uow.Repeaters.Remove(toRemove);
|
||||
await uow.SaveChangesAsync();
|
||||
return removed;
|
||||
}
|
||||
@@ -396,7 +395,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toToggle = await uow._context
|
||||
var toToggle = await uow
|
||||
.Repeaters
|
||||
.AsQueryable()
|
||||
.Skip(index)
|
||||
|
@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
bool success = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
|
||||
if (listType == StreamRoleListType.Whitelist)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj));
|
||||
if (toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
|
||||
streamRoleSettings.Keyword = keyword;
|
||||
UpdateCache(guild.Id, streamRoleSettings);
|
||||
@@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
StreamRoleSettings setting;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
setting = uow._context.GetStreamRoleSettings(guildId);
|
||||
setting = uow.GetStreamRoleSettings(guildId);
|
||||
}
|
||||
|
||||
UpdateCache(guildId, setting);
|
||||
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
StreamRoleSettings setting;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(fromRole.Guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id);
|
||||
|
||||
streamRoleSettings.Enabled = true;
|
||||
streamRoleSettings.AddRoleId = addRole.Id;
|
||||
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
streamRoleSettings.Enabled = false;
|
||||
streamRoleSettings.AddRoleId = 0;
|
||||
streamRoleSettings.FromRoleId = 0;
|
||||
|
@@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
||||
if (enabled==null) enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition
|
||||
else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.
|
||||
|
@@ -29,8 +29,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
|
||||
club = null;
|
||||
using var uow = _db.GetDbContext();
|
||||
var du = uow._context.GetOrCreateUser(user);
|
||||
uow._context.SaveChanges();
|
||||
var du = uow.GetOrCreateUser(user);
|
||||
uow.SaveChanges();
|
||||
var xp = new LevelStats(du.TotalXp);
|
||||
|
||||
if (xp.Level >= 5 && du.Club == null)
|
||||
@@ -39,17 +39,17 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
du.Club = new ClubInfo()
|
||||
{
|
||||
Name = clubName,
|
||||
Discrim = uow._context.Clubs.GetNextDiscrim(clubName),
|
||||
Discrim = uow.Clubs.GetNextDiscrim(clubName),
|
||||
Owner = du,
|
||||
};
|
||||
uow._context.Clubs.Add(du.Club);
|
||||
uow._context.SaveChanges();
|
||||
uow.Clubs.Add(du.Club);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
uow._context.Set<ClubApplicants>()
|
||||
.RemoveRange(uow._context.Set<ClubApplicants>()
|
||||
uow.Set<ClubApplicants>()
|
||||
.RemoveRange(uow.Set<ClubApplicants>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.UserId == du.Id));
|
||||
club = du.Club;
|
||||
@@ -63,8 +63,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
ClubInfo club;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByOwner(from.Id);
|
||||
var newOwnerUser = uow._context.GetOrCreateUser(newOwner);
|
||||
club = uow.Clubs.GetByOwner(from.Id);
|
||||
var newOwnerUser = uow.GetOrCreateUser(newOwner);
|
||||
|
||||
if (club == null ||
|
||||
club.Owner.UserId != from.Id ||
|
||||
@@ -84,8 +84,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
bool newState;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var club = uow._context.Clubs.GetByOwner(owner.Id);
|
||||
var adminUser = uow._context.GetOrCreateUser(toAdmin);
|
||||
var club = uow.Clubs.GetByOwner(owner.Id);
|
||||
var adminUser = uow.GetOrCreateUser(toAdmin);
|
||||
|
||||
if (club == null || club.Owner.UserId != owner.Id ||
|
||||
!club.Users.Contains(adminUser))
|
||||
@@ -103,7 +103,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public ClubInfo GetClubByMember(IUser user)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var member = uow._context.Clubs.GetByMember(user.Id);
|
||||
var member = uow.Clubs.GetByMember(user.Id);
|
||||
return member;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var club = uow._context.Clubs.GetByOwner(ownerUserId);
|
||||
var club = uow.Clubs.GetByOwner(ownerUserId);
|
||||
|
||||
if (club == null)
|
||||
return false;
|
||||
@@ -148,7 +148,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByName(name, discrim);
|
||||
club = uow.Clubs.GetByName(name, discrim);
|
||||
if (club == null)
|
||||
return false;
|
||||
else
|
||||
@@ -160,8 +160,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var du = uow._context.GetOrCreateUser(user);
|
||||
uow._context.SaveChanges();
|
||||
var du = uow.GetOrCreateUser(user);
|
||||
uow.SaveChanges();
|
||||
|
||||
if (du.Club != null
|
||||
|| new LevelStats(du.TotalXp).Level < club.MinimumLevelReq
|
||||
@@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
UserId = du.Id,
|
||||
};
|
||||
|
||||
uow._context.Set<ClubApplicants>().Add(app);
|
||||
uow.Set<ClubApplicants>().Add(app);
|
||||
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -191,7 +191,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
discordUser = null;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var club = uow._context.Clubs.GetByOwnerOrAdmin(clubOwnerUserId);
|
||||
var club = uow.Clubs.GetByOwnerOrAdmin(clubOwnerUserId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -204,8 +204,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
club.Applicants.Remove(applicant);
|
||||
|
||||
//remove that user's all other applications
|
||||
uow._context.Set<ClubApplicants>()
|
||||
.RemoveRange(uow._context.Set<ClubApplicants>()
|
||||
uow.Set<ClubApplicants>()
|
||||
.RemoveRange(uow.Set<ClubApplicants>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.UserId == applicant.User.Id));
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.Clubs.GetByOwnerOrAdmin(ownerUserId);
|
||||
return uow.Clubs.GetByOwnerOrAdmin(ownerUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var du = uow._context.GetOrCreateUser(user);
|
||||
var du = uow.GetOrCreateUser(user);
|
||||
if (du.Club == null || du.Club.OwnerId == du.Id)
|
||||
return false;
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var club = uow._context.Clubs.GetByOwner(userId);
|
||||
var club = uow.Clubs.GetByOwner(userId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var club = uow._context.Clubs.GetByOwner(userId);
|
||||
var club = uow.Clubs.GetByOwner(userId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -275,11 +275,11 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByOwner(userId);
|
||||
club = uow.Clubs.GetByOwner(userId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
uow._context.Clubs.Remove(club);
|
||||
uow.Clubs.Remove(club);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
return true;
|
||||
@@ -289,7 +289,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByOwnerOrAdmin(bannerId);
|
||||
club = uow.Clubs.GetByOwnerOrAdmin(bannerId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -322,7 +322,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByOwnerOrAdmin(ownerUserId);
|
||||
club = uow.Clubs.GetByOwnerOrAdmin(ownerUserId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
club = uow._context.Clubs.GetByOwnerOrAdmin(kickerId);
|
||||
club = uow.Clubs.GetByOwnerOrAdmin(kickerId);
|
||||
if (club == null)
|
||||
return false;
|
||||
|
||||
@@ -368,7 +368,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
throw new ArgumentOutOfRangeException(nameof(page));
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context.Clubs.GetClubLeaderboardPage(page);
|
||||
return uow.Clubs.GetClubLeaderboardPage(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public void EnsureMigrated()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
using var conn = uow._context.Database.GetDbConnection();
|
||||
using var conn = uow.Database.GetDbConnection();
|
||||
Migrate(conn);
|
||||
}
|
||||
|
||||
|
@@ -167,8 +167,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
//2. (better but much harder) Move everything to the database, and get old and new xp
|
||||
// amounts for every user (in order to give rewards)
|
||||
|
||||
var usr = uow._context.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id);
|
||||
var du = uow._context.GetOrCreateUser(item.Key.User);
|
||||
var usr = uow.GetOrCreateUserXpStats(item.Key.GuildId, item.Key.User.Id);
|
||||
var du = uow.GetOrCreateUser(item.Key.User);
|
||||
|
||||
var globalXp = du.TotalXp;
|
||||
var oldGlobalLevelData = new LevelStats(globalXp);
|
||||
@@ -201,13 +201,13 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
//give role
|
||||
if (!roleRewards.TryGetValue(usr.GuildId, out var rrews))
|
||||
{
|
||||
rrews = uow._context.XpSettingsFor(usr.GuildId).RoleRewards.ToList();
|
||||
rrews = uow.XpSettingsFor(usr.GuildId).RoleRewards.ToList();
|
||||
roleRewards.Add(usr.GuildId, rrews);
|
||||
}
|
||||
|
||||
if (!curRewards.TryGetValue(usr.GuildId, out var crews))
|
||||
{
|
||||
crews = uow._context.XpSettingsFor(usr.GuildId).CurrencyRewards.ToList();
|
||||
crews = uow.XpSettingsFor(usr.GuildId).CurrencyRewards.ToList();
|
||||
curRewards.Add(usr.GuildId, crews);
|
||||
}
|
||||
|
||||
@@ -317,14 +317,14 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var settings = uow._context.XpSettingsFor(guildId);
|
||||
var settings = uow.XpSettingsFor(guildId);
|
||||
|
||||
if (amount <= 0)
|
||||
{
|
||||
var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||
if (toRemove != null)
|
||||
{
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
settings.CurrencyRewards.Remove(toRemove);
|
||||
}
|
||||
}
|
||||
@@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.XpSettingsFor(id)
|
||||
return uow.XpSettingsFor(id)
|
||||
.CurrencyRewards
|
||||
.ToArray();
|
||||
}
|
||||
@@ -359,7 +359,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public IEnumerable<XpRoleReward> GetRoleRewards(ulong id)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context.XpSettingsFor(id)
|
||||
return uow.XpSettingsFor(id)
|
||||
.RoleRewards
|
||||
.ToArray();
|
||||
}
|
||||
@@ -367,12 +367,12 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public void ResetRoleReward(ulong guildId, int level)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var settings = uow._context.XpSettingsFor(guildId);
|
||||
var settings = uow.XpSettingsFor(guildId);
|
||||
|
||||
var toRemove = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
|
||||
if (toRemove != null)
|
||||
{
|
||||
uow._context.Remove(toRemove);
|
||||
uow.Remove(toRemove);
|
||||
settings.RoleRewards.Remove(toRemove);
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public void SetRoleReward(ulong guildId, int level, ulong roleId, bool remove)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var settings = uow._context.XpSettingsFor(guildId);
|
||||
var settings = uow.XpSettingsFor(guildId);
|
||||
|
||||
|
||||
var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
|
||||
@@ -409,7 +409,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.UserXpStats.GetUsersFor(guildId, page);
|
||||
return uow.UserXpStats.GetUsersFor(guildId, page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.UserXpStats.GetTopUserXps(guildId, count);
|
||||
return uow.UserXpStats.GetTopUserXps(guildId, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.DiscordUser.GetUsersXpLeaderboardFor(page);
|
||||
return uow.DiscordUser.GetUsersXpLeaderboardFor(page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var user = uow._context.GetOrCreateUserXpStats(guildId, userId);
|
||||
var user = uow.GetOrCreateUserXpStats(guildId, userId);
|
||||
user.NotifyOnLevelUp = type;
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -443,7 +443,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var user = uow._context.GetOrCreateUserXpStats(guildId, userId);
|
||||
var user = uow.GetOrCreateUserXpStats(guildId, userId);
|
||||
return user.NotifyOnLevelUp;
|
||||
}
|
||||
}
|
||||
@@ -452,7 +452,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GetOrCreateUser(user).NotifyOnLevelUp;
|
||||
return uow.GetOrCreateUser(user).NotifyOnLevelUp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var du = uow._context.GetOrCreateUser(user);
|
||||
var du = uow.GetOrCreateUser(user);
|
||||
du.NotifyOnLevelUp = type;
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -657,7 +657,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var usr = uow._context.GetOrCreateUserXpStats(guildId, userId);
|
||||
var usr = uow.GetOrCreateUserXpStats(guildId, userId);
|
||||
|
||||
usr.AwardedXp += amount;
|
||||
|
||||
@@ -706,11 +706,11 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
int guildRank;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
du = uow._context.GetOrCreateUser(user);
|
||||
du = uow.GetOrCreateUser(user);
|
||||
totalXp = du.TotalXp;
|
||||
globalRank = uow._context.DiscordUser.GetUserGlobalRank(user.Id);
|
||||
guildRank = uow._context.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId);
|
||||
stats = uow._context.GetOrCreateUserXpStats(user.GuildId, user.Id);
|
||||
globalRank = uow.DiscordUser.GetUserGlobalRank(user.Id);
|
||||
guildRank = uow.UserXpStats.GetUserGuildRanking(user.Id, user.GuildId);
|
||||
stats = uow.GetOrCreateUserXpStats(user.GuildId, user.Id);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -747,7 +747,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var xpSetting = uow._context.XpSettingsFor(id);
|
||||
var xpSetting = uow.XpSettingsFor(id);
|
||||
if (_excludedServers.Add(id))
|
||||
{
|
||||
xpSetting.ServerExcluded = true;
|
||||
@@ -767,7 +767,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>());
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var xpSetting = uow._context.XpSettingsFor(guildId);
|
||||
var xpSetting = uow.XpSettingsFor(guildId);
|
||||
var excludeObj = new ExcludedItem
|
||||
{
|
||||
ItemId = rId,
|
||||
@@ -790,7 +790,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj));
|
||||
if (toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -804,7 +804,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
var channels = _excludedChannels.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>());
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var xpSetting = uow._context.XpSettingsFor(guildId);
|
||||
var xpSetting = uow.XpSettingsFor(guildId);
|
||||
var excludeObj = new ExcludedItem
|
||||
{
|
||||
ItemId = chId,
|
||||
@@ -1200,7 +1200,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.UserXpStats.ResetGuildUserXp(userId, guildId);
|
||||
uow.UserXpStats.ResetGuildUserXp(userId, guildId);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -1209,7 +1209,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.UserXpStats.ResetGuildXp(guildId);
|
||||
uow.UserXpStats.ResetGuildXp(guildId);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -1217,15 +1217,15 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
public async Task ResetXpRewards(ulong guildId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var guildConfig = uow._context.GuildConfigsForId(guildId,
|
||||
var guildConfig = uow.GuildConfigsForId(guildId,
|
||||
set => set
|
||||
.Include(x => x.XpSettings)
|
||||
.ThenInclude(x => x.CurrencyRewards)
|
||||
.Include(x => x.XpSettings)
|
||||
.ThenInclude(x => x.RoleRewards));
|
||||
|
||||
uow._context.RemoveRange(guildConfig.XpSettings.RoleRewards);
|
||||
uow._context.RemoveRange(guildConfig.XpSettings.CurrencyRewards);
|
||||
uow.RemoveRange(guildConfig.XpSettings.RoleRewards);
|
||||
uow.RemoveRange(guildConfig.XpSettings.CurrencyRewards);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guild.Id, set => set);
|
||||
var gc = uow.GuildConfigsForId(guild.Id, set => set);
|
||||
gc.Prefix = prefix;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -57,6 +57,6 @@ namespace NadekoBot.Core.Services
|
||||
return context;
|
||||
}
|
||||
|
||||
public IUnitOfWork GetDbContext() => new UnitOfWork(GetDbContextInternal());
|
||||
public NadekoContext GetDbContext() => GetDbContextInternal();
|
||||
}
|
||||
}
|
@@ -107,7 +107,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GuildConfigsForId(id, set => set)?.DmGreetMessageText;
|
||||
return uow.GuildConfigsForId(id, set => set)?.DmGreetMessageText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GuildConfigsForId(gid, set => set).ChannelGreetMessageText;
|
||||
return uow.GuildConfigsForId(gid, set => set).ChannelGreetMessageText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.GuildConfigsForId(gid, set => set).ChannelByeMessageText;
|
||||
return uow.GuildConfigsForId(gid, set => set).ChannelByeMessageText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
settings = GreetSettings.Create(gc);
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
conf.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions();
|
||||
conf.ChannelGreetMessageText = settings.ChannelGreetMessageText?.SanitizeMentions();
|
||||
conf.ChannelByeMessageText = settings.ChannelByeMessageText?.SanitizeMentions();
|
||||
@@ -382,7 +382,7 @@ namespace NadekoBot.Core.Services
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage;
|
||||
conf.GreetMessageChannelId = channelId;
|
||||
|
||||
@@ -404,7 +404,7 @@ namespace NadekoBot.Core.Services
|
||||
bool greetMsgEnabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
conf.ChannelGreetMessageText = message;
|
||||
greetMsgEnabled = conf.SendChannelGreetMessage;
|
||||
|
||||
@@ -421,7 +421,7 @@ namespace NadekoBot.Core.Services
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage;
|
||||
|
||||
var toAdd = GreetSettings.Create(conf);
|
||||
@@ -437,7 +437,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
return conf.SendDmGreetMessage;
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
return conf.SendChannelGreetMessage;
|
||||
}
|
||||
}
|
||||
@@ -455,7 +455,7 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
return conf.SendChannelByeMessage;
|
||||
}
|
||||
}
|
||||
@@ -492,7 +492,7 @@ namespace NadekoBot.Core.Services
|
||||
bool greetMsgEnabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
conf.DmGreetMessageText = message;
|
||||
greetMsgEnabled = conf.SendDmGreetMessage;
|
||||
|
||||
@@ -509,7 +509,7 @@ namespace NadekoBot.Core.Services
|
||||
bool enabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage;
|
||||
conf.ByeMessageChannelId = channelId;
|
||||
|
||||
@@ -531,7 +531,7 @@ namespace NadekoBot.Core.Services
|
||||
bool byeMsgEnabled;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
conf.ChannelByeMessageText = message;
|
||||
byeMsgEnabled = conf.SendChannelByeMessage;
|
||||
|
||||
@@ -550,7 +550,7 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set);
|
||||
conf.AutoDeleteByeMessagesTimer = timer;
|
||||
|
||||
var toAdd = GreetSettings.Create(conf);
|
||||
@@ -567,7 +567,7 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var conf = uow._context.GuildConfigsForId(id, set => set);
|
||||
var conf = uow.GuildConfigsForId(id, set => set);
|
||||
conf.AutoDeleteGreetMessagesTimer = timer;
|
||||
|
||||
var toAdd = GreetSettings.Create(conf);
|
||||
|
@@ -33,19 +33,19 @@ namespace NadekoBot.Core.Services
|
||||
};
|
||||
|
||||
private bool InternalChange(ulong userId, string userName, string discrim, string avatar,
|
||||
string reason, long amount, bool gamble, IUnitOfWork uow)
|
||||
string reason, long amount, bool gamble, NadekoContext uow)
|
||||
{
|
||||
var result = uow._context.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount);
|
||||
var result = uow.TryUpdateCurrencyState(userId, userName, discrim, avatar, amount);
|
||||
if (result)
|
||||
{
|
||||
var t = GetCurrencyTransaction(userId, reason, amount);
|
||||
uow._context.CurrencyTransactions.Add(t);
|
||||
uow.CurrencyTransactions.Add(t);
|
||||
|
||||
if (gamble)
|
||||
{
|
||||
var t2 = GetCurrencyTransaction(_bot.Id, reason, -amount);
|
||||
uow._context.CurrencyTransactions.Add(t2);
|
||||
uow._context.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true);
|
||||
uow.CurrencyTransactions.Add(t2);
|
||||
uow.TryUpdateCurrencyState(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId, -amount, true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@@ -56,7 +56,7 @@ namespace NadekoBot.Core.Services.Impl
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
gc.Locale = ci.Name;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace NadekoBot.Core.Services.Impl
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
gc.Locale = null;
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
@@ -136,7 +136,7 @@ namespace NadekoBot
|
||||
public IEnumerable<GuildConfig> GetCurrentGuildConfigs()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow._context.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray();
|
||||
return uow.GuildConfigs.GetAllGuildConfigs(GetCurrentGuildIds()).ToImmutableArray();
|
||||
}
|
||||
|
||||
private void AddServices()
|
||||
@@ -147,8 +147,8 @@ namespace NadekoBot
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId);
|
||||
AllGuildConfigs = uow._context.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
uow.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId);
|
||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
}
|
||||
|
||||
var s = new ServiceCollection()
|
||||
@@ -314,7 +314,7 @@ namespace NadekoBot
|
||||
GuildConfig gc;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
gc = uow._context.GuildConfigsForId(arg.Id);
|
||||
gc = uow.GuildConfigsForId(arg.Id);
|
||||
}
|
||||
await JoinedGuild.Invoke(gc).ConfigureAwait(false);
|
||||
});
|
||||
|
@@ -22,7 +22,7 @@ namespace NadekoBot.Core.Services
|
||||
public void EnsureMigrated()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
using var conn = uow._context.Database.GetDbConnection();
|
||||
using var conn = uow.Database.GetDbConnection();
|
||||
|
||||
// check if bot config exists
|
||||
using (var checkTableCommand = conn.CreateCommand())
|
||||
|
@@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services
|
||||
public void EnsureMigrated()
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
using var conn = uow._context.Database.GetDbConnection();
|
||||
using var conn = uow.Database.GetDbConnection();
|
||||
Migrate(conn);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user