mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Removed sar repository
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Modules.Xp;
|
||||
using NadekoBot.Modules.Administration.Common;
|
||||
|
||||
namespace NadekoBot.Core.Modules.Administration.Services
|
||||
{
|
||||
@@ -40,13 +41,13 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
||||
{
|
||||
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))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uow.SelfAssignedRoles.Add(new SelfAssignedRole
|
||||
uow._context.SelfAssignableRoles.Add(new SelfAssignedRole
|
||||
{
|
||||
Group = group,
|
||||
RoleId = role.Id,
|
||||
@@ -194,7 +195,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
||||
bool success;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
success = uow.SelfAssignedRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
||||
success = uow._context.SelfAssignableRoles.DeleteByGuildAndRoleId(guildId, roleId);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
return success;
|
||||
@@ -207,7 +208,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
||||
var gc = uow.GuildConfigs.ForId(guildId, set => set);
|
||||
var autoDelete = gc.AutoDeleteSelfAssignedRoleMessages;
|
||||
var exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||
var roles = uow.SelfAssignedRoles.GetFromGuild(guildId);
|
||||
var roles = uow._context.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
|
||||
return (autoDelete, exclusive, roles);
|
||||
}
|
||||
@@ -217,7 +218,7 @@ namespace NadekoBot.Core.Modules.Administration.Services
|
||||
{
|
||||
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);
|
||||
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));
|
||||
exclusive = gc.ExclusiveSelfAssignedRoles;
|
||||
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
|
||||
.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();
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
IQuoteRepository Quotes { get; }
|
||||
IGuildConfigRepository GuildConfigs { get; }
|
||||
IReminderRepository Reminders { get; }
|
||||
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
|
||||
ICustomReactionRepository CustomReactions { get; }
|
||||
IMusicPlaylistRepository MusicPlaylists { 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;
|
||||
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
||||
|
||||
private ISelfAssignedRolesRepository _selfAssignedRoles;
|
||||
public ISelfAssignedRolesRepository SelfAssignedRoles => _selfAssignedRoles ?? (_selfAssignedRoles = new SelfAssignedRolesRepository(_context));
|
||||
|
||||
private IMusicPlaylistRepository _musicPlaylists;
|
||||
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
||||
|
||||
|
Reference in New Issue
Block a user