Browse Source

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
pull/874/head
Chris Johnston Chris Johnston 7 years ago
parent
commit
0a5e68d62d
7 changed files with 24 additions and 14 deletions
  1. +3
    -1
      src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs
  2. +7
    -3
      src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
  3. +8
    -4
      src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs
  4. +1
    -1
      src/Discord.Net.Core/Utils/Permissions.cs
  5. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  6. +1
    -1
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  7. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

+ 3
- 1
src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs View File

@@ -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,


+ 7
- 3
src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs View File

@@ -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);


+ 8
- 4
src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs View File

@@ -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);


+ 1
- 1
src/Discord.Net.Core/Utils/Permissions.cs View File

@@ -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;


+ 2
- 2
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -234,7 +234,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;
@@ -255,7 +255,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) =>


+ 1
- 1
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -192,7 +192,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();
}


+ 2
- 2
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -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;


Loading…
Cancel
Save