* Fix #854 Added ViewChannel enum and property to channel permissions * replaced usages of ChannelPermission#ReadMessages with ViewChannel * rename parameter of ChannelPermissions constructor * made OverwritePermissions#ReadMessages obsolete, use ViewChannel instead * Fix #854 Added ViewChannel enum and property to channel permissions replaced usages of ChannelPermission#ReadMessages with ViewChannel rename parameter of ChannelPermissions constructor made OverwritePermissions#ReadMessages obsolete, use ViewChannel instead * renamed readMessages parameter in ChannelPermissions constructor and Modify * fixed channel permission tests to use ChannelPermission enum instead of GuildPermission enum * replaced usages of readmessages in channel permission tests * resolve build warnings for permission tests
This commit is contained in:
committed by
Christopher F
parent
804d9188e7
commit
edfbd055bb
@@ -11,7 +11,9 @@ namespace Discord
|
||||
|
||||
// Text
|
||||
AddReactions = 0x00_00_00_40,
|
||||
ReadMessages = 0x00_00_04_00,
|
||||
[Obsolete("Use ViewChannel instead.")]
|
||||
ReadMessages = ViewChannel,
|
||||
ViewChannel = 0x00_00_04_00,
|
||||
SendMessages = 0x00_00_08_00,
|
||||
SendTTSMessages = 0x00_00_10_00,
|
||||
ManageMessages = 0x00_00_20_00,
|
||||
|
||||
@@ -41,7 +41,11 @@ namespace Discord
|
||||
/// <summary> If true, a user may add reactions. </summary>
|
||||
public bool AddReactions => Permissions.GetValue(RawValue, ChannelPermission.AddReactions);
|
||||
/// <summary> If True, a user may join channels. </summary>
|
||||
public bool ReadMessages => Permissions.GetValue(RawValue, ChannelPermission.ReadMessages);
|
||||
[Obsolete("Use ViewChannel instead.")]
|
||||
public bool ReadMessages => ViewChannel;
|
||||
/// <summary> If True, a user may view channels. </summary>
|
||||
public bool ViewChannel => Permissions.GetValue(RawValue, ChannelPermission.ViewChannel);
|
||||
|
||||
/// <summary> If True, a user may send messages. </summary>
|
||||
public bool SendMessages => Permissions.GetValue(RawValue, ChannelPermission.SendMessages);
|
||||
/// <summary> If True, a user may send text-to-speech messages. </summary>
|
||||
@@ -82,7 +86,7 @@ namespace Discord
|
||||
|
||||
private ChannelPermissions(ulong initialValue, bool? createInstantInvite = null, bool? manageChannel = null,
|
||||
bool? addReactions = null,
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? viewChannel = 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? manageRoles = null, bool? manageWebhooks = null)
|
||||
@@ -92,7 +96,7 @@ namespace Discord
|
||||
Permissions.SetValue(ref value, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||
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, viewChannel, ChannelPermission.ViewChannel);
|
||||
Permissions.SetValue(ref value, sendMessages, ChannelPermission.SendMessages);
|
||||
Permissions.SetValue(ref value, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
||||
Permissions.SetValue(ref value, manageMessages, ChannelPermission.ManageMessages);
|
||||
@@ -116,11 +120,11 @@ namespace Discord
|
||||
/// <summary> Creates a new ChannelPermissions with the provided permissions. </summary>
|
||||
public ChannelPermissions(bool createInstantInvite = false, bool manageChannel = false,
|
||||
bool addReactions = false,
|
||||
bool readMessages = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false,
|
||||
bool viewChannel = 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 manageRoles = false, bool manageWebhooks = false)
|
||||
: this(0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
: this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks)
|
||||
{ }
|
||||
@@ -128,11 +132,11 @@ namespace Discord
|
||||
/// <summary> Creates a new ChannelPermissions from this one, changing the provided non-null permissions. </summary>
|
||||
public ChannelPermissions Modify(bool? createInstantInvite = null, bool? manageChannel = null,
|
||||
bool? addReactions = null,
|
||||
bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null,
|
||||
bool? viewChannel = 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? manageRoles = null, bool? manageWebhooks = null)
|
||||
=> new ChannelPermissions(RawValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
|
||||
=> new ChannelPermissions(RawValue, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages,
|
||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
|
||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Discord
|
||||
@@ -27,7 +28,10 @@ namespace Discord
|
||||
/// <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>
|
||||
public PermValue ReadMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ReadMessages);
|
||||
[Obsolete("Use ViewChannel instead.")]
|
||||
public PermValue ReadMessages => ViewChannel;
|
||||
/// <summary> If Allowed, a user may join channels. </summary>
|
||||
public PermValue ViewChannel => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ViewChannel);
|
||||
/// <summary> If Allowed, a user may send messages. </summary>
|
||||
public PermValue SendMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.SendMessages);
|
||||
/// <summary> If Allowed, a user may send text-to-speech messages. </summary>
|
||||
@@ -72,7 +76,7 @@ namespace Discord
|
||||
|
||||
private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null,
|
||||
PermValue? addReactions = null,
|
||||
PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null,
|
||||
PermValue? viewChannel = 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? manageRoles = null,
|
||||
@@ -81,7 +85,7 @@ namespace Discord
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite);
|
||||
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, viewChannel, ChannelPermission.ViewChannel);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, sendMessages, ChannelPermission.SendMessages);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, sendTTSMessages, ChannelPermission.SendTTSMessages);
|
||||
Permissions.SetValue(ref allowValue, ref denyValue, manageMessages, ChannelPermission.ManageMessages);
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace Discord
|
||||
|
||||
if (channel is ITextChannel textChannel)
|
||||
{
|
||||
if (!GetValue(resolvedPermissions, ChannelPermission.ReadMessages))
|
||||
if (!GetValue(resolvedPermissions, ChannelPermission.ViewChannel))
|
||||
{
|
||||
//No read permission on a text channel removes all other permissions
|
||||
resolvedPermissions = 0;
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace Discord.Rest
|
||||
if (model == null)
|
||||
return null;
|
||||
var user = RestGuildUser.Create(client, guild, model);
|
||||
if (!user.GetPermissions(channel).ReadMessages)
|
||||
if (!user.GetPermissions(channel).ViewChannel)
|
||||
return null;
|
||||
|
||||
return user;
|
||||
@@ -265,7 +265,7 @@ namespace Discord.Rest
|
||||
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return models
|
||||
.Select(x => RestGuildUser.Create(client, guild, x))
|
||||
.Where(x => x.GetPermissions(channel).ReadMessages)
|
||||
.Where(x => x.GetPermissions(channel).ViewChannel)
|
||||
.ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace Discord.Rest
|
||||
var channels = await GetTextChannelsAsync(options).ConfigureAwait(false);
|
||||
var user = await GetCurrentUserAsync(options).ConfigureAwait(false);
|
||||
return channels
|
||||
.Where(c => user.GetPermissions(c).ReadMessages)
|
||||
.Where(c => user.GetPermissions(c).ViewChannel)
|
||||
.OrderBy(c => c.Position)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Discord.WebSocket
|
||||
public override IReadOnlyCollection<SocketGuildUser> Users
|
||||
=> Guild.Users.Where(x => Permissions.GetValue(
|
||||
Permissions.ResolveChannel(Guild, x, this, Permissions.ResolveGuild(Guild, x)),
|
||||
ChannelPermission.ReadMessages)).ToImmutableArray();
|
||||
ChannelPermission.ViewChannel)).ToImmutableArray();
|
||||
|
||||
internal SocketTextChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
|
||||
: base(discord, id, guild)
|
||||
@@ -107,7 +107,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var guildPerms = Permissions.ResolveGuild(Guild, user);
|
||||
var channelPerms = Permissions.ResolveChannel(Guild, user, this, guildPerms);
|
||||
if (Permissions.GetValue(channelPerms, ChannelPermission.ReadMessages))
|
||||
if (Permissions.GetValue(channelPerms, ChannelPermission.ViewChannel))
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user