From fb111833ff1025fcbbb0d741f2d5fbad9975455f Mon Sep 17 00:00:00 2001 From: Brandon Smith Date: Sat, 15 Aug 2015 14:27:17 -0300 Subject: [PATCH] Added Role Permissions --- Discord.Net/DiscordClient.cs | 2 +- Discord.Net/Role.cs | 37 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Discord.Net/DiscordClient.cs b/Discord.Net/DiscordClient.cs index 79245481b..903b59b78 100644 --- a/Discord.Net/DiscordClient.cs +++ b/Discord.Net/DiscordClient.cs @@ -118,7 +118,7 @@ namespace Discord (role, model) => { role.Name = model.Name; - role.Permissions = model.Permissions; + role.Permissions.RawValue = (uint)model.Permissions; }, role => { } ); diff --git a/Discord.Net/Role.cs b/Discord.Net/Role.cs index 8178b57ca..db2771309 100644 --- a/Discord.Net/Role.cs +++ b/Discord.Net/Role.cs @@ -4,12 +4,44 @@ namespace Discord { public sealed class Role { + public sealed class PackedPermissions + { + private uint _rawValue; + public uint RawValue { get { return _rawValue; } set { _rawValue = value; } } + + public PackedPermissions() { } + + public bool General_CreateInstantInvite { get { return ((_rawValue >> 0) & 0x1) == 1; } } + public bool General_BanMembers { get { return ((_rawValue >> 1) & 0x1) == 1; } } + public bool General_KickMembers { get { return ((_rawValue >> 2) & 0x1) == 1; } } + public bool General_ManageRoles { get { return ((_rawValue >> 3) & 0x1) == 1; } } + public bool General_ManageChannels { get { return ((_rawValue >> 4) & 0x1) == 1; } } + public bool General_ManageServer { get { return ((_rawValue >> 5) & 0x1) == 1; } } + //4 Unused + public bool Text_ReadMessages { get { return ((_rawValue >> 10) & 0x1) == 1; } } + public bool Text_SendMessages { get { return ((_rawValue >> 11) & 0x1) == 1; } } + public bool Text_SendTTSMessages { get { return ((_rawValue >> 12) & 0x1) == 1; } } + public bool Text_ManageMessages { get { return ((_rawValue >> 13) & 0x1) == 1; } } + public bool Text_EmbedLinks { get { return ((_rawValue >> 14) & 0x1) == 1; } } + public bool Text_AttachFiles { get { return ((_rawValue >> 15) & 0x1) == 1; } } + public bool Text_ReadMessageHistory { get { return ((_rawValue >> 16) & 0x1) == 1; } } + public bool Text_MentionEveryone { get { return ((_rawValue >> 17) & 0x1) == 1; } } + //2 Unused + public bool Voice_Connect { get { return ((_rawValue >> 20) & 0x1) == 1; } } + public bool Voice_Speak { get { return ((_rawValue >> 21) & 0x1) == 1; } } + public bool Voice_MuteMembers { get { return ((_rawValue >> 22) & 0x1) == 1; } } + public bool Voice_DeafenMembers { get { return ((_rawValue >> 23) & 0x1) == 1; } } + public bool Voice_MoveMembers { get { return ((_rawValue >> 24) & 0x1) == 1; } } + public bool Voice_UseVoiceActivation { get { return ((_rawValue >> 25) & 0x1) == 1; } } + //6 Unused + } + private readonly DiscordClient _client; public string Id { get; } public string Name { get; internal set; } - - public int Permissions { get; internal set; } + + public PackedPermissions Permissions { get; } public string ServerId { get; } [JsonIgnore] @@ -17,6 +49,7 @@ namespace Discord internal Role(string id, string serverId, DiscordClient client) { + Permissions = new PackedPermissions(); Id = id; ServerId = serverId; _client = client;