Added role order support to permission resolving

This commit is contained in:
RogueException
2015-10-13 05:27:05 -03:00
parent 356bcc2a65
commit 72f8e4f5df
2 changed files with 8 additions and 4 deletions

View File

@@ -184,11 +184,12 @@ namespace Discord
if (channel == null) return;
var channelOverwrites = channel.PermissionOverwrites;
foreach (var serverRole in Roles)
var orderedRoles = Roles.OrderBy(x => x.Id);
foreach (var serverRole in orderedRoles)
newPermissions |= serverRole.Permissions.RawValue;
foreach (var denyRole in channelOverwrites.Where(x => x.Type == PermissionTarget.Role && x.Deny.RawValue != 0 && RoleIds.Contains(x.TargetId)))
foreach (var denyRole in channelOverwrites.Where(x => x.Type == PermissionTarget.Role && x.Deny.RawValue != 0 && orderedRoles.Any(y => y.Id == x.TargetId)))
newPermissions &= ~denyRole.Deny.RawValue;
foreach (var allowRole in channelOverwrites.Where(x => x.Type == PermissionTarget.Role && x.Allow.RawValue != 0 && RoleIds.Contains(x.TargetId)))
foreach (var allowRole in channelOverwrites.Where(x => x.Type == PermissionTarget.Role && x.Allow.RawValue != 0 && orderedRoles.Any(y => y.Id == x.TargetId)))
newPermissions |= allowRole.Allow.RawValue;
foreach (var denyMembers in channelOverwrites.Where(x => x.Type == PermissionTarget.Member && x.TargetId == UserId && x.Deny.RawValue != 0))
newPermissions &= ~denyMembers.Deny.RawValue;

View File

@@ -45,6 +45,9 @@ namespace Discord
Permissions.Lock();
Color = new PackedColor(0);
Color.Lock();
if (isEveryone)
Position = int.MinValue;
}
internal void Update(API.RoleInfo model)
@@ -53,7 +56,7 @@ namespace Discord
Name = model.Name;
if (model.Hoist != null)
Hoist = model.Hoist.Value;
if (model.Position != null)
if (model.Position != null && !IsEveryone)
Position = model.Position.Value;
if (model.Color != null)
Color.SetRawValue(model.Color.Value);