Cleaned up helpers and permissions, bumped perms up to uint64.
This commit is contained in:
@@ -9,8 +9,8 @@ namespace Discord.API
|
|||||||
[JsonProperty("type")]
|
[JsonProperty("type")]
|
||||||
public PermissionTarget TargetType { get; set; }
|
public PermissionTarget TargetType { get; set; }
|
||||||
[JsonProperty("deny")]
|
[JsonProperty("deny")]
|
||||||
public uint Deny { get; set; }
|
public ulong Deny { get; set; }
|
||||||
[JsonProperty("allow")]
|
[JsonProperty("allow")]
|
||||||
public uint Allow { get; set; }
|
public ulong Allow { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Discord.API
|
|||||||
[JsonProperty("position")]
|
[JsonProperty("position")]
|
||||||
public int? Position { get; set; }
|
public int? Position { get; set; }
|
||||||
[JsonProperty("permissions")]
|
[JsonProperty("permissions")]
|
||||||
public uint? Permissions { get; set; }
|
public ulong? Permissions { get; set; }
|
||||||
[JsonProperty("managed")]
|
[JsonProperty("managed")]
|
||||||
public bool? Managed { get; set; }
|
public bool? Managed { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace Discord.API.Rest
|
|||||||
public class ModifyChannelPermissionsParams
|
public class ModifyChannelPermissionsParams
|
||||||
{
|
{
|
||||||
[JsonProperty("allow")]
|
[JsonProperty("allow")]
|
||||||
public Optional<uint> Allow { get; set; }
|
public Optional<ulong> Allow { get; set; }
|
||||||
[JsonProperty("deny")]
|
[JsonProperty("deny")]
|
||||||
public Optional<uint> Deny { get; set; }
|
public Optional<ulong> Deny { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Discord.API.Rest
|
|||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public Optional<string> Name { get; set; }
|
public Optional<string> Name { get; set; }
|
||||||
[JsonProperty("permissions")]
|
[JsonProperty("permissions")]
|
||||||
public Optional<uint> Permissions { get; set; }
|
public Optional<ulong> Permissions { get; set; }
|
||||||
[JsonProperty("position")]
|
[JsonProperty("position")]
|
||||||
public Optional<int> Position { get; set; }
|
public Optional<int> Position { get; set; }
|
||||||
[JsonProperty("color")]
|
[JsonProperty("color")]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
internal static class DateTimeHelper
|
internal static class DateTimeUtils
|
||||||
{
|
{
|
||||||
private const ulong EpochTicks = 621355968000000000UL;
|
private const ulong EpochTicks = 621355968000000000UL;
|
||||||
|
|
||||||
@@ -25,74 +25,74 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets a packed value representing all the permissions in this ChannelPermissions. </summary>
|
/// <summary> Gets a packed value representing all the permissions in this ChannelPermissions. </summary>
|
||||||
public uint RawValue { get; }
|
public ulong RawValue { get; }
|
||||||
|
|
||||||
/// <summary> If True, a user may create invites. </summary>
|
/// <summary> If True, a user may create invites. </summary>
|
||||||
public bool CreateInstantInvite => PermissionUtilities.GetValue(RawValue, ChannelPermission.CreateInstantInvite);
|
public bool CreateInstantInvite => Permissions.GetValue(RawValue, ChannelPermission.CreateInstantInvite);
|
||||||
/// <summary> If True, a user may create, delete and modify this channel. </summary>
|
/// <summary> If True, a user may create, delete and modify this channel. </summary>
|
||||||
public bool ManageChannel => PermissionUtilities.GetValue(RawValue, ChannelPermission.ManageChannel);
|
public bool ManageChannel => Permissions.GetValue(RawValue, ChannelPermission.ManageChannel);
|
||||||
|
|
||||||
/// <summary> If True, a user may join channels. </summary>
|
/// <summary> If True, a user may join channels. </summary>
|
||||||
public bool ReadMessages => PermissionUtilities.GetValue(RawValue, ChannelPermission.ReadMessages);
|
public bool ReadMessages => Permissions.GetValue(RawValue, ChannelPermission.ReadMessages);
|
||||||
/// <summary> If True, a user may send messages. </summary>
|
/// <summary> If True, a user may send messages. </summary>
|
||||||
public bool SendMessages => PermissionUtilities.GetValue(RawValue, ChannelPermission.SendMessages);
|
public bool SendMessages => Permissions.GetValue(RawValue, ChannelPermission.SendMessages);
|
||||||
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
||||||
public bool SendTTSMessages => PermissionUtilities.GetValue(RawValue, ChannelPermission.SendTTSMessages);
|
public bool SendTTSMessages => Permissions.GetValue(RawValue, ChannelPermission.SendTTSMessages);
|
||||||
/// <summary> If True, a user may delete messages. </summary>
|
/// <summary> If True, a user may delete messages. </summary>
|
||||||
public bool ManageMessages => PermissionUtilities.GetValue(RawValue, ChannelPermission.ManageMessages);
|
public bool ManageMessages => Permissions.GetValue(RawValue, ChannelPermission.ManageMessages);
|
||||||
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
||||||
public bool EmbedLinks => PermissionUtilities.GetValue(RawValue, ChannelPermission.EmbedLinks);
|
public bool EmbedLinks => Permissions.GetValue(RawValue, ChannelPermission.EmbedLinks);
|
||||||
/// <summary> If True, a user may send files. </summary>
|
/// <summary> If True, a user may send files. </summary>
|
||||||
public bool AttachFiles => PermissionUtilities.GetValue(RawValue, ChannelPermission.AttachFiles);
|
public bool AttachFiles => Permissions.GetValue(RawValue, ChannelPermission.AttachFiles);
|
||||||
/// <summary> If True, a user may read previous messages. </summary>
|
/// <summary> If True, a user may read previous messages. </summary>
|
||||||
public bool ReadMessageHistory => PermissionUtilities.GetValue(RawValue, ChannelPermission.ReadMessageHistory);
|
public bool ReadMessageHistory => Permissions.GetValue(RawValue, ChannelPermission.ReadMessageHistory);
|
||||||
/// <summary> If True, a user may mention @everyone. </summary>
|
/// <summary> If True, a user may mention @everyone. </summary>
|
||||||
public bool MentionEveryone => PermissionUtilities.GetValue(RawValue, ChannelPermission.MentionEveryone);
|
public bool MentionEveryone => Permissions.GetValue(RawValue, ChannelPermission.MentionEveryone);
|
||||||
|
|
||||||
/// <summary> If True, a user may connect to a voice channel. </summary>
|
/// <summary> If True, a user may connect to a voice channel. </summary>
|
||||||
public bool Connect => PermissionUtilities.GetValue(RawValue, ChannelPermission.Connect);
|
public bool Connect => Permissions.GetValue(RawValue, ChannelPermission.Connect);
|
||||||
/// <summary> If True, a user may speak in a voice channel. </summary>
|
/// <summary> If True, a user may speak in a voice channel. </summary>
|
||||||
public bool Speak => PermissionUtilities.GetValue(RawValue, ChannelPermission.Speak);
|
public bool Speak => Permissions.GetValue(RawValue, ChannelPermission.Speak);
|
||||||
/// <summary> If True, a user may mute users. </summary>
|
/// <summary> If True, a user may mute users. </summary>
|
||||||
public bool MuteMembers => PermissionUtilities.GetValue(RawValue, ChannelPermission.MuteMembers);
|
public bool MuteMembers => Permissions.GetValue(RawValue, ChannelPermission.MuteMembers);
|
||||||
/// <summary> If True, a user may deafen users. </summary>
|
/// <summary> If True, a user may deafen users. </summary>
|
||||||
public bool DeafenMembers => PermissionUtilities.GetValue(RawValue, ChannelPermission.DeafenMembers);
|
public bool DeafenMembers => Permissions.GetValue(RawValue, ChannelPermission.DeafenMembers);
|
||||||
/// <summary> If True, a user may move other users between voice channels. </summary>
|
/// <summary> If True, a user may move other users between voice channels. </summary>
|
||||||
public bool MoveMembers => PermissionUtilities.GetValue(RawValue, ChannelPermission.MoveMembers);
|
public bool MoveMembers => Permissions.GetValue(RawValue, ChannelPermission.MoveMembers);
|
||||||
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
||||||
public bool UseVAD => PermissionUtilities.GetValue(RawValue, ChannelPermission.UseVAD);
|
public bool UseVAD => Permissions.GetValue(RawValue, ChannelPermission.UseVAD);
|
||||||
|
|
||||||
/// <summary> If True, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
/// <summary> If True, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
||||||
public bool ManagePermissions => PermissionUtilities.GetValue(RawValue, ChannelPermission.ManagePermissions);
|
public bool ManagePermissions => Permissions.GetValue(RawValue, ChannelPermission.ManagePermissions);
|
||||||
|
|
||||||
/// <summary> Creates a new ChannelPermissions with the provided packed value. </summary>
|
/// <summary> Creates a new ChannelPermissions with the provided packed value. </summary>
|
||||||
public ChannelPermissions(uint rawValue) { RawValue = rawValue; }
|
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
|
||||||
|
|
||||||
private ChannelPermissions(uint initialValue, bool? createInstantInvite = null, bool? manageChannel = null,
|
private ChannelPermissions(ulong initialValue, bool? createInstantInvite = null, bool? manageChannel = null,
|
||||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = 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? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||||
bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null,
|
||||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? managePermissions = null)
|
bool? moveMembers = null, bool? useVoiceActivation = null, bool? managePermissions = null)
|
||||||
{
|
{
|
||||||
uint value = initialValue;
|
ulong value = initialValue;
|
||||||
|
|
||||||
PermissionUtilities.SetValue(ref value, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
Permissions.SetValue(ref value, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||||
PermissionUtilities.SetValue(ref value, manageChannel, ChannelPermission.ManageChannel);
|
Permissions.SetValue(ref value, manageChannel, ChannelPermission.ManageChannel);
|
||||||
PermissionUtilities.SetValue(ref value, readMessages, ChannelPermission.ReadMessages);
|
Permissions.SetValue(ref value, readMessages, ChannelPermission.ReadMessages);
|
||||||
PermissionUtilities.SetValue(ref value, sendMessages, ChannelPermission.SendMessages);
|
Permissions.SetValue(ref value, sendMessages, ChannelPermission.SendMessages);
|
||||||
PermissionUtilities.SetValue(ref value, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
Permissions.SetValue(ref value, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
||||||
PermissionUtilities.SetValue(ref value, manageMessages, ChannelPermission.ManageMessages);
|
Permissions.SetValue(ref value, manageMessages, ChannelPermission.ManageMessages);
|
||||||
PermissionUtilities.SetValue(ref value, embedLinks, ChannelPermission.EmbedLinks);
|
Permissions.SetValue(ref value, embedLinks, ChannelPermission.EmbedLinks);
|
||||||
PermissionUtilities.SetValue(ref value, attachFiles, ChannelPermission.AttachFiles);
|
Permissions.SetValue(ref value, attachFiles, ChannelPermission.AttachFiles);
|
||||||
PermissionUtilities.SetValue(ref value, readMessageHistory, ChannelPermission.ReadMessageHistory);
|
Permissions.SetValue(ref value, readMessageHistory, ChannelPermission.ReadMessageHistory);
|
||||||
PermissionUtilities.SetValue(ref value, mentionEveryone, ChannelPermission.MentionEveryone);
|
Permissions.SetValue(ref value, mentionEveryone, ChannelPermission.MentionEveryone);
|
||||||
PermissionUtilities.SetValue(ref value, connect, ChannelPermission.Connect);
|
Permissions.SetValue(ref value, connect, ChannelPermission.Connect);
|
||||||
PermissionUtilities.SetValue(ref value, speak, ChannelPermission.Speak);
|
Permissions.SetValue(ref value, speak, ChannelPermission.Speak);
|
||||||
PermissionUtilities.SetValue(ref value, muteMembers, ChannelPermission.MuteMembers);
|
Permissions.SetValue(ref value, muteMembers, ChannelPermission.MuteMembers);
|
||||||
PermissionUtilities.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers);
|
Permissions.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers);
|
||||||
PermissionUtilities.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers);
|
Permissions.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers);
|
||||||
PermissionUtilities.SetValue(ref value, useVoiceActivation, ChannelPermission.UseVAD);
|
Permissions.SetValue(ref value, useVoiceActivation, ChannelPermission.UseVAD);
|
||||||
PermissionUtilities.SetValue(ref value, managePermissions, ChannelPermission.ManagePermissions);
|
Permissions.SetValue(ref value, managePermissions, ChannelPermission.ManagePermissions);
|
||||||
|
|
||||||
RawValue = value;
|
RawValue = value;
|
||||||
}
|
}
|
||||||
@@ -121,8 +121,8 @@ namespace Discord
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var perms = new List<string>();
|
var perms = new List<string>();
|
||||||
int x = 1;
|
ulong x = 1;
|
||||||
for (byte i = 0; i < 32; i++, x <<= 1)
|
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||||
{
|
{
|
||||||
if ((RawValue & x) != 0)
|
if ((RawValue & x) != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,62 +10,62 @@ namespace Discord
|
|||||||
public static readonly GuildPermissions All = new GuildPermissions(0b000111_111111_0011111111_0000111111);
|
public static readonly GuildPermissions All = new GuildPermissions(0b000111_111111_0011111111_0000111111);
|
||||||
|
|
||||||
/// <summary> Gets a packed value representing all the permissions in this GuildPermissions. </summary>
|
/// <summary> Gets a packed value representing all the permissions in this GuildPermissions. </summary>
|
||||||
public uint RawValue { get; }
|
public ulong RawValue { get; }
|
||||||
|
|
||||||
/// <summary> If True, a user may create invites. </summary>
|
/// <summary> If True, a user may create invites. </summary>
|
||||||
public bool CreateInstantInvite => PermissionUtilities.GetValue(RawValue, GuildPermission.CreateInstantInvite);
|
public bool CreateInstantInvite => Permissions.GetValue(RawValue, GuildPermission.CreateInstantInvite);
|
||||||
/// <summary> If True, a user may ban users from the guild. </summary>
|
/// <summary> If True, a user may ban users from the guild. </summary>
|
||||||
public bool BanMembers => PermissionUtilities.GetValue(RawValue, GuildPermission.BanMembers);
|
public bool BanMembers => Permissions.GetValue(RawValue, GuildPermission.BanMembers);
|
||||||
/// <summary> If True, a user may kick users from the guild. </summary>
|
/// <summary> If True, a user may kick users from the guild. </summary>
|
||||||
public bool KickMembers => PermissionUtilities.GetValue(RawValue, GuildPermission.KickMembers);
|
public bool KickMembers => Permissions.GetValue(RawValue, GuildPermission.KickMembers);
|
||||||
/// <summary> If True, a user is granted all permissions, and cannot have them revoked via channel permissions. </summary>
|
/// <summary> If True, a user is granted all permissions, and cannot have them revoked via channel permissions. </summary>
|
||||||
public bool Administrator => PermissionUtilities.GetValue(RawValue, GuildPermission.Administrator);
|
public bool Administrator => Permissions.GetValue(RawValue, GuildPermission.Administrator);
|
||||||
/// <summary> If True, a user may create, delete and modify channels. </summary>
|
/// <summary> If True, a user may create, delete and modify channels. </summary>
|
||||||
public bool ManageChannels => PermissionUtilities.GetValue(RawValue, GuildPermission.ManageChannels);
|
public bool ManageChannels => Permissions.GetValue(RawValue, GuildPermission.ManageChannels);
|
||||||
/// <summary> If True, a user may adjust guild properties. </summary>
|
/// <summary> If True, a user may adjust guild properties. </summary>
|
||||||
public bool ManageGuild => PermissionUtilities.GetValue(RawValue, GuildPermission.ManageGuild);
|
public bool ManageGuild => Permissions.GetValue(RawValue, GuildPermission.ManageGuild);
|
||||||
|
|
||||||
/// <summary> If True, a user may join channels. </summary>
|
/// <summary> If True, a user may join channels. </summary>
|
||||||
public bool ReadMessages => PermissionUtilities.GetValue(RawValue, GuildPermission.ReadMessages);
|
public bool ReadMessages => Permissions.GetValue(RawValue, GuildPermission.ReadMessages);
|
||||||
/// <summary> If True, a user may send messages. </summary>
|
/// <summary> If True, a user may send messages. </summary>
|
||||||
public bool SendMessages => PermissionUtilities.GetValue(RawValue, GuildPermission.SendMessages);
|
public bool SendMessages => Permissions.GetValue(RawValue, GuildPermission.SendMessages);
|
||||||
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
||||||
public bool SendTTSMessages => PermissionUtilities.GetValue(RawValue, GuildPermission.SendTTSMessages);
|
public bool SendTTSMessages => Permissions.GetValue(RawValue, GuildPermission.SendTTSMessages);
|
||||||
/// <summary> If True, a user may delete messages. </summary>
|
/// <summary> If True, a user may delete messages. </summary>
|
||||||
public bool ManageMessages => PermissionUtilities.GetValue(RawValue, GuildPermission.ManageMessages);
|
public bool ManageMessages => Permissions.GetValue(RawValue, GuildPermission.ManageMessages);
|
||||||
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
||||||
public bool EmbedLinks => PermissionUtilities.GetValue(RawValue, GuildPermission.EmbedLinks);
|
public bool EmbedLinks => Permissions.GetValue(RawValue, GuildPermission.EmbedLinks);
|
||||||
/// <summary> If True, a user may send files. </summary>
|
/// <summary> If True, a user may send files. </summary>
|
||||||
public bool AttachFiles => PermissionUtilities.GetValue(RawValue, GuildPermission.AttachFiles);
|
public bool AttachFiles => Permissions.GetValue(RawValue, GuildPermission.AttachFiles);
|
||||||
/// <summary> If True, a user may read previous messages. </summary>
|
/// <summary> If True, a user may read previous messages. </summary>
|
||||||
public bool ReadMessageHistory => PermissionUtilities.GetValue(RawValue, GuildPermission.ReadMessageHistory);
|
public bool ReadMessageHistory => Permissions.GetValue(RawValue, GuildPermission.ReadMessageHistory);
|
||||||
/// <summary> If True, a user may mention @everyone. </summary>
|
/// <summary> If True, a user may mention @everyone. </summary>
|
||||||
public bool MentionEveryone => PermissionUtilities.GetValue(RawValue, GuildPermission.MentionEveryone);
|
public bool MentionEveryone => Permissions.GetValue(RawValue, GuildPermission.MentionEveryone);
|
||||||
|
|
||||||
/// <summary> If True, a user may connect to a voice channel. </summary>
|
/// <summary> If True, a user may connect to a voice channel. </summary>
|
||||||
public bool Connect => PermissionUtilities.GetValue(RawValue, GuildPermission.Connect);
|
public bool Connect => Permissions.GetValue(RawValue, GuildPermission.Connect);
|
||||||
/// <summary> If True, a user may speak in a voice channel. </summary>
|
/// <summary> If True, a user may speak in a voice channel. </summary>
|
||||||
public bool Speak => PermissionUtilities.GetValue(RawValue, GuildPermission.Speak);
|
public bool Speak => Permissions.GetValue(RawValue, GuildPermission.Speak);
|
||||||
/// <summary> If True, a user may mute users. </summary>
|
/// <summary> If True, a user may mute users. </summary>
|
||||||
public bool MuteMembers => PermissionUtilities.GetValue(RawValue, GuildPermission.MuteMembers);
|
public bool MuteMembers => Permissions.GetValue(RawValue, GuildPermission.MuteMembers);
|
||||||
/// <summary> If True, a user may deafen users. </summary>
|
/// <summary> If True, a user may deafen users. </summary>
|
||||||
public bool DeafenMembers => PermissionUtilities.GetValue(RawValue, GuildPermission.DeafenMembers);
|
public bool DeafenMembers => Permissions.GetValue(RawValue, GuildPermission.DeafenMembers);
|
||||||
/// <summary> If True, a user may move other users between voice channels. </summary>
|
/// <summary> If True, a user may move other users between voice channels. </summary>
|
||||||
public bool MoveMembers => PermissionUtilities.GetValue(RawValue, GuildPermission.MoveMembers);
|
public bool MoveMembers => Permissions.GetValue(RawValue, GuildPermission.MoveMembers);
|
||||||
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
||||||
public bool UseVAD => PermissionUtilities.GetValue(RawValue, GuildPermission.UseVAD);
|
public bool UseVAD => Permissions.GetValue(RawValue, GuildPermission.UseVAD);
|
||||||
|
|
||||||
/// <summary> If True, a user may change their own nickname. </summary>
|
/// <summary> If True, a user may change their own nickname. </summary>
|
||||||
public bool ChangeNickname => PermissionUtilities.GetValue(RawValue, GuildPermission.ChangeNickname);
|
public bool ChangeNickname => Permissions.GetValue(RawValue, GuildPermission.ChangeNickname);
|
||||||
/// <summary> If True, a user may change the nickname of other users. </summary>
|
/// <summary> If True, a user may change the nickname of other users. </summary>
|
||||||
public bool ManageNicknames => PermissionUtilities.GetValue(RawValue, GuildPermission.ManageNicknames);
|
public bool ManageNicknames => Permissions.GetValue(RawValue, GuildPermission.ManageNicknames);
|
||||||
/// <summary> If True, a user may adjust roles. </summary>
|
/// <summary> If True, a user may adjust roles. </summary>
|
||||||
public bool ManageRoles => PermissionUtilities.GetValue(RawValue, GuildPermission.ManageRoles);
|
public bool ManageRoles => Permissions.GetValue(RawValue, GuildPermission.ManageRoles);
|
||||||
|
|
||||||
/// <summary> Creates a new GuildPermissions with the provided packed value. </summary>
|
/// <summary> Creates a new GuildPermissions with the provided packed value. </summary>
|
||||||
public GuildPermissions(uint rawValue) { RawValue = rawValue; }
|
public GuildPermissions(ulong rawValue) { RawValue = rawValue; }
|
||||||
|
|
||||||
private GuildPermissions(uint initialValue, bool? createInstantInvite = null, bool? kickMembers = null,
|
private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null,
|
||||||
bool? banMembers = null, bool? administrator = null, bool? manageChannel = null, bool? manageGuild = null,
|
bool? banMembers = null, bool? administrator = null, bool? manageChannel = null, bool? manageGuild = null,
|
||||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = 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? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null,
|
||||||
@@ -73,31 +73,31 @@ namespace Discord
|
|||||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null,
|
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null,
|
||||||
bool? manageRoles = null)
|
bool? manageRoles = null)
|
||||||
{
|
{
|
||||||
uint value = initialValue;
|
ulong value = initialValue;
|
||||||
|
|
||||||
PermissionUtilities.SetValue(ref value, createInstantInvite, GuildPermission.CreateInstantInvite);
|
Permissions.SetValue(ref value, createInstantInvite, GuildPermission.CreateInstantInvite);
|
||||||
PermissionUtilities.SetValue(ref value, banMembers, GuildPermission.BanMembers);
|
Permissions.SetValue(ref value, banMembers, GuildPermission.BanMembers);
|
||||||
PermissionUtilities.SetValue(ref value, kickMembers, GuildPermission.KickMembers);
|
Permissions.SetValue(ref value, kickMembers, GuildPermission.KickMembers);
|
||||||
PermissionUtilities.SetValue(ref value, administrator, GuildPermission.Administrator);
|
Permissions.SetValue(ref value, administrator, GuildPermission.Administrator);
|
||||||
PermissionUtilities.SetValue(ref value, manageChannel, GuildPermission.ManageChannels);
|
Permissions.SetValue(ref value, manageChannel, GuildPermission.ManageChannels);
|
||||||
PermissionUtilities.SetValue(ref value, manageGuild, GuildPermission.ManageGuild);
|
Permissions.SetValue(ref value, manageGuild, GuildPermission.ManageGuild);
|
||||||
PermissionUtilities.SetValue(ref value, readMessages, GuildPermission.ReadMessages);
|
Permissions.SetValue(ref value, readMessages, GuildPermission.ReadMessages);
|
||||||
PermissionUtilities.SetValue(ref value, sendMessages, GuildPermission.SendMessages);
|
Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages);
|
||||||
PermissionUtilities.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages);
|
Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages);
|
||||||
PermissionUtilities.SetValue(ref value, manageMessages, GuildPermission.ManageMessages);
|
Permissions.SetValue(ref value, manageMessages, GuildPermission.ManageMessages);
|
||||||
PermissionUtilities.SetValue(ref value, embedLinks, GuildPermission.EmbedLinks);
|
Permissions.SetValue(ref value, embedLinks, GuildPermission.EmbedLinks);
|
||||||
PermissionUtilities.SetValue(ref value, attachFiles, GuildPermission.AttachFiles);
|
Permissions.SetValue(ref value, attachFiles, GuildPermission.AttachFiles);
|
||||||
PermissionUtilities.SetValue(ref value, readMessageHistory, GuildPermission.ReadMessageHistory);
|
Permissions.SetValue(ref value, readMessageHistory, GuildPermission.ReadMessageHistory);
|
||||||
PermissionUtilities.SetValue(ref value, mentionEveryone, GuildPermission.MentionEveryone);
|
Permissions.SetValue(ref value, mentionEveryone, GuildPermission.MentionEveryone);
|
||||||
PermissionUtilities.SetValue(ref value, connect, GuildPermission.Connect);
|
Permissions.SetValue(ref value, connect, GuildPermission.Connect);
|
||||||
PermissionUtilities.SetValue(ref value, speak, GuildPermission.Speak);
|
Permissions.SetValue(ref value, speak, GuildPermission.Speak);
|
||||||
PermissionUtilities.SetValue(ref value, muteMembers, GuildPermission.MuteMembers);
|
Permissions.SetValue(ref value, muteMembers, GuildPermission.MuteMembers);
|
||||||
PermissionUtilities.SetValue(ref value, deafenMembers, GuildPermission.DeafenMembers);
|
Permissions.SetValue(ref value, deafenMembers, GuildPermission.DeafenMembers);
|
||||||
PermissionUtilities.SetValue(ref value, moveMembers, GuildPermission.MoveMembers);
|
Permissions.SetValue(ref value, moveMembers, GuildPermission.MoveMembers);
|
||||||
PermissionUtilities.SetValue(ref value, useVoiceActivation, GuildPermission.UseVAD);
|
Permissions.SetValue(ref value, useVoiceActivation, GuildPermission.UseVAD);
|
||||||
PermissionUtilities.SetValue(ref value, changeNickname, GuildPermission.ChangeNickname);
|
Permissions.SetValue(ref value, changeNickname, GuildPermission.ChangeNickname);
|
||||||
PermissionUtilities.SetValue(ref value, manageNicknames, GuildPermission.ManageNicknames);
|
Permissions.SetValue(ref value, manageNicknames, GuildPermission.ManageNicknames);
|
||||||
PermissionUtilities.SetValue(ref value, manageRoles, GuildPermission.ManageRoles);
|
Permissions.SetValue(ref value, manageRoles, GuildPermission.ManageRoles);
|
||||||
|
|
||||||
RawValue = value;
|
RawValue = value;
|
||||||
}
|
}
|
||||||
@@ -130,8 +130,8 @@ namespace Discord
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var perms = new List<string>();
|
var perms = new List<string>();
|
||||||
int x = 1;
|
ulong x = 1;
|
||||||
for (byte i = 0; i < 32; i++, x <<= 1)
|
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||||
{
|
{
|
||||||
if ((RawValue & x) != 0)
|
if ((RawValue & x) != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,77 +15,77 @@ namespace Discord
|
|||||||
=> new OverwritePermissions(0, ChannelPermissions.All(channel).RawValue);
|
=> new OverwritePermissions(0, ChannelPermissions.All(channel).RawValue);
|
||||||
|
|
||||||
/// <summary> Gets a packed value representing all the allowed permissions in this OverwritePermissions. </summary>
|
/// <summary> Gets a packed value representing all the allowed permissions in this OverwritePermissions. </summary>
|
||||||
public uint AllowValue { get; }
|
public ulong AllowValue { get; }
|
||||||
/// <summary> Gets a packed value representing all the denied permissions in this OverwritePermissions. </summary>
|
/// <summary> Gets a packed value representing all the denied permissions in this OverwritePermissions. </summary>
|
||||||
public uint DenyValue { get; }
|
public ulong DenyValue { get; }
|
||||||
|
|
||||||
/// <summary> If True, a user may create invites. </summary>
|
/// <summary> If True, a user may create invites. </summary>
|
||||||
public PermValue CreateInstantInvite => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.CreateInstantInvite);
|
public PermValue CreateInstantInvite => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.CreateInstantInvite);
|
||||||
/// <summary> If True, a user may create, delete and modify this channel. </summary>
|
/// <summary> If True, a user may create, delete and modify this channel. </summary>
|
||||||
public PermValue ManageChannel => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.ManageChannel);
|
public PermValue ManageChannel => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageChannel);
|
||||||
/// <summary> If True, a user may join channels. </summary>
|
/// <summary> If True, a user may join channels. </summary>
|
||||||
public PermValue ReadMessages => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.ReadMessages);
|
public PermValue ReadMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ReadMessages);
|
||||||
/// <summary> If True, a user may send messages. </summary>
|
/// <summary> If True, a user may send messages. </summary>
|
||||||
public PermValue SendMessages => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.SendMessages);
|
public PermValue SendMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.SendMessages);
|
||||||
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
||||||
public PermValue SendTTSMessages => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.SendTTSMessages);
|
public PermValue SendTTSMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.SendTTSMessages);
|
||||||
/// <summary> If True, a user may delete messages. </summary>
|
/// <summary> If True, a user may delete messages. </summary>
|
||||||
public PermValue ManageMessages => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.ManageMessages);
|
public PermValue ManageMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageMessages);
|
||||||
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
/// <summary> If True, Discord will auto-embed links sent by this user. </summary>
|
||||||
public PermValue EmbedLinks => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.EmbedLinks);
|
public PermValue EmbedLinks => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.EmbedLinks);
|
||||||
/// <summary> If True, a user may send files. </summary>
|
/// <summary> If True, a user may send files. </summary>
|
||||||
public PermValue AttachFiles => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.AttachFiles);
|
public PermValue AttachFiles => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.AttachFiles);
|
||||||
/// <summary> If True, a user may read previous messages. </summary>
|
/// <summary> If True, a user may read previous messages. </summary>
|
||||||
public PermValue ReadMessageHistory => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.ReadMessageHistory);
|
public PermValue ReadMessageHistory => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ReadMessageHistory);
|
||||||
/// <summary> If True, a user may mention @everyone. </summary>
|
/// <summary> If True, a user may mention @everyone. </summary>
|
||||||
public PermValue MentionEveryone => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.MentionEveryone);
|
public PermValue MentionEveryone => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.MentionEveryone);
|
||||||
|
|
||||||
/// <summary> If True, a user may connect to a voice channel. </summary>
|
/// <summary> If True, a user may connect to a voice channel. </summary>
|
||||||
public PermValue Connect => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.Connect);
|
public PermValue Connect => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.Connect);
|
||||||
/// <summary> If True, a user may speak in a voice channel. </summary>
|
/// <summary> If True, a user may speak in a voice channel. </summary>
|
||||||
public PermValue Speak => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.Speak);
|
public PermValue Speak => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.Speak);
|
||||||
/// <summary> If True, a user may mute users. </summary>
|
/// <summary> If True, a user may mute users. </summary>
|
||||||
public PermValue MuteMembers => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.MuteMembers);
|
public PermValue MuteMembers => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.MuteMembers);
|
||||||
/// <summary> If True, a user may deafen users. </summary>
|
/// <summary> If True, a user may deafen users. </summary>
|
||||||
public PermValue DeafenMembers => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.DeafenMembers);
|
public PermValue DeafenMembers => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.DeafenMembers);
|
||||||
/// <summary> If True, a user may move other users between voice channels. </summary>
|
/// <summary> If True, a user may move other users between voice channels. </summary>
|
||||||
public PermValue MoveMembers => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.MoveMembers);
|
public PermValue MoveMembers => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.MoveMembers);
|
||||||
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
/// <summary> If True, a user may use voice-activity-detection rather than push-to-talk. </summary>
|
||||||
public PermValue UseVAD => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.UseVAD);
|
public PermValue UseVAD => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.UseVAD);
|
||||||
|
|
||||||
/// <summary> If True, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
/// <summary> If True, a user may adjust permissions. This also implictly grants all other permissions. </summary>
|
||||||
public PermValue ManagePermissions => PermissionUtilities.GetValue(AllowValue, DenyValue, ChannelPermission.ManagePermissions);
|
public PermValue ManagePermissions => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManagePermissions);
|
||||||
|
|
||||||
/// <summary> Creates a new OverwritePermissions with the provided allow and deny packed values. </summary>
|
/// <summary> Creates a new OverwritePermissions with the provided allow and deny packed values. </summary>
|
||||||
public OverwritePermissions(uint allowValue, uint denyValue)
|
public OverwritePermissions(ulong allowValue, ulong denyValue)
|
||||||
{
|
{
|
||||||
AllowValue = allowValue;
|
AllowValue = allowValue;
|
||||||
DenyValue = denyValue;
|
DenyValue = denyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OverwritePermissions(uint allowValue, uint denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null,
|
private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null,
|
||||||
PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null,
|
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? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null,
|
||||||
PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null,
|
PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null,
|
||||||
PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? managePermissions = null)
|
PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? managePermissions = null)
|
||||||
{
|
{
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, manageChannel, ChannelPermission.ManageChannel);
|
Permissions.SetValue(ref allowValue, ref denyValue, manageChannel, ChannelPermission.ManageChannel);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, readMessages, ChannelPermission.ReadMessages);
|
Permissions.SetValue(ref allowValue, ref denyValue, readMessages, ChannelPermission.ReadMessages);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, sendMessages, ChannelPermission.SendMessages);
|
Permissions.SetValue(ref allowValue, ref denyValue, sendMessages, ChannelPermission.SendMessages);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
Permissions.SetValue(ref allowValue, ref denyValue, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, manageMessages, ChannelPermission.ManageMessages);
|
Permissions.SetValue(ref allowValue, ref denyValue, manageMessages, ChannelPermission.ManageMessages);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, embedLinks, ChannelPermission.EmbedLinks);
|
Permissions.SetValue(ref allowValue, ref denyValue, embedLinks, ChannelPermission.EmbedLinks);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, attachFiles, ChannelPermission.AttachFiles);
|
Permissions.SetValue(ref allowValue, ref denyValue, attachFiles, ChannelPermission.AttachFiles);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, readMessageHistory, ChannelPermission.ReadMessageHistory);
|
Permissions.SetValue(ref allowValue, ref denyValue, readMessageHistory, ChannelPermission.ReadMessageHistory);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, mentionEveryone, ChannelPermission.MentionEveryone);
|
Permissions.SetValue(ref allowValue, ref denyValue, mentionEveryone, ChannelPermission.MentionEveryone);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, connect, ChannelPermission.Connect);
|
Permissions.SetValue(ref allowValue, ref denyValue, connect, ChannelPermission.Connect);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, speak, ChannelPermission.Speak);
|
Permissions.SetValue(ref allowValue, ref denyValue, speak, ChannelPermission.Speak);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, muteMembers, ChannelPermission.MuteMembers);
|
Permissions.SetValue(ref allowValue, ref denyValue, muteMembers, ChannelPermission.MuteMembers);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, deafenMembers, ChannelPermission.DeafenMembers);
|
Permissions.SetValue(ref allowValue, ref denyValue, deafenMembers, ChannelPermission.DeafenMembers);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, moveMembers, ChannelPermission.MoveMembers);
|
Permissions.SetValue(ref allowValue, ref denyValue, moveMembers, ChannelPermission.MoveMembers);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, useVoiceActivation, ChannelPermission.UseVAD);
|
Permissions.SetValue(ref allowValue, ref denyValue, useVoiceActivation, ChannelPermission.UseVAD);
|
||||||
PermissionUtilities.SetValue(ref allowValue, ref denyValue, managePermissions, ChannelPermission.ManagePermissions);
|
Permissions.SetValue(ref allowValue, ref denyValue, managePermissions, ChannelPermission.ManagePermissions);
|
||||||
|
|
||||||
AllowValue = allowValue;
|
AllowValue = allowValue;
|
||||||
DenyValue = denyValue;
|
DenyValue = denyValue;
|
||||||
@@ -115,8 +115,8 @@ namespace Discord
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var perms = new List<string>();
|
var perms = new List<string>();
|
||||||
int x = 1;
|
ulong x = 1;
|
||||||
for (byte i = 0; i < 32; i++, x <<= 1)
|
for (byte i = 0; i < Permissions.MaxBits; i++, x <<= 1)
|
||||||
{
|
{
|
||||||
if ((AllowValue & x) != 0)
|
if ((AllowValue & x) != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace Discord
|
|
||||||
{
|
|
||||||
internal static class PermissionUtilities
|
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static PermValue GetValue(uint allow, uint deny, ChannelPermission bit)
|
|
||||||
=> GetValue(allow, deny, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static PermValue GetValue(uint allow, uint deny, GuildPermission bit)
|
|
||||||
=> GetValue(allow, deny, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static PermValue GetValue(uint allow, uint deny, byte bit)
|
|
||||||
{
|
|
||||||
if (HasBit(allow, bit))
|
|
||||||
return PermValue.Allow;
|
|
||||||
else if (HasBit(deny, bit))
|
|
||||||
return PermValue.Deny;
|
|
||||||
else
|
|
||||||
return PermValue.Inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool GetValue(uint value, ChannelPermission bit)
|
|
||||||
=> GetValue(value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool GetValue(uint value, GuildPermission bit)
|
|
||||||
=> GetValue(value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool GetValue(uint value, byte bit) => HasBit(value, bit);
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint rawValue, bool? value, ChannelPermission bit)
|
|
||||||
=> SetValue(ref rawValue, value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint rawValue, bool? value, GuildPermission bit)
|
|
||||||
=> SetValue(ref rawValue, value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint rawValue, bool? value, byte bit)
|
|
||||||
{
|
|
||||||
if (value.HasValue)
|
|
||||||
{
|
|
||||||
if (value == true)
|
|
||||||
SetBit(ref rawValue, bit);
|
|
||||||
else
|
|
||||||
UnsetBit(ref rawValue, bit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint allow, ref uint deny, PermValue? value, ChannelPermission bit)
|
|
||||||
=> SetValue(ref allow, ref deny, value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint allow, ref uint deny, PermValue? value, GuildPermission bit)
|
|
||||||
=> SetValue(ref allow, ref deny, value, (byte)bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetValue(ref uint allow, ref uint deny, PermValue? value, byte bit)
|
|
||||||
{
|
|
||||||
if (value.HasValue)
|
|
||||||
{
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case PermValue.Allow:
|
|
||||||
SetBit(ref allow, bit);
|
|
||||||
UnsetBit(ref deny, bit);
|
|
||||||
break;
|
|
||||||
case PermValue.Deny:
|
|
||||||
UnsetBit(ref allow, bit);
|
|
||||||
SetBit(ref deny, bit);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
UnsetBit(ref allow, bit);
|
|
||||||
UnsetBit(ref deny, bit);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
private static bool HasBit(uint value, byte bit) => (value & (1U << bit)) != 0;
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void SetBit(ref uint value, byte bit) => value |= (1U << bit);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void UnsetBit(ref uint value, byte bit) => value &= ~(1U << bit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
152
src/Discord.Net/Common/Entities/Permissions/Permissions.cs
Normal file
152
src/Discord.Net/Common/Entities/Permissions/Permissions.cs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace Discord
|
||||||
|
{
|
||||||
|
internal static class Permissions
|
||||||
|
{
|
||||||
|
public const int MaxBits = 53;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static PermValue GetValue(ulong allow, ulong deny, ChannelPermission bit)
|
||||||
|
=> GetValue(allow, deny, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static PermValue GetValue(ulong allow, ulong deny, GuildPermission bit)
|
||||||
|
=> GetValue(allow, deny, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static PermValue GetValue(ulong allow, ulong deny, byte bit)
|
||||||
|
{
|
||||||
|
if (HasBit(allow, bit))
|
||||||
|
return PermValue.Allow;
|
||||||
|
else if (HasBit(deny, bit))
|
||||||
|
return PermValue.Deny;
|
||||||
|
else
|
||||||
|
return PermValue.Inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool GetValue(ulong value, ChannelPermission bit)
|
||||||
|
=> GetValue(value, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool GetValue(ulong value, GuildPermission bit)
|
||||||
|
=> GetValue(value, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool GetValue(ulong value, byte bit) => HasBit(value, bit);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void SetValue(ref ulong rawValue, bool? value, ChannelPermission bit)
|
||||||
|
=> SetValue(ref rawValue, value, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void SetValue(ref ulong rawValue, bool? value, GuildPermission bit)
|
||||||
|
=> SetValue(ref rawValue, value, (byte)bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void SetValue(ref ulong rawValue, bool? value, byte bit)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
if (value == true)
|
||||||
|
SetBit(ref rawValue, bit);
|
||||||
|
else
|
||||||
|
UnsetBit(ref rawValue, bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
[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);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void SetValue(ref ulong allow, ref ulong deny, PermValue? value, byte bit)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case PermValue.Allow:
|
||||||
|
SetBit(ref allow, bit);
|
||||||
|
UnsetBit(ref deny, bit);
|
||||||
|
break;
|
||||||
|
case PermValue.Deny:
|
||||||
|
UnsetBit(ref allow, bit);
|
||||||
|
SetBit(ref deny, bit);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UnsetBit(ref allow, bit);
|
||||||
|
UnsetBit(ref deny, bit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private static bool HasBit(ulong value, byte bit) => (value & (1U << bit)) != 0;
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void SetBit(ref ulong value, byte bit) => value |= (1U << bit);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void UnsetBit(ref ulong value, byte bit) => value &= ~(1U << bit);
|
||||||
|
|
||||||
|
public static ulong ResolveGuild(IGuildUser user)
|
||||||
|
{
|
||||||
|
var roles = user.Roles;
|
||||||
|
ulong newPermissions = 0;
|
||||||
|
for (int i = 0; i < roles.Count; i++)
|
||||||
|
newPermissions |= roles[i].Permissions.RawValue;
|
||||||
|
return newPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static ulong ResolveChannel(IGuildUser user, IGuildChannel channel)
|
||||||
|
{
|
||||||
|
return ResolveChannel(user, channel, ResolveGuild(user));
|
||||||
|
}*/
|
||||||
|
public static ulong ResolveChannel(IGuildUser user, IGuildChannel channel, ulong guildPermissions)
|
||||||
|
{
|
||||||
|
ulong resolvedPermissions = 0;
|
||||||
|
|
||||||
|
ulong mask = ChannelPermissions.All(channel).RawValue;
|
||||||
|
if (user.Id == user.Guild.OwnerId || GetValue(resolvedPermissions, GuildPermission.Administrator))
|
||||||
|
resolvedPermissions = mask; //Owners and administrators always have all permissions
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Start with this user's guild permissions
|
||||||
|
resolvedPermissions = guildPermissions;
|
||||||
|
var overwrites = channel.PermissionOverwrites;
|
||||||
|
|
||||||
|
Overwrite entry;
|
||||||
|
var roles = user.Roles;
|
||||||
|
if (roles.Count > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < roles.Count; i++)
|
||||||
|
{
|
||||||
|
if (overwrites.TryGetValue(roles[i].Id, out entry))
|
||||||
|
resolvedPermissions &= ~entry.Permissions.DenyValue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < roles.Count; i++)
|
||||||
|
{
|
||||||
|
if (overwrites.TryGetValue(roles[i].Id, out entry))
|
||||||
|
resolvedPermissions |= entry.Permissions.AllowValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (overwrites.TryGetValue(user.Id, out entry))
|
||||||
|
resolvedPermissions = (resolvedPermissions & ~entry.Permissions.DenyValue) | entry.Permissions.AllowValue;
|
||||||
|
|
||||||
|
switch (channel)
|
||||||
|
{
|
||||||
|
case ITextChannel _:
|
||||||
|
if (!GetValue(resolvedPermissions, ChannelPermission.ReadMessages))
|
||||||
|
resolvedPermissions = 0; //No read permission on a text channel removes all other permissions
|
||||||
|
break;
|
||||||
|
case IVoiceChannel _:
|
||||||
|
if (!GetValue(resolvedPermissions, ChannelPermission.Connect))
|
||||||
|
resolvedPermissions = 0; //No read permission on a text channel removes all other permissions
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
resolvedPermissions &= mask; //Ensure we didnt get any permissions this channel doesnt support (from guildPerms, for example)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolvedPermissions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
namespace Discord
|
|
||||||
{
|
|
||||||
public static class PermissionHelper
|
|
||||||
{
|
|
||||||
public static uint Resolve(IGuildUser user)
|
|
||||||
{
|
|
||||||
var roles = user.Roles;
|
|
||||||
uint newPermissions = 0;
|
|
||||||
for (int i = 0; i < roles.Count; i++)
|
|
||||||
newPermissions |= roles[i].Permissions.RawValue;
|
|
||||||
return newPermissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static uint Resolve(IGuildUser user, IGuildChannel channel)
|
|
||||||
{
|
|
||||||
uint resolvedPermissions = 0;
|
|
||||||
|
|
||||||
uint mask = ChannelPermissions.All(channel).RawValue;
|
|
||||||
if (user.Id == user.Guild.OwnerId || PermissionUtilities.GetValue(resolvedPermissions, GuildPermission.Administrator))
|
|
||||||
resolvedPermissions = mask; //Owners and administrators always have all permissions
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Start with this user's guild permissions
|
|
||||||
resolvedPermissions = Resolve(user);
|
|
||||||
var overwrites = channel.PermissionOverwrites;
|
|
||||||
|
|
||||||
Overwrite entry;
|
|
||||||
var roles = user.Roles;
|
|
||||||
if (roles.Count > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < roles.Count; i++)
|
|
||||||
{
|
|
||||||
if (overwrites.TryGetValue(roles[i].Id, out entry))
|
|
||||||
resolvedPermissions &= ~entry.Permissions.DenyValue;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < roles.Count; i++)
|
|
||||||
{
|
|
||||||
if (overwrites.TryGetValue(roles[i].Id, out entry))
|
|
||||||
resolvedPermissions |= entry.Permissions.AllowValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (overwrites.TryGetValue(user.Id, out entry))
|
|
||||||
resolvedPermissions = (resolvedPermissions & ~entry.Permissions.DenyValue) | entry.Permissions.AllowValue;
|
|
||||||
|
|
||||||
switch (channel)
|
|
||||||
{
|
|
||||||
case ITextChannel _:
|
|
||||||
if (!PermissionUtilities.GetValue(resolvedPermissions, ChannelPermission.ReadMessages))
|
|
||||||
resolvedPermissions = 0; //No read permission on a text channel removes all other permissions
|
|
||||||
break;
|
|
||||||
case IVoiceChannel _:
|
|
||||||
if (!PermissionUtilities.GetValue(resolvedPermissions, ChannelPermission.Connect))
|
|
||||||
resolvedPermissions = 0; //No read permission on a text channel removes all other permissions
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
resolvedPermissions &= mask; //Ensure we didnt get any permissions this channel doesnt support (from guildPerms, for example)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolvedPermissions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
public static class MentionHelper
|
public static class MentionUtils
|
||||||
{
|
{
|
||||||
private static readonly Regex _userRegex = new Regex(@"<@!?([0-9]+)>", RegexOptions.Compiled);
|
private static readonly Regex _userRegex = new Regex(@"<@!?([0-9]+)>", RegexOptions.Compiled);
|
||||||
private static readonly Regex _channelRegex = new Regex(@"<#([0-9]+)>", RegexOptions.Compiled);
|
private static readonly Regex _channelRegex = new Regex(@"<#([0-9]+)>", RegexOptions.Compiled);
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
<Compile Include="Common\Entities\Permissions\GuildPermissions.cs" />
|
<Compile Include="Common\Entities\Permissions\GuildPermissions.cs" />
|
||||||
<Compile Include="Common\Entities\Permissions\Overwrite.cs" />
|
<Compile Include="Common\Entities\Permissions\Overwrite.cs" />
|
||||||
<Compile Include="Common\Entities\Permissions\OverwritePermissions.cs" />
|
<Compile Include="Common\Entities\Permissions\OverwritePermissions.cs" />
|
||||||
<Compile Include="Common\Entities\Permissions\PermissionUtilities.cs" />
|
<Compile Include="Common\Entities\Permissions\Permissions.cs" />
|
||||||
<Compile Include="Common\Entities\Permissions\PermissionTarget.cs" />
|
<Compile Include="Common\Entities\Permissions\PermissionTarget.cs" />
|
||||||
<Compile Include="Common\Entities\Permissions\PermValue.cs" />
|
<Compile Include="Common\Entities\Permissions\PermValue.cs" />
|
||||||
<Compile Include="Common\Entities\Users\UserStatus.cs" />
|
<Compile Include="Common\Entities\Users\UserStatus.cs" />
|
||||||
@@ -166,7 +166,6 @@
|
|||||||
<Compile Include="Rest\Entities\Guilds\GuildIntegration.cs" />
|
<Compile Include="Rest\Entities\Guilds\GuildIntegration.cs" />
|
||||||
<Compile Include="Common\Entities\Guilds\IntegrationAccount.cs" />
|
<Compile Include="Common\Entities\Guilds\IntegrationAccount.cs" />
|
||||||
<Compile Include="Common\Entities\Users\Connection.cs" />
|
<Compile Include="Common\Entities\Users\Connection.cs" />
|
||||||
<Compile Include="Common\Helpers\PermissionHelper.cs" />
|
|
||||||
<Compile Include="Common\Entities\Invites\Invite.cs" />
|
<Compile Include="Common\Entities\Invites\Invite.cs" />
|
||||||
<Compile Include="Rest\Entities\Message.cs" />
|
<Compile Include="Rest\Entities\Message.cs" />
|
||||||
<Compile Include="Rest\Entities\Role.cs" />
|
<Compile Include="Rest\Entities\Role.cs" />
|
||||||
@@ -177,9 +176,9 @@
|
|||||||
<Compile Include="Common\Entities\Guilds\VoiceRegion.cs" />
|
<Compile Include="Common\Entities\Guilds\VoiceRegion.cs" />
|
||||||
<Compile Include="Common\Events\LogMessageEventArgs.cs" />
|
<Compile Include="Common\Events\LogMessageEventArgs.cs" />
|
||||||
<Compile Include="Common\Events\SentRequestEventArgs.cs" />
|
<Compile Include="Common\Events\SentRequestEventArgs.cs" />
|
||||||
<Compile Include="Common\Helpers\DateTimeHelper.cs" />
|
<Compile Include="Common\DateTimeUtils.cs" />
|
||||||
<Compile Include="Common\Helpers\EventExtensions.cs" />
|
<Compile Include="Common\EventExtensions.cs" />
|
||||||
<Compile Include="Common\Helpers\MentionHelper.cs" />
|
<Compile Include="Common\MentionUtils.cs" />
|
||||||
<Compile Include="IDiscordClient.cs" />
|
<Compile Include="IDiscordClient.cs" />
|
||||||
<Compile Include="Logging\ILogger.cs" />
|
<Compile Include="Logging\ILogger.cs" />
|
||||||
<Compile Include="Logging\Logger.cs" />
|
<Compile Include="Logging\Logger.cs" />
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Discord.Rest
|
|||||||
public DMUser Recipient { get; private set; }
|
public DMUser Recipient { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
|
|
||||||
internal DMChannel(DiscordClient discord, Model model)
|
internal DMChannel(DiscordClient discord, Model model)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Discord.Rest
|
|||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyDictionary<ulong, Overwrite> PermissionOverwrites => _overwrites;
|
public IReadOnlyDictionary<ulong, Overwrite> PermissionOverwrites => _overwrites;
|
||||||
internal DiscordClient Discord => Guild.Discord;
|
internal DiscordClient Discord => Guild.Discord;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Discord.Rest
|
|||||||
public string Topic { get; private set; }
|
public string Topic { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this);
|
public string Mention => MentionUtils.Mention(this);
|
||||||
|
|
||||||
internal TextChannel(Guild guild, Model model)
|
internal TextChannel(Guild guild, Model model)
|
||||||
: base(guild, model)
|
: base(guild, model)
|
||||||
@@ -40,14 +40,14 @@ namespace Discord.Rest
|
|||||||
public override async Task<GuildUser> GetUser(ulong id)
|
public override async Task<GuildUser> GetUser(ulong id)
|
||||||
{
|
{
|
||||||
var user = await Guild.GetUser(id).ConfigureAwait(false);
|
var user = await Guild.GetUser(id).ConfigureAwait(false);
|
||||||
if (user != null && PermissionUtilities.GetValue(PermissionHelper.Resolve(user, this), ChannelPermission.ReadMessages))
|
if (user != null && Permissions.GetValue(Permissions.ResolveChannel(user, this, user.GuildPermissions.RawValue), ChannelPermission.ReadMessages))
|
||||||
return user;
|
return user;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public override async Task<IEnumerable<GuildUser>> GetUsers()
|
public override async Task<IEnumerable<GuildUser>> GetUsers()
|
||||||
{
|
{
|
||||||
var users = await Guild.GetUsers().ConfigureAwait(false);
|
var users = await Guild.GetUsers().ConfigureAwait(false);
|
||||||
return users.Where(x => PermissionUtilities.GetValue(PermissionHelper.Resolve(x, this), ChannelPermission.ReadMessages));
|
return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Discord.Rest
|
|||||||
public IReadOnlyList<string> Features { get; private set; }
|
public IReadOnlyList<string> Features { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Discord
|
|||||||
public ulong? ChannelId { get; private set; }
|
public ulong? ChannelId { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
|
|
||||||
internal GuildEmbed(Model model)
|
internal GuildEmbed(Model model)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Discord
|
|||||||
public GuildPermissions Permissions { get; private set; }
|
public GuildPermissions Permissions { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Discord.Rest
|
|||||||
public IReadOnlyList<ulong> MentionedRoleIds { get; private set; }
|
public IReadOnlyList<ulong> MentionedRoleIds { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
internal DiscordClient Discord => (Channel as TextChannel)?.Discord ?? (Channel as DMChannel).Discord;
|
internal DiscordClient Discord => (Channel as TextChannel)?.Discord ?? (Channel as DMChannel).Discord;
|
||||||
|
|
||||||
internal Message(IMessageChannel channel, Model model)
|
internal Message(IMessageChannel channel, Model model)
|
||||||
@@ -88,8 +88,8 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
MentionedUsers = Array.Empty<PublicUser>();
|
MentionedUsers = Array.Empty<PublicUser>();
|
||||||
MentionedChannelIds = MentionHelper.GetChannelMentions(model.Content);
|
MentionedChannelIds = MentionUtils.GetChannelMentions(model.Content);
|
||||||
MentionedRoleIds = MentionHelper.GetRoleMentions(model.Content);
|
MentionedRoleIds = MentionUtils.GetRoleMentions(model.Content);
|
||||||
if (model.IsMentioningEveryone)
|
if (model.IsMentioningEveryone)
|
||||||
{
|
{
|
||||||
ulong? guildId = (Channel as IGuildChannel)?.Guild.Id;
|
ulong? guildId = (Channel as IGuildChannel)?.Guild.Id;
|
||||||
@@ -107,7 +107,7 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text = MentionHelper.CleanUserMentions(model.Content, model.Mentions);
|
Text = MentionUtils.CleanUserMentions(model.Content, model.Mentions);
|
||||||
|
|
||||||
Author.Update(model.Author);
|
Author.Update(model.Author);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ namespace Discord.Rest
|
|||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsEveryone => Id == Guild.Id;
|
public bool IsEveryone => Id == Guild.Id;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this);
|
public string Mention => MentionUtils.Mention(this);
|
||||||
internal DiscordClient Discord => Guild.Discord;
|
internal DiscordClient Discord => Guild.Discord;
|
||||||
|
|
||||||
internal Role(Guild guild, Model model)
|
internal Role(Guild guild, Model model)
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Nickname { get; private set; }
|
public string Nickname { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public GuildPermissions GuildPermissions { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyList<Role> Roles => _roles;
|
public IReadOnlyList<Role> Roles => _roles;
|
||||||
internal override DiscordClient Discord => Guild.Discord;
|
internal override DiscordClient Discord => Guild.Discord;
|
||||||
@@ -44,6 +47,8 @@ namespace Discord.Rest
|
|||||||
for (int i = 0; i < model.Roles.Length; i++)
|
for (int i = 0; i < model.Roles.Length; i++)
|
||||||
roles.Add(Guild.GetRole(model.Roles[i]));
|
roles.Add(Guild.GetRole(model.Roles[i]));
|
||||||
_roles = roles.ToImmutable();
|
_roles = roles.ToImmutable();
|
||||||
|
|
||||||
|
GuildPermissions = new GuildPermissions(Permissions.ResolveGuild(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update()
|
public async Task Update()
|
||||||
@@ -67,14 +72,10 @@ namespace Discord.Rest
|
|||||||
await Discord.BaseClient.RemoveGuildMember(Guild.Id, Id).ConfigureAwait(false);
|
await Discord.BaseClient.RemoveGuildMember(Guild.Id, Id).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuildPermissions GetGuildPermissions()
|
|
||||||
{
|
|
||||||
return new GuildPermissions(PermissionHelper.Resolve(this));
|
|
||||||
}
|
|
||||||
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
||||||
{
|
{
|
||||||
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
||||||
return new ChannelPermissions(PermissionHelper.Resolve(this, channel));
|
return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Modify(Action<ModifyGuildMemberParams> func)
|
public async Task Modify(Action<ModifyGuildMemberParams> func)
|
||||||
@@ -111,6 +112,8 @@ namespace Discord.Rest
|
|||||||
IReadOnlyList<IRole> IGuildUser.Roles => Roles;
|
IReadOnlyList<IRole> IGuildUser.Roles => Roles;
|
||||||
IVoiceChannel IGuildUser.VoiceChannel => null;
|
IVoiceChannel IGuildUser.VoiceChannel => null;
|
||||||
|
|
||||||
|
GuildPermissions IGuildUser.GetGuildPermissions()
|
||||||
|
=> GuildPermissions;
|
||||||
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel)
|
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel)
|
||||||
=> GetPermissions(channel);
|
=> GetPermissions(channel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId);
|
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this, false);
|
public string Mention => MentionUtils.Mention(this, false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string NicknameMention => MentionHelper.Mention(this, true);
|
public string NicknameMention => MentionUtils.Mention(this, true);
|
||||||
|
|
||||||
internal User(Model model)
|
internal User(Model model)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
public void Add(GuildUser user)
|
public void Add(GuildUser user)
|
||||||
{
|
{
|
||||||
_users[user.Id] = new ChannelMember(user, new ChannelPermissions(PermissionHelper.Resolve(user, _channel)));
|
_users[user.Id] = new ChannelMember(user, new ChannelPermissions(Permissions.ResolveChannel(user, _channel, user.GuildPermissions.RawValue)));
|
||||||
}
|
}
|
||||||
public void Remove(GuildUser user)
|
public void Remove(GuildUser user)
|
||||||
{
|
{
|
||||||
@@ -52,7 +52,7 @@ namespace Discord.WebSocket
|
|||||||
foreach (var pair in _users)
|
foreach (var pair in _users)
|
||||||
{
|
{
|
||||||
var member = pair.Value;
|
var member = pair.Value;
|
||||||
var newPerms = PermissionHelper.Resolve(member.User, _channel);
|
var newPerms = Permissions.ResolveChannel(member.User, _channel, member.User.GuildPermissions.RawValue);
|
||||||
if (newPerms != member.Permissions.RawValue)
|
if (newPerms != member.Permissions.RawValue)
|
||||||
_users[pair.Key] = new ChannelMember(member.User, new ChannelPermissions(newPerms));
|
_users[pair.Key] = new ChannelMember(member.User, new ChannelPermissions(newPerms));
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ namespace Discord.WebSocket
|
|||||||
ChannelMember member;
|
ChannelMember member;
|
||||||
if (_users.TryGetValue(user.Id, out member))
|
if (_users.TryGetValue(user.Id, out member))
|
||||||
{
|
{
|
||||||
var newPerms = PermissionHelper.Resolve(user, _channel);
|
var newPerms = Permissions.ResolveChannel(user, _channel, user.GuildPermissions.RawValue);
|
||||||
if (newPerms != member.Permissions.RawValue)
|
if (newPerms != member.Permissions.RawValue)
|
||||||
_users[user.Id] = new ChannelMember(user, new ChannelPermissions(newPerms));
|
_users[user.Id] = new ChannelMember(user, new ChannelPermissions(newPerms));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Discord.WebSocket
|
|||||||
public DMUser Recipient { get; private set; }
|
public DMUser Recipient { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<IUser> Users => ImmutableArray.Create<IUser>(Discord.CurrentUser, Recipient);
|
public IEnumerable<IUser> Users => ImmutableArray.Create<IUser>(Discord.CurrentUser, Recipient);
|
||||||
public IEnumerable<Message> CachedMessages => _messages.Messages;
|
public IEnumerable<Message> CachedMessages => _messages.Messages;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Discord.WebSocket
|
|||||||
public abstract IEnumerable<GuildUser> Users { get; }
|
public abstract IEnumerable<GuildUser> Users { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyDictionary<ulong, Overwrite> PermissionOverwrites => _overwrites;
|
public IReadOnlyDictionary<ulong, Overwrite> PermissionOverwrites => _overwrites;
|
||||||
internal DiscordClient Discord => Guild.Discord;
|
internal DiscordClient Discord => Guild.Discord;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Discord.WebSocket
|
|||||||
public string Topic { get; private set; }
|
public string Topic { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this);
|
public string Mention => MentionUtils.Mention(this);
|
||||||
public override IEnumerable<GuildUser> Users
|
public override IEnumerable<GuildUser> Users
|
||||||
=> _permissions.Members.Where(x => x.Permissions.ReadMessages).Select(x => x.User).ToImmutableArray();
|
=> _permissions.Members.Where(x => x.Permissions.ReadMessages).Select(x => x.User).ToImmutableArray();
|
||||||
public IEnumerable<Message> CachedMessages => _messages.Messages;
|
public IEnumerable<Message> CachedMessages => _messages.Messages;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Discord.WebSocket
|
|||||||
public IReadOnlyList<string> Features { get; private set; }
|
public IReadOnlyList<string> Features { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Discord.WebSocket
|
|||||||
public IReadOnlyList<ulong> MentionedRoleIds { get; private set; }
|
public IReadOnlyList<ulong> MentionedRoleIds { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
internal DiscordClient Discord => (Channel as TextChannel)?.Discord ?? (Channel as DMChannel).Discord;
|
internal DiscordClient Discord => (Channel as TextChannel)?.Discord ?? (Channel as DMChannel).Discord;
|
||||||
|
|
||||||
internal Message(IMessageChannel channel, Model model)
|
internal Message(IMessageChannel channel, Model model)
|
||||||
@@ -88,8 +88,8 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
MentionedUsers = Array.Empty<PublicUser>();
|
MentionedUsers = Array.Empty<PublicUser>();
|
||||||
MentionedChannelIds = MentionHelper.GetChannelMentions(model.Content);
|
MentionedChannelIds = MentionUtils.GetChannelMentions(model.Content);
|
||||||
MentionedRoleIds = MentionHelper.GetRoleMentions(model.Content);
|
MentionedRoleIds = MentionUtils.GetRoleMentions(model.Content);
|
||||||
if (model.IsMentioningEveryone)
|
if (model.IsMentioningEveryone)
|
||||||
{
|
{
|
||||||
ulong? guildId = (Channel as IGuildChannel)?.Guild.Id;
|
ulong? guildId = (Channel as IGuildChannel)?.Guild.Id;
|
||||||
@@ -107,7 +107,7 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text = MentionHelper.CleanUserMentions(model.Content, model.Mentions);
|
Text = MentionUtils.CleanUserMentions(model.Content, model.Mentions);
|
||||||
|
|
||||||
Author.Update(model.Author);
|
Author.Update(model.Author);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ namespace Discord.WebSocket
|
|||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsEveryone => Id == Guild.Id;
|
public bool IsEveryone => Id == Guild.Id;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this);
|
public string Mention => MentionUtils.Mention(this);
|
||||||
internal DiscordClient Discord => Guild.Discord;
|
internal DiscordClient Discord => Guild.Discord;
|
||||||
|
|
||||||
internal Role(Guild guild, Model model)
|
internal Role(Guild guild, Model model)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace Discord.WebSocket
|
|||||||
public string Nickname { get; private set; }
|
public string Nickname { get; private set; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public VoiceChannel VoiceChannel { get; private set; }
|
public VoiceChannel VoiceChannel { get; private set; }
|
||||||
|
public GuildPermissions GuildPermissions { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyList<Role> Roles => _roles;
|
public IReadOnlyList<Role> Roles => _roles;
|
||||||
@@ -46,6 +47,12 @@ namespace Discord.WebSocket
|
|||||||
for (int i = 0; i < model.Roles.Length; i++)
|
for (int i = 0; i < model.Roles.Length; i++)
|
||||||
roles.Add(Guild.GetRole(model.Roles[i]));
|
roles.Add(Guild.GetRole(model.Roles[i]));
|
||||||
_roles = roles.ToImmutable();
|
_roles = roles.ToImmutable();
|
||||||
|
|
||||||
|
UpdateGuildPermissions();
|
||||||
|
}
|
||||||
|
internal void UpdateGuildPermissions()
|
||||||
|
{
|
||||||
|
GuildPermissions = new GuildPermissions(Permissions.ResolveGuild(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasRole(IRole role)
|
public bool HasRole(IRole role)
|
||||||
@@ -65,12 +72,12 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
public GuildPermissions GetGuildPermissions()
|
public GuildPermissions GetGuildPermissions()
|
||||||
{
|
{
|
||||||
return new GuildPermissions(PermissionHelper.Resolve(this));
|
return new GuildPermissions(Permissions.ResolveGuild(this));
|
||||||
}
|
}
|
||||||
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
||||||
{
|
{
|
||||||
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
||||||
return new ChannelPermissions(PermissionHelper.Resolve(this, channel));
|
return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Modify(Action<ModifyGuildMemberParams> func)
|
public async Task Modify(Action<ModifyGuildMemberParams> func)
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId);
|
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
|
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Mention => MentionHelper.Mention(this, false);
|
public string Mention => MentionUtils.Mention(this, false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string NicknameMention => MentionHelper.Mention(this, true);
|
public string NicknameMention => MentionUtils.Mention(this, true);
|
||||||
|
|
||||||
internal User(Model model)
|
internal User(Model model)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user