mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-04 16:44:28 -05:00
UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user