Allow setting the rawvalue of unlocked permission objects
This commit is contained in:
@@ -260,7 +260,7 @@ namespace Discord.API
|
|||||||
public class RoleInfo
|
public class RoleInfo
|
||||||
{
|
{
|
||||||
[JsonProperty("permissions")]
|
[JsonProperty("permissions")]
|
||||||
public int Permissions;
|
public uint Permissions;
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public string Name;
|
public string Name;
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace Discord
|
|||||||
|
|
||||||
if (permissions.RawValue != newPermissions)
|
if (permissions.RawValue != newPermissions)
|
||||||
{
|
{
|
||||||
permissions.RawValue = newPermissions;
|
permissions.SetRawValue(newPermissions);
|
||||||
channel._areMembersStale = true;
|
channel._areMembersStale = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,16 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
private bool _isLocked;
|
private bool _isLocked;
|
||||||
protected uint _rawValue;
|
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; }
|
protected PackedPermissions(bool isLocked, uint rawValue) { _isLocked = isLocked; _rawValue = rawValue; }
|
||||||
|
|
||||||
@@ -92,6 +101,11 @@ namespace Discord
|
|||||||
|
|
||||||
//6 Unused
|
//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 bool GetBit(int pos) => ((_rawValue >> (pos - 1)) & 1U) == 1;
|
||||||
protected void SetBit(int pos, bool value)
|
protected void SetBit(int pos, bool value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Discord
|
|||||||
internal void Update(API.RoleInfo model)
|
internal void Update(API.RoleInfo model)
|
||||||
{
|
{
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Permissions.RawValue = (uint)model.Permissions;
|
Permissions.SetRawValue(model.Permissions);
|
||||||
|
|
||||||
foreach (var member in Members)
|
foreach (var member in Members)
|
||||||
member.UpdatePermissions();
|
member.UpdatePermissions();
|
||||||
|
|||||||
Reference in New Issue
Block a user