;mp almost fixed. Might need a rework >.>

This commit is contained in:
Kwoth 2016-10-07 15:00:42 +02:00
parent ede095fe1e
commit 0eec287e7b
6 changed files with 35 additions and 15 deletions

View File

@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
namespace NadekoBot.Migrations
{
[DbContext(typeof(NadekoSqliteContext))]
[Migration("20161005030440_first")]
[Migration("20161007091612_first")]
partial class first
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -6,6 +6,7 @@ using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -159,8 +160,7 @@ namespace NadekoBot.Modules.Permissions
if (index == 0)
{
perm.Previous = toAdd;
toAdd.Next = perm;
perm.Prepend(toAdd);
return;
}

View File

@ -91,7 +91,8 @@ namespace NadekoBot.Modules.Permissions
Permission p;
using (var uow = DbHandler.UnitOfWork())
{
var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission;
var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
var perms = config.RootPermission;
if (index == perms.Count() - 1)
{
return;
@ -99,7 +100,7 @@ namespace NadekoBot.Modules.Permissions
else if (index == 0)
{
p = perms;
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.Next;
config.RootPermission = perms.Next;
}
else
{
@ -114,7 +115,7 @@ namespace NadekoBot.Modules.Permissions
uow2._context.SaveChanges();
}
await channel.SendMessageAsync($"{imsg.Author.Mention} removed permission **{p.GetCommand()}** from position #{index + 1}.").ConfigureAwait(false);
await channel.SendMessageAsync($"{imsg.Author.Mention} removed permission **{p.GetCommand(channel.Guild)}** from position #{index + 1}.").ConfigureAwait(false);
}
catch (ArgumentOutOfRangeException)
{
@ -136,21 +137,29 @@ namespace NadekoBot.Modules.Permissions
Permission toInsert;
using (var uow = DbHandler.UnitOfWork())
{
var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission;
var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
var perms = config.RootPermission;
if (from == 0)
{
toInsert = perms;
perms = perms.Next;
toInsert.Previous = null;
toInsert.Next = null;
perms.Previous = null;
}
else
{
toInsert = perms.RemoveAt(from);
if (from < to)
to -= 1;
var last = perms.Count() - 1;
if (from == last || to == last)
toInsert.Previous = null;
}
var size = perms.Count();
if (from == size || to == size)
throw new IndexOutOfRangeException();
perms.Insert(to, toInsert);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.GetRoot();
config.RootPermission = perms.GetRoot();
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"`Moved permission:` \"{toInsert.GetCommand()}\" `from #{from} to #{to}.`").ConfigureAwait(false);
await channel.SendMessageAsync($"`Moved permission:` \"{toInsert.GetCommand(channel.Guild)}\" `from #{from} to #{to}.`").ConfigureAwait(false);
return;
}
catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)

View File

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
[DebuggerDisplay("{global::NadekoBot.Modules.Permissions.PermissionExtensions.GetCommand(this)}", Target = typeof(Permission))]
public class Permission : DbEntity
{
public Permission Previous { get; set; } = null;
@ -49,6 +51,15 @@ namespace NadekoBot.Services.Database.Models
return blockNsfw;
}
public Permission Clone() => new Permission()
{
PrimaryTarget = PrimaryTarget,
SecondaryTarget = SecondaryTarget,
PrimaryTargetId = PrimaryTargetId,
SecondaryTargetName = SecondaryTargetName,
State = State,
};
}
public enum PrimaryPermissionType

View File

@ -186,8 +186,8 @@ namespace NadekoBot.Services.Database
var permissionEntity = modelBuilder.Entity<Permission>();
permissionEntity
.HasOne(p => p.Next)
.WithOne(p => p.Previous);
.WithOne(p => p.Previous)
.IsRequired(false);
#endregion
#region LogSettings