* Initial commit of changes. Changed permissions from bitwise index to use bitwise flags instead. Modified relevant methods involved * Revised enum value naming * Added FlagsAttribute to ChannelPermission, GuildPermission * Added comments per Joe4evr suggestion * Added underlines to hex value digits for readability per Joe4evr suggestion * updated names to better reflect actual permission names as per SubZero0 suggestion * fix for 236775c2d8aca9481d6c51c674f5727f97adec04 * Replaced Math.Pow with left shift operator * Cleaned up the formatting of ChannelPermission and GuildPermission enums to make it easier to read
This commit is contained in:
committed by
Christopher F
parent
759db34146
commit
f9963380a7
@@ -1,40 +1,36 @@
|
||||
namespace Discord
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public enum ChannelPermission : byte
|
||||
[FlagsAttribute]
|
||||
public enum ChannelPermission : ulong
|
||||
{
|
||||
// General
|
||||
CreateInstantInvite = 0,
|
||||
//KickMembers = 1,
|
||||
//BanMembers = 2,
|
||||
//Administrator = 3,
|
||||
ManageChannel = 4,
|
||||
//ManageGuild = 5,
|
||||
CreateInstantInvite = 0x00_00_00_01,
|
||||
ManageChannels = 0x00_00_00_10,
|
||||
|
||||
// Text
|
||||
AddReactions = 6,
|
||||
ReadMessages = 10,
|
||||
SendMessages = 11,
|
||||
SendTTSMessages = 12,
|
||||
ManageMessages = 13,
|
||||
EmbedLinks = 14,
|
||||
AttachFiles = 15,
|
||||
ReadMessageHistory = 16,
|
||||
MentionEveryone = 17,
|
||||
UseExternalEmojis = 18,
|
||||
AddReactions = 0x00_00_00_40,
|
||||
ReadMessages = 0x00_00_04_00,
|
||||
SendMessages = 0x00_00_08_00,
|
||||
SendTTSMessages = 0x00_00_10_00,
|
||||
ManageMessages = 0x00_00_20_00,
|
||||
EmbedLinks = 0x00_00_40_00,
|
||||
AttachFiles = 0x00_00_80_00,
|
||||
ReadMessageHistory = 0x00_01_00_00,
|
||||
MentionEveryone = 0x00_02_00_00,
|
||||
UseExternalEmojis = 0x00_04_00_00,
|
||||
|
||||
// Voice
|
||||
Connect = 20,
|
||||
Speak = 21,
|
||||
MuteMembers = 22,
|
||||
DeafenMembers = 23,
|
||||
MoveMembers = 24,
|
||||
UseVAD = 25,
|
||||
Connect = 0x00_10_00_00,
|
||||
Speak = 0x00_20_00_00,
|
||||
MuteMembers = 0x00_40_00_00,
|
||||
DeafenMembers = 0x00_80_00_00,
|
||||
MoveMembers = 0x01_00_00_00,
|
||||
UseVAD = 0x02_00_00_00,
|
||||
|
||||
//General2
|
||||
//ChangeNickname = 26,
|
||||
//ManageNicknames = 27,
|
||||
ManagePermissions = 28,
|
||||
ManageWebhooks = 29,
|
||||
//ManageEmojis = 30
|
||||
// More General
|
||||
ManageRoles = 0x10_00_00_00,
|
||||
ManageWebhooks = 0x20_00_00_00,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Discord
|
||||
/// <summary> If True, a user may create invites. </summary>
|
||||
public bool CreateInstantInvite => Permissions.GetValue(RawValue, ChannelPermission.CreateInstantInvite);
|
||||
/// <summary> If True, a user may create, delete and modify this channel. </summary>
|
||||
public bool ManageChannel => Permissions.GetValue(RawValue, ChannelPermission.ManageChannel);
|
||||
public bool ManageChannel => Permissions.GetValue(RawValue, ChannelPermission.ManageChannels);
|
||||
|
||||
/// <summary> If true, a user may add reactions. </summary>
|
||||
public bool AddReactions => Permissions.GetValue(RawValue, ChannelPermission.AddReactions);
|
||||
@@ -72,8 +72,8 @@ namespace Discord
|
||||
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
||||
public bool UseVAD => Permissions.GetValue(RawValue, ChannelPermission.UseVAD);
|
||||
|
||||
/// <summary> If True, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
||||
public bool ManagePermissions => Permissions.GetValue(RawValue, ChannelPermission.ManagePermissions);
|
||||
/// <summary> If True, a user may adjust role permissions. This also implictly grants all other permissions. </summary>
|
||||
public bool ManageRoles => Permissions.GetValue(RawValue, ChannelPermission.ManageRoles);
|
||||
/// <summary> If True, a user may edit the webhooks for this channel. </summary>
|
||||
public bool ManageWebhooks => Permissions.GetValue(RawValue, ChannelPermission.ManageWebhooks);
|
||||
|
||||
@@ -85,12 +85,12 @@ namespace Discord
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||
bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? managePermissions = null, bool? manageWebhooks = null)
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null)
|
||||
{
|
||||
ulong value = initialValue;
|
||||
|
||||
Permissions.SetValue(ref value, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||
Permissions.SetValue(ref value, manageChannel, ChannelPermission.ManageChannel);
|
||||
Permissions.SetValue(ref value, manageChannel, ChannelPermission.ManageChannels);
|
||||
Permissions.SetValue(ref value, addReactions, ChannelPermission.AddReactions);
|
||||
Permissions.SetValue(ref value, readMessages, ChannelPermission.ReadMessages);
|
||||
Permissions.SetValue(ref value, sendMessages, ChannelPermission.SendMessages);
|
||||
@@ -107,7 +107,7 @@ namespace Discord
|
||||
Permissions.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers);
|
||||
Permissions.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers);
|
||||
Permissions.SetValue(ref value, useVoiceActivation, ChannelPermission.UseVAD);
|
||||
Permissions.SetValue(ref value, managePermissions, ChannelPermission.ManagePermissions);
|
||||
Permissions.SetValue(ref value, manageRoles, ChannelPermission.ManageRoles);
|
||||
Permissions.SetValue(ref value, manageWebhooks, ChannelPermission.ManageWebhooks);
|
||||
|
||||
RawValue = value;
|
||||
@@ -119,10 +119,10 @@ namespace Discord
|
||||
bool readMessages = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false,
|
||||
bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false,
|
||||
bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false,
|
||||
bool moveMembers = false, bool useVoiceActivation = false, bool managePermissions = false, bool manageWebhooks = false)
|
||||
bool moveMembers = false, bool useVoiceActivation = false, bool manageRoles = false, bool manageWebhooks = false)
|
||||
: this(0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, managePermissions, manageWebhooks)
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks)
|
||||
{ }
|
||||
|
||||
/// <summary> Creates a new ChannelPermissions from this one, changing the provided non-null permissions. </summary>
|
||||
@@ -131,21 +131,21 @@ namespace Discord
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||
bool useExternalEmojis = false, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? managePermissions = null, bool? manageWebhooks = null)
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null)
|
||||
=> new ChannelPermissions(RawValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, managePermissions, manageWebhooks);
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks);
|
||||
|
||||
public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission);
|
||||
|
||||
public List<ChannelPermission> ToList()
|
||||
{
|
||||
var perms = new List<ChannelPermission>();
|
||||
ulong x = 1;
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++)
|
||||
{
|
||||
if ((RawValue & x) != 0)
|
||||
perms.Add((ChannelPermission)i);
|
||||
ulong flag = ((ulong)1 << i);
|
||||
if ((RawValue & flag) != 0)
|
||||
perms.Add((ChannelPermission)flag);
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
namespace Discord
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public enum GuildPermission : byte
|
||||
[FlagsAttribute]
|
||||
public enum GuildPermission : ulong
|
||||
{
|
||||
// General
|
||||
CreateInstantInvite = 0,
|
||||
KickMembers = 1,
|
||||
BanMembers = 2,
|
||||
Administrator = 3,
|
||||
ManageChannels = 4,
|
||||
ManageGuild = 5,
|
||||
CreateInstantInvite = 0x00_00_00_01,
|
||||
KickMembers = 0x00_00_00_02,
|
||||
BanMembers = 0x00_00_00_04,
|
||||
Administrator = 0x00_00_00_08,
|
||||
ManageChannels = 0x00_00_00_10,
|
||||
ManageGuild = 0x00_00_00_20,
|
||||
|
||||
// Text
|
||||
AddReactions = 6,
|
||||
ReadMessages = 10,
|
||||
SendMessages = 11,
|
||||
SendTTSMessages = 12,
|
||||
ManageMessages = 13,
|
||||
EmbedLinks = 14,
|
||||
AttachFiles = 15,
|
||||
ReadMessageHistory = 16,
|
||||
MentionEveryone = 17,
|
||||
UseExternalEmojis = 18,
|
||||
AddReactions = 0x00_00_00_40,
|
||||
ViewAuditLog = 0x00_00_00_80,
|
||||
ReadMessages = 0x00_00_04_00,
|
||||
SendMessages = 0x00_00_08_00,
|
||||
SendTTSMessages = 0x00_00_10_00,
|
||||
ManageMessages = 0x00_00_20_00,
|
||||
EmbedLinks = 0x00_00_40_00,
|
||||
AttachFiles = 0x00_00_80_00,
|
||||
ReadMessageHistory = 0x00_01_00_00,
|
||||
MentionEveryone = 0x00_02_00_00,
|
||||
UseExternalEmojis = 0x00_04_00_00,
|
||||
|
||||
// Voice
|
||||
Connect = 20,
|
||||
Speak = 21,
|
||||
MuteMembers = 22,
|
||||
DeafenMembers = 23,
|
||||
MoveMembers = 24,
|
||||
UseVAD = 25,
|
||||
Connect = 0x00_10_00_00,
|
||||
Speak = 0x00_20_00_00,
|
||||
MuteMembers = 0x00_40_00_00,
|
||||
DeafenMembers = 0x00_80_00_00,
|
||||
MoveMembers = 0x01_00_00_00,
|
||||
UseVAD = 0x02_00_00_00,
|
||||
|
||||
// General 2
|
||||
ChangeNickname = 26,
|
||||
ManageNicknames = 27,
|
||||
ManageRoles = 28,
|
||||
ManageWebhooks = 29,
|
||||
ManageEmojis = 30
|
||||
ChangeNickname = 0x04_00_00_00,
|
||||
ManageNicknames = 0x08_00_00_00,
|
||||
ManageRoles = 0x10_00_00_00,
|
||||
ManageWebhooks = 0x20_00_00_00,
|
||||
ManageEmojis = 0x40_00_00_00
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Discord
|
||||
/// <summary> Gets a GuildPermissions that grants all guild permissions for webhook users. </summary>
|
||||
public static readonly GuildPermissions Webhook = new GuildPermissions(0b00000_0000000_0001101100000_000000);
|
||||
/// <summary> Gets a GuildPermissions that grants all guild permissions. </summary>
|
||||
public static readonly GuildPermissions All = new GuildPermissions(0b11111_1111110_0111111110001_111111);
|
||||
public static readonly GuildPermissions All = new GuildPermissions(0b11111_1111110_0111111110011_111111);
|
||||
|
||||
/// <summary> Gets a packed value representing all the permissions in this GuildPermissions. </summary>
|
||||
public ulong RawValue { get; }
|
||||
@@ -31,6 +31,9 @@ namespace Discord
|
||||
|
||||
/// <summary> If true, a user may add reactions. </summary>
|
||||
public bool AddReactions => Permissions.GetValue(RawValue, GuildPermission.AddReactions);
|
||||
/// <summary> If true, a user may view the audit log. </summary>
|
||||
public bool ViewAuditLog => Permissions.GetValue(RawValue, GuildPermission.ViewAuditLog);
|
||||
|
||||
/// <summary> If True, a user may join channels. </summary>
|
||||
public bool ReadMessages => Permissions.GetValue(RawValue, GuildPermission.ReadMessages);
|
||||
/// <summary> If True, a user may send messages. </summary>
|
||||
@@ -78,11 +81,11 @@ namespace Discord
|
||||
public GuildPermissions(ulong rawValue) { RawValue = rawValue; }
|
||||
|
||||
private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null,
|
||||
bool? banMembers = null, bool? administrator = null, bool? manageChannel = null, bool? manageGuild = null,
|
||||
bool? addReactions = null,
|
||||
bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null,
|
||||
bool? addReactions = null, bool? viewAuditLog = null,
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||
bool? userExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||
bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null,
|
||||
bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null)
|
||||
{
|
||||
@@ -92,9 +95,10 @@ namespace Discord
|
||||
Permissions.SetValue(ref value, banMembers, GuildPermission.BanMembers);
|
||||
Permissions.SetValue(ref value, kickMembers, GuildPermission.KickMembers);
|
||||
Permissions.SetValue(ref value, administrator, GuildPermission.Administrator);
|
||||
Permissions.SetValue(ref value, manageChannel, GuildPermission.ManageChannels);
|
||||
Permissions.SetValue(ref value, manageChannels, GuildPermission.ManageChannels);
|
||||
Permissions.SetValue(ref value, manageGuild, GuildPermission.ManageGuild);
|
||||
Permissions.SetValue(ref value, addReactions, GuildPermission.AddReactions);
|
||||
Permissions.SetValue(ref value, viewAuditLog, GuildPermission.ViewAuditLog);
|
||||
Permissions.SetValue(ref value, readMessages, GuildPermission.ReadMessages);
|
||||
Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages);
|
||||
Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages);
|
||||
@@ -103,7 +107,7 @@ namespace Discord
|
||||
Permissions.SetValue(ref value, attachFiles, GuildPermission.AttachFiles);
|
||||
Permissions.SetValue(ref value, readMessageHistory, GuildPermission.ReadMessageHistory);
|
||||
Permissions.SetValue(ref value, mentionEveryone, GuildPermission.MentionEveryone);
|
||||
Permissions.SetValue(ref value, userExternalEmojis, GuildPermission.UseExternalEmojis);
|
||||
Permissions.SetValue(ref value, useExternalEmojis, GuildPermission.UseExternalEmojis);
|
||||
Permissions.SetValue(ref value, connect, GuildPermission.Connect);
|
||||
Permissions.SetValue(ref value, speak, GuildPermission.Speak);
|
||||
Permissions.SetValue(ref value, muteMembers, GuildPermission.MuteMembers);
|
||||
@@ -122,26 +126,26 @@ namespace Discord
|
||||
/// <summary> Creates a new GuildPermissions with the provided permissions. </summary>
|
||||
public GuildPermissions(bool createInstantInvite = false, bool kickMembers = false,
|
||||
bool banMembers = false, bool administrator = false, bool manageChannels = false, bool manageGuild = false,
|
||||
bool addReactions = false,
|
||||
bool addReactions = false, bool viewAuditLog = false,
|
||||
bool readMessages = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false,
|
||||
bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false,
|
||||
bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false,
|
||||
bool moveMembers = false, bool useVoiceActivation = false, bool? changeNickname = false, bool? manageNicknames = false,
|
||||
bool manageRoles = false, bool manageWebhooks = false, bool manageEmojis = false)
|
||||
: this(0, createInstantInvite, manageRoles, kickMembers, banMembers, manageChannels, manageGuild, addReactions,
|
||||
: this(0, createInstantInvite, manageRoles, kickMembers, banMembers, manageChannels, manageGuild, addReactions, viewAuditLog,
|
||||
readMessages, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, mentionEveryone, useExternalEmojis, connect,
|
||||
manageWebhooks, manageEmojis) { }
|
||||
|
||||
/// <summary> Creates a new GuildPermissions from this one, changing the provided non-null permissions. </summary>
|
||||
public GuildPermissions Modify(bool? createInstantInvite = null, bool? kickMembers = null,
|
||||
bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null,
|
||||
bool? addReactions = null,
|
||||
bool? addReactions = null, bool? viewAuditLog = null,
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||
bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null,
|
||||
bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null)
|
||||
=> new GuildPermissions(RawValue, createInstantInvite, manageRoles, kickMembers, banMembers, manageChannels, manageGuild, addReactions,
|
||||
=> new GuildPermissions(RawValue, createInstantInvite, manageRoles, kickMembers, banMembers, manageChannels, manageGuild, addReactions, viewAuditLog,
|
||||
readMessages, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, mentionEveryone, useExternalEmojis, connect,
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, changeNickname, manageNicknames, manageRoles,
|
||||
manageWebhooks, manageEmojis);
|
||||
@@ -151,11 +155,14 @@ namespace Discord
|
||||
public List<GuildPermission> ToList()
|
||||
{
|
||||
var perms = new List<GuildPermission>();
|
||||
ulong x = 1;
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||
|
||||
// bitwise operations on raw value
|
||||
// each of the GuildPermissions increments by 2^i from 0 to MaxBits
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++)
|
||||
{
|
||||
if ((RawValue & x) != 0)
|
||||
perms.Add((GuildPermission)i);
|
||||
ulong flag = ((ulong)1 << i);
|
||||
if ((RawValue & flag) != 0)
|
||||
perms.Add((GuildPermission)flag);
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Discord
|
||||
/// <summary> If Allowed, a user may create invites. </summary>
|
||||
public PermValue CreateInstantInvite => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.CreateInstantInvite);
|
||||
/// <summary> If Allowed, a user may create, delete and modify this channel. </summary>
|
||||
public PermValue ManageChannel => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageChannel);
|
||||
public PermValue ManageChannel => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageChannels);
|
||||
/// <summary> If Allowed, a user may add reactions. </summary>
|
||||
public PermValue AddReactions => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.AddReactions);
|
||||
/// <summary> If Allowed, a user may join channels. </summary>
|
||||
@@ -58,8 +58,8 @@ namespace Discord
|
||||
/// <summary> If Allowed, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
||||
public PermValue UseVAD => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.UseVAD);
|
||||
|
||||
/// <summary> If Allowed, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
||||
public PermValue ManagePermissions => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManagePermissions);
|
||||
/// <summary> If Allowed, a user may adjust role permissions. This also implictly grants all other permissions. </summary>
|
||||
public PermValue ManageRoles => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageRoles);
|
||||
/// <summary> If True, a user may edit the webhooks for this channel. </summary>
|
||||
public PermValue ManageWebhooks => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageWebhooks);
|
||||
|
||||
@@ -75,11 +75,11 @@ namespace Discord
|
||||
PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null,
|
||||
PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null,
|
||||
PermValue? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null,
|
||||
PermValue? deafenMembers = null, PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? managePermissions = null,
|
||||
PermValue? deafenMembers = null, PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null,
|
||||
PermValue? manageWebhooks = null)
|
||||
{
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, manageChannel, ChannelPermission.ManageChannel);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, manageChannel, ChannelPermission.ManageChannels);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, addReactions, ChannelPermission.AddReactions);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, readMessages, ChannelPermission.ReadMessages);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, sendMessages, ChannelPermission.SendMessages);
|
||||
@@ -96,7 +96,7 @@ namespace Discord
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, deafenMembers, ChannelPermission.DeafenMembers);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, moveMembers, ChannelPermission.MoveMembers);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, useVoiceActivation, ChannelPermission.UseVAD);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, managePermissions, ChannelPermission.ManagePermissions);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, manageRoles, ChannelPermission.ManageRoles);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, manageWebhooks, ChannelPermission.ManageWebhooks);
|
||||
|
||||
AllowValue = allowValue;
|
||||
@@ -109,10 +109,10 @@ namespace Discord
|
||||
PermValue readMessages = PermValue.Inherit, PermValue sendMessages = PermValue.Inherit, PermValue sendTTSMessages = PermValue.Inherit, PermValue manageMessages = PermValue.Inherit,
|
||||
PermValue embedLinks = PermValue.Inherit, PermValue attachFiles = PermValue.Inherit, PermValue readMessageHistory = PermValue.Inherit, PermValue mentionEveryone = PermValue.Inherit,
|
||||
PermValue useExternalEmojis = PermValue.Inherit, PermValue connect = PermValue.Inherit, PermValue speak = PermValue.Inherit, PermValue muteMembers = PermValue.Inherit, PermValue deafenMembers = PermValue.Inherit,
|
||||
PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue managePermissions = PermValue.Inherit, PermValue manageWebhooks = PermValue.Inherit)
|
||||
PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue manageRoles = PermValue.Inherit, PermValue manageWebhooks = PermValue.Inherit)
|
||||
: this(0, 0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
|
||||
moveMembers, useVoiceActivation, managePermissions, manageWebhooks) { }
|
||||
moveMembers, useVoiceActivation, manageRoles, manageWebhooks) { }
|
||||
|
||||
/// <summary> Creates a new OverwritePermissions from this one, changing the provided non-null permissions. </summary>
|
||||
public OverwritePermissions Modify(PermValue? createInstantInvite = null, PermValue? manageChannel = null,
|
||||
@@ -120,30 +120,31 @@ namespace Discord
|
||||
PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null,
|
||||
PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null,
|
||||
PermValue? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null,
|
||||
PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? managePermissions = null, PermValue? manageWebhooks = null)
|
||||
PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, PermValue? manageWebhooks = null)
|
||||
=> new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
|
||||
moveMembers, useVoiceActivation, managePermissions, manageWebhooks);
|
||||
moveMembers, useVoiceActivation, manageRoles, manageWebhooks);
|
||||
|
||||
public List<ChannelPermission> ToAllowList()
|
||||
{
|
||||
var perms = new List<ChannelPermission>();
|
||||
ulong x = 1;
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++)
|
||||
{
|
||||
if ((AllowValue & x) != 0)
|
||||
perms.Add((ChannelPermission)i);
|
||||
// first operand must be long or ulong to shift >31 bits
|
||||
ulong flag = ((ulong)1 << i);
|
||||
if ((AllowValue & flag) != 0)
|
||||
perms.Add((ChannelPermission)flag);
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
public List<ChannelPermission> ToDenyList()
|
||||
{
|
||||
var perms = new List<ChannelPermission>();
|
||||
ulong x = 1;
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||
for (byte i = 0; i < Permissions.MaxBits; i++)
|
||||
{
|
||||
if ((DenyValue & x) != 0)
|
||||
perms.Add((ChannelPermission)i);
|
||||
ulong flag = ((ulong)1 << i);
|
||||
if ((DenyValue & flag) != 0)
|
||||
perms.Add((ChannelPermission)flag);
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
|
||||
@@ -7,84 +7,84 @@ namespace Discord
|
||||
public const int MaxBits = 53;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static PermValue GetValue(ulong allow, ulong deny, ChannelPermission bit)
|
||||
=> GetValue(allow, deny, (byte)bit);
|
||||
public static PermValue GetValue(ulong allow, ulong deny, ChannelPermission flag)
|
||||
=> GetValue(allow, deny, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static PermValue GetValue(ulong allow, ulong deny, GuildPermission bit)
|
||||
=> GetValue(allow, deny, (byte)bit);
|
||||
public static PermValue GetValue(ulong allow, ulong deny, GuildPermission flag)
|
||||
=> GetValue(allow, deny, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static PermValue GetValue(ulong allow, ulong deny, byte bit)
|
||||
public static PermValue GetValue(ulong allow, ulong deny, ulong flag)
|
||||
{
|
||||
if (HasBit(allow, bit))
|
||||
if (HasFlag(allow, flag))
|
||||
return PermValue.Allow;
|
||||
else if (HasBit(deny, bit))
|
||||
else if (HasFlag(deny, flag))
|
||||
return PermValue.Deny;
|
||||
else
|
||||
return PermValue.Inherit;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool GetValue(ulong value, ChannelPermission bit)
|
||||
=> GetValue(value, (byte)bit);
|
||||
public static bool GetValue(ulong value, ChannelPermission flag)
|
||||
=> GetValue(value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool GetValue(ulong value, GuildPermission bit)
|
||||
=> GetValue(value, (byte)bit);
|
||||
public static bool GetValue(ulong value, GuildPermission flag)
|
||||
=> GetValue(value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool GetValue(ulong value, byte bit) => HasBit(value, bit);
|
||||
public static bool GetValue(ulong value, ulong flag) => HasFlag(value, flag);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong rawValue, bool? value, ChannelPermission bit)
|
||||
=> SetValue(ref rawValue, value, (byte)bit);
|
||||
public static void SetValue(ref ulong rawValue, bool? value, ChannelPermission flag)
|
||||
=> SetValue(ref rawValue, value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong rawValue, bool? value, GuildPermission bit)
|
||||
=> SetValue(ref rawValue, value, (byte)bit);
|
||||
public static void SetValue(ref ulong rawValue, bool? value, GuildPermission flag)
|
||||
=> SetValue(ref rawValue, value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong rawValue, bool? value, byte bit)
|
||||
public static void SetValue(ref ulong rawValue, bool? value, ulong flag)
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
if (value == true)
|
||||
SetBit(ref rawValue, bit);
|
||||
SetFlag(ref rawValue, flag);
|
||||
else
|
||||
UnsetBit(ref rawValue, bit);
|
||||
UnsetFlag(ref rawValue, flag);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, ChannelPermission bit)
|
||||
=> SetValue(ref allow, ref deny, value, (byte)bit);
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, ChannelPermission flag)
|
||||
=> SetValue(ref allow, ref deny, value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, GuildPermission bit)
|
||||
=> SetValue(ref allow, ref deny, value, (byte)bit);
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, GuildPermission flag)
|
||||
=> SetValue(ref allow, ref deny, value, (ulong)flag);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, byte bit)
|
||||
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, ulong flag)
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case PermValue.Allow:
|
||||
SetBit(ref allow, bit);
|
||||
UnsetBit(ref deny, bit);
|
||||
SetFlag(ref allow, flag);
|
||||
UnsetFlag(ref deny, flag);
|
||||
break;
|
||||
case PermValue.Deny:
|
||||
UnsetBit(ref allow, bit);
|
||||
SetBit(ref deny, bit);
|
||||
UnsetFlag(ref allow, flag);
|
||||
SetFlag(ref deny, flag);
|
||||
break;
|
||||
default:
|
||||
UnsetBit(ref allow, bit);
|
||||
UnsetBit(ref deny, bit);
|
||||
UnsetFlag(ref allow, flag);
|
||||
UnsetFlag(ref deny, flag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool HasBit(ulong value, byte bit) => (value & (1U << bit)) != 0;
|
||||
private static bool HasFlag(ulong value, ulong flag) => (value & flag) != 0;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetBit(ref ulong value, byte bit) => value |= (1U << bit);
|
||||
public static void SetFlag(ref ulong value, ulong flag) => value |= flag;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void UnsetBit(ref ulong value, byte bit) => value &= ~(1U << bit);
|
||||
public static void UnsetFlag(ref ulong value, ulong flag) => value &= ~flag;
|
||||
|
||||
public static ChannelPermissions ToChannelPerms(IGuildChannel channel, ulong guildPermissions)
|
||||
=> new ChannelPermissions(guildPermissions & ChannelPermissions.All(channel).RawValue);
|
||||
|
||||
Reference in New Issue
Block a user