Browse Source

Added Set/Remove channel permissions

tags/docs-0.9
Brandon Smith 10 years ago
parent
commit
7e5d33f8ba
2 changed files with 11 additions and 6 deletions
  1. +2
    -2
      src/Discord.Net/DiscordClient.API.cs
  2. +9
    -4
      src/Discord.Net/Models/PackedPermissions.cs

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

@@ -456,8 +456,8 @@ namespace Discord
=> RemoveChannelPermissions(channel?.Id, user?.Id);
public Task RemoveChannelUserPermissions(string channelId, User user)
=> RemoveChannelPermissions(channelId, user?.Id);
public Task RemoveChannelPermissions(Channel channel, string userId)
=> RemoveChannelUserPermissions(channel?.Id, userId);
public Task RemoveChannelUserPermissions(Channel channel, string userId)
=> RemoveChannelPermissions(channel?.Id, userId);
public Task RemoveChannelUserPermissions(string channelId, string userId)
=> RemoveChannelPermissions(channelId, userId);



+ 9
- 4
src/Discord.Net/Models/PackedPermissions.cs View File

@@ -1,4 +1,6 @@
namespace Discord
using System;

namespace Discord
{
public sealed class PackedPermissions
{
@@ -6,6 +8,7 @@
private uint _rawValue;
public uint RawValue { get { return _rawValue; } internal set { _rawValue = value; } } //Internal set bypasses isLocked for API changes.

public PackedPermissions() { _isLocked = false; }
internal PackedPermissions(bool isLocked) { _isLocked = isLocked; }
internal PackedPermissions(bool isLocked, uint rawValue) { _isLocked = isLocked; _rawValue = rawValue; }

@@ -61,13 +64,15 @@
private bool GetBit(int pos) => ((_rawValue >> (pos - 1)) & 1U) == 1;
private void SetBit(int pos, bool value)
{
if (_isLocked)
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
if (value)
_rawValue &= (1U << (pos - 1));
_rawValue |= (1U << (pos - 1));
else
_rawValue |= ~(1U << (pos - 1));
_rawValue &= ~(1U << (pos - 1));
}

public static implicit operator uint (PackedPermissions perms) => perms._rawValue;
public PackedPermissions Edit() => new PackedPermissions(false, _rawValue);
public PackedPermissions Copy() => new PackedPermissions(false, _rawValue);
}
}

Loading…
Cancel
Save