Browse Source

Allow setting the rawvalue of unlocked permission objects

tags/docs-0.9
RogueException 9 years ago
parent
commit
6f9e876252
4 changed files with 18 additions and 4 deletions
  1. +1
    -1
      src/Discord.Net/API/Common.cs
  2. +1
    -1
      src/Discord.Net/Models/Member.cs
  3. +15
    -1
      src/Discord.Net/Models/PackedPermissions.cs
  4. +1
    -1
      src/Discord.Net/Models/Role.cs

+ 1
- 1
src/Discord.Net/API/Common.cs View File

@@ -260,7 +260,7 @@ namespace Discord.API
public class RoleInfo
{
[JsonProperty("permissions")]
public int Permissions;
public uint Permissions;
[JsonProperty("name")]
public string Name;
[JsonProperty("id")]


+ 1
- 1
src/Discord.Net/Models/Member.cs View File

@@ -186,7 +186,7 @@ namespace Discord

if (permissions.RawValue != newPermissions)
{
permissions.RawValue = newPermissions;
permissions.SetRawValue(newPermissions);
channel._areMembersStale = true;
}
}


+ 15
- 1
src/Discord.Net/Models/PackedPermissions.cs View File

@@ -44,7 +44,16 @@ namespace Discord
{
private bool _isLocked;
protected uint _rawValue;
public uint RawValue { get { return _rawValue; } internal set { _rawValue = value; } } //Internal set bypasses isLocked for API changes.
public uint RawValue
{
get { return _rawValue; }
set
{
if (_isLocked)
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
_rawValue = value;
}
}
protected PackedPermissions(bool isLocked, uint rawValue) { _isLocked = isLocked; _rawValue = rawValue; }

@@ -92,6 +101,11 @@ namespace Discord

//6 Unused

internal void SetRawValue(uint rawValue)
{
//Bypasses isLocked for API changes.
_rawValue = rawValue;
}
protected bool GetBit(int pos) => ((_rawValue >> (pos - 1)) & 1U) == 1;
protected void SetBit(int pos, bool value)
{


+ 1
- 1
src/Discord.Net/Models/Role.cs View File

@@ -41,7 +41,7 @@ namespace Discord
internal void Update(API.RoleInfo model)
{
Name = model.Name;
Permissions.RawValue = (uint)model.Permissions;
Permissions.SetRawValue(model.Permissions);

foreach (var member in Members)
member.UpdatePermissions();


Loading…
Cancel
Save