A few role color fixes

This commit is contained in:
RogueException
2015-10-13 04:42:21 -03:00
parent bf49a7ff95
commit 3c882cf2e5
2 changed files with 12 additions and 8 deletions

View File

@@ -652,15 +652,18 @@ namespace Discord
return _api.CreateRole(serverId);
}
public Task EditRole(Role role, string newName)
=> EditRole(role?.ServerId, role?.Id, newName);
public Task EditRole(string serverId, string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null)
public Task EditRole(string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null)
=> EditRole(_roles[roleId], name: name, permissions: permissions, color: color, hoist: hoist);
public Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null)
{
CheckReady();
if (serverId == null) throw new NullReferenceException(nameof(serverId));
if (roleId == null) throw new NullReferenceException(nameof(roleId));
if (role == null) throw new NullReferenceException(nameof(role));
return _api.EditRole(serverId, roleId, name: name, permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist);
return _api.EditRole(role.ServerId, role.Id,
name: name ?? role.Name,
permissions: permissions?.RawValue ?? role.Permissions.RawValue,
color: color?.RawValue ?? role.Color.RawValue,
hoist: hoist ?? role.Hoist);
}
public Task DeleteRole(Role role)

View File

@@ -38,9 +38,10 @@ namespace Discord
if (_isLocked)
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
uint original = _rawValue;
int bit = 8 * (pos - 1);
uint mask = (uint)((1 << bit) - 1);
_rawValue = ((uint)value << bit) | (_rawValue & mask);
uint mask = (uint)~(0xFF << bit);
_rawValue = (_rawValue & mask) | ((uint)value << bit);
}
}
}