Browse Source

A few role color fixes

tags/docs-0.9
RogueException 9 years ago
parent
commit
3c882cf2e5
2 changed files with 12 additions and 8 deletions
  1. +9
    -6
      src/Discord.Net/DiscordClient.API.cs
  2. +3
    -2
      src/Discord.Net/Models/PackedColor.cs

+ 9
- 6
src/Discord.Net/DiscordClient.API.cs View File

@@ -652,15 +652,18 @@ namespace Discord
return _api.CreateRole(serverId); 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(); 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) public Task DeleteRole(Role role)


+ 3
- 2
src/Discord.Net/Models/PackedColor.cs View File

@@ -38,9 +38,10 @@ namespace Discord
if (_isLocked) if (_isLocked)
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy."); throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");


uint original = _rawValue;
int bit = 8 * (pos - 1); 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);
} }
} }
} }

Loading…
Cancel
Save