mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
Removed sar repository
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NadekoBot.Modules.Xp;
|
using NadekoBot.Modules.Xp;
|
||||||
|
using NadekoBot.Modules.Administration.Common;
|
||||||
|
|
||||||
namespace NadekoBot.Core.Modules.Administration.Services
|
namespace NadekoBot.Core.Modules.Administration.Services
|
||||||
{
|
{
|
||||||
@@ -40,13 +41,13 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
|||||||
{
|
{
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var roles = uow.SelfAssignedRoles.GetFromGuild(guildId);
|
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||||
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uow.SelfAssignedRoles.Add(new SelfAssignedRole
|
uow._context.SelfAssignableRoles.Add(new SelfAssignedRole
|
||||||
{
|
{
|
||||||
Group = group,
|
Group = group,
|
||||||
RoleId = role.Id,
|
RoleId = role.Id,
|
||||||
@@ -194,7 +195,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
|||||||
bool success;
|
bool success;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
success = uow.SelfAssignedRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
success = uow._context.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
@@ -207,7 +208,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
|||||||
var gc = uow.GuildConfigs.ForId(guildId, set => set);
|
var gc = uow.GuildConfigs.ForId(guildId, set => set);
|
||||||
var autoDelete = gc.AutoDeleteSelfAssignedRoleMessages;
|
var autoDelete = gc.AutoDeleteSelfAssignedRoleMessages;
|
||||||
var exclusive = gc.ExclusiveSelfAssignedRoles;
|
var exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||||
var roles = uow.SelfAssignedRoles.GetFromGuild(guildId);
|
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||||
|
|
||||||
return (autoDelete, exclusive, roles);
|
return (autoDelete, exclusive, roles);
|
||||||
}
|
}
|
||||||
@@ -217,7 +218,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
|||||||
{
|
{
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var roles = uow.SelfAssignedRoles.GetFromGuild(guildId);
|
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||||
var sar = roles.FirstOrDefault(x => x.RoleId == role.Id);
|
var sar = roles.FirstOrDefault(x => x.RoleId == role.Id);
|
||||||
if (sar != null)
|
if (sar != null)
|
||||||
{
|
{
|
||||||
@@ -257,10 +258,10 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
|||||||
var gc = uow.GuildConfigs.ForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames));
|
var gc = uow.GuildConfigs.ForId(guild.Id, set => set.Include(x => x.SelfAssignableRoleGroupNames));
|
||||||
exclusive = gc.ExclusiveSelfAssignedRoles;
|
exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||||
groupNames = gc.SelfAssignableRoleGroupNames.ToDictionary(x => x.Number, x => x.Name);
|
groupNames = gc.SelfAssignableRoleGroupNames.ToDictionary(x => x.Number, x => x.Name);
|
||||||
var roleModels = uow.SelfAssignedRoles.GetFromGuild(guild.Id);
|
var roleModels = uow._context.SelfAssignableRoles.GetFromGuild(guild.Id);
|
||||||
roles = roleModels
|
roles = roleModels
|
||||||
.Select(x => (Model: x, Role: guild.GetRole(x.RoleId)));
|
.Select(x => (Model: x, Role: guild.GetRole(x.RoleId)));
|
||||||
uow.SelfAssignedRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray());
|
uow._context.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray());
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
IQuoteRepository Quotes { get; }
|
IQuoteRepository Quotes { get; }
|
||||||
IGuildConfigRepository GuildConfigs { get; }
|
IGuildConfigRepository GuildConfigs { get; }
|
||||||
IReminderRepository Reminders { get; }
|
IReminderRepository Reminders { get; }
|
||||||
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
|
|
||||||
ICustomReactionRepository CustomReactions { get; }
|
ICustomReactionRepository CustomReactions { get; }
|
||||||
IMusicPlaylistRepository MusicPlaylists { get; }
|
IMusicPlaylistRepository MusicPlaylists { get; }
|
||||||
IWaifuRepository Waifus { get; }
|
IWaifuRepository Waifus { get; }
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories
|
|
||||||
{
|
|
||||||
public interface ISelfAssignedRolesRepository : IRepository<SelfAssignedRole>
|
|
||||||
{
|
|
||||||
bool DeleteByGuildAndRoleId(ulong guildId, ulong roleId);
|
|
||||||
IEnumerable<SelfAssignedRole> GetFromGuild(ulong guildId);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,26 @@
|
|||||||
|
using NadekoBot.Core.Services.Database.Models;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Administration.Common
|
||||||
|
{
|
||||||
|
public static class SelfAssignableRolesExtensions
|
||||||
|
{
|
||||||
|
public static bool DeleteByGuildAndRoleId(this DbSet<SelfAssignedRole> roles, ulong guildId, ulong roleId)
|
||||||
|
{
|
||||||
|
var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId);
|
||||||
|
|
||||||
|
if (role == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
roles.Remove(role);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<SelfAssignedRole> GetFromGuild(this DbSet<SelfAssignedRole> roles, ulong guildId)
|
||||||
|
=> roles.AsQueryable()
|
||||||
|
.Where(s => s.GuildId == guildId)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,30 +0,0 @@
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
|
||||||
{
|
|
||||||
public class SelfAssignedRolesRepository : Repository<SelfAssignedRole>, ISelfAssignedRolesRepository
|
|
||||||
{
|
|
||||||
public SelfAssignedRolesRepository(DbContext context) : base(context)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool DeleteByGuildAndRoleId(ulong guildId, ulong roleId)
|
|
||||||
{
|
|
||||||
var role = _set.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId);
|
|
||||||
|
|
||||||
if (role == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_set.Remove(role);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<SelfAssignedRole> GetFromGuild(ulong guildId)
|
|
||||||
=> _set.AsQueryable()
|
|
||||||
.Where(s => s.GuildId == guildId)
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -18,9 +18,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
private IReminderRepository _reminders;
|
private IReminderRepository _reminders;
|
||||||
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
||||||
|
|
||||||
private ISelfAssignedRolesRepository _selfAssignedRoles;
|
|
||||||
public ISelfAssignedRolesRepository SelfAssignedRoles => _selfAssignedRoles ?? (_selfAssignedRoles = new SelfAssignedRolesRepository(_context));
|
|
||||||
|
|
||||||
private IMusicPlaylistRepository _musicPlaylists;
|
private IMusicPlaylistRepository _musicPlaylists;
|
||||||
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user