diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
index 3d11e2c6f..0c8ae3b58 100644
--- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
@@ -20,17 +20,6 @@ namespace Discord
///
int Position { get; }
- ///
- /// Gets the parent ID (category) of this channel in the guild's channel list.
- ///
- ///
- /// The parent category ID associated with this channel, or null if none is set.
- ///
- ulong? CategoryId { get; }
- ///
- /// Gets the parent channel (category) of this channel.
- ///
- Task GetCategoryAsync();
///
/// Gets the guild associated with this channel.
///
diff --git a/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs b/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs
new file mode 100644
index 000000000..c8d2bcaaf
--- /dev/null
+++ b/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs
@@ -0,0 +1,16 @@
+using System.Threading.Tasks;
+
+namespace Discord
+{
+ ///
+ /// A type of guild channel that can be nested within a category.
+ /// Contains a CategoryId that is set to the parent category, if it is set.
+ ///
+ public interface INestedChannel : IGuildChannel
+ {
+ /// Gets the parentid (category) of this channel in the guild's channel list.
+ ulong? CategoryId { get; }
+ /// Gets the parent channel (category) of this channel, if it is set. If unset, returns null.
+ Task GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
+ }
+}
diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
index 29c67bf6b..92f5b140a 100644
--- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
@@ -8,7 +8,7 @@ namespace Discord
///
/// Represents a generic channel in a guild that can send and receive messages.
///
- public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel
+ public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel
{
///
/// Determines whether the channel is NSFW.
diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs
index 4dc3a6086..3119a5ae7 100644
--- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs
@@ -6,7 +6,7 @@ namespace Discord
///
/// Represents a generic voice channel in a guild.
///
- public interface IVoiceChannel : IGuildChannel, IAudioChannel
+ public interface IVoiceChannel : INestedChannel, IAudioChannel
{
///
/// Gets the bitrate, in bits per second, clients in this voice channel are requested to use.
diff --git a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
index 758bc5758..753be6d51 100644
--- a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
+++ b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
@@ -88,12 +88,27 @@ namespace Discord
/// Creates a new with the provided packed value.
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
- private ChannelPermissions(ulong initialValue, bool? createInstantInvite = null, bool? manageChannel = null,
+ private ChannelPermissions(ulong initialValue,
+ bool? createInstantInvite = null,
+ bool? manageChannel = null,
bool? addReactions = 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)
+ 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)
{
ulong value = initialValue;
@@ -122,27 +137,75 @@ namespace Discord
}
/// Creates a new with the provided permissions.
- public ChannelPermissions(bool createInstantInvite = false, bool manageChannel = false,
+ public ChannelPermissions(
+ bool createInstantInvite = false,
+ bool manageChannel = false,
bool addReactions = 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)
+ 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, viewChannel, sendMessages, sendTTSMessages, manageMessages,
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks)
{ }
/// Creates a new from this one, changing the provided non-null permissions.
- public ChannelPermissions Modify(bool? createInstantInvite = null, bool? manageChannel = null,
+ public ChannelPermissions Modify(
+ bool? createInstantInvite = null,
+ bool? manageChannel = null,
bool? addReactions = 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, viewChannel, sendMessages, sendTTSMessages, manageMessages,
- embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
- speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks);
+ 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)
+ => new ChannelPermissions(RawValue,
+ createInstantInvite,
+ manageChannel,
+ addReactions,
+ viewChannel,
+ sendMessages,
+ sendTTSMessages,
+ manageMessages,
+ embedLinks,
+ attachFiles,
+ readMessageHistory,
+ mentionEveryone,
+ useExternalEmojis,
+ connect,
+ speak,
+ muteMembers,
+ deafenMembers,
+ moveMembers,
+ useVoiceActivation,
+ manageRoles,
+ manageWebhooks);
public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission);
diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs
index c77883832..9ad7d34b4 100644
--- a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs
+++ b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs
@@ -84,14 +84,35 @@ namespace Discord
/// Creates a new with the provided packed value.
public GuildPermissions(ulong rawValue) { RawValue = rawValue; }
- private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null,
- bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null,
- bool? addReactions = null, bool? viewAuditLog = 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? changeNickname = null, bool? manageNicknames = null,
- bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null)
+ private GuildPermissions(ulong initialValue,
+ bool? createInstantInvite = null,
+ bool? kickMembers = null,
+ bool? banMembers = null,
+ bool? administrator = null,
+ bool? manageChannels = null,
+ bool? manageGuild = null,
+ bool? addReactions = null,
+ bool? viewAuditLog = 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? changeNickname = null,
+ bool? manageNicknames = null,
+ bool? manageRoles = null,
+ bool? manageWebhooks = null,
+ bool? manageEmojis = null)
{
ulong value = initialValue;
@@ -128,32 +149,96 @@ namespace Discord
}
/// Creates a new with the provided permissions.
- public GuildPermissions(bool createInstantInvite = false, bool kickMembers = false,
- bool banMembers = false, bool administrator = false, bool manageChannels = false, bool manageGuild = false,
- bool addReactions = false, bool viewAuditLog = 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? changeNickname = false, bool? manageNicknames = false,
- bool manageRoles = false, bool manageWebhooks = false, bool manageEmojis = false)
- : this(0, createInstantInvite: createInstantInvite, manageRoles: manageRoles, kickMembers: kickMembers, banMembers: banMembers,
- administrator: administrator, manageChannels: manageChannels, manageGuild: manageGuild, addReactions: addReactions,
- viewAuditLog: viewAuditLog, viewChannel: viewChannel, sendMessages: sendMessages, sendTTSMessages: sendTTSMessages,
- manageMessages: manageMessages, embedLinks: embedLinks, attachFiles: attachFiles, readMessageHistory: readMessageHistory,
- mentionEveryone: mentionEveryone, useExternalEmojis: useExternalEmojis, connect: connect, speak: speak, muteMembers: muteMembers,
- deafenMembers: deafenMembers, moveMembers: moveMembers, useVoiceActivation: useVoiceActivation, changeNickname: changeNickname,
- manageNicknames: manageNicknames, manageWebhooks: manageWebhooks, manageEmojis: manageEmojis)
+ public GuildPermissions(
+ bool createInstantInvite = false,
+ bool kickMembers = false,
+ bool banMembers = false,
+ bool administrator = false,
+ bool manageChannels = false,
+ bool manageGuild = false,
+ bool addReactions = false,
+ bool viewAuditLog = 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 changeNickname = false,
+ bool manageNicknames = false,
+ bool manageRoles = false,
+ bool manageWebhooks = false,
+ bool manageEmojis = false)
+ : this(0,
+ createInstantInvite: createInstantInvite,
+ manageRoles: manageRoles,
+ kickMembers: kickMembers,
+ banMembers: banMembers,
+ administrator: administrator,
+ manageChannels: manageChannels,
+ manageGuild: manageGuild,
+ addReactions: addReactions,
+ viewAuditLog: viewAuditLog,
+ viewChannel: viewChannel,
+ sendMessages: sendMessages,
+ sendTTSMessages: sendTTSMessages,
+ manageMessages: manageMessages,
+ embedLinks: embedLinks,
+ attachFiles: attachFiles,
+ readMessageHistory: readMessageHistory,
+ mentionEveryone: mentionEveryone,
+ useExternalEmojis: useExternalEmojis,
+ connect: connect,
+ speak: speak,
+ muteMembers: muteMembers,
+ deafenMembers: deafenMembers,
+ moveMembers: moveMembers,
+ useVoiceActivation: useVoiceActivation,
+ changeNickname: changeNickname,
+ manageNicknames: manageNicknames,
+ manageWebhooks: manageWebhooks,
+ manageEmojis: manageEmojis)
{ }
/// Creates a new from this one, changing the provided non-null permissions.
- public GuildPermissions Modify(bool? createInstantInvite = null, bool? kickMembers = null,
- bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null,
- bool? addReactions = null, bool? viewAuditLog = 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? changeNickname = null, bool? manageNicknames = null,
- bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null)
+ public GuildPermissions Modify(
+ bool? createInstantInvite = null,
+ bool? kickMembers = null,
+ bool? banMembers = null,
+ bool? administrator = null,
+ bool? manageChannels = null,
+ bool? manageGuild = null,
+ bool? addReactions = null,
+ bool? viewAuditLog = 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? changeNickname = null,
+ bool? manageNicknames = null,
+ bool? manageRoles = null,
+ bool? manageWebhooks = null,
+ bool? manageEmojis = null)
=> new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions,
viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles,
readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers,
diff --git a/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs b/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs
index bcc34b98a..57c42b316 100644
--- a/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs
+++ b/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs
@@ -84,12 +84,26 @@ namespace Discord
DenyValue = denyValue;
}
- private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null,
+ private OverwritePermissions(ulong allowValue, ulong denyValue,
+ PermValue? createInstantInvite = null,
+ PermValue? manageChannel = null,
PermValue? addReactions = 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,
+ 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,
PermValue? manageWebhooks = null)
{
Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite);
@@ -120,12 +134,27 @@ namespace Discord
///
/// Creates a new with the provided permissions.
///
- public OverwritePermissions(PermValue createInstantInvite = PermValue.Inherit, PermValue manageChannel = PermValue.Inherit,
+ public OverwritePermissions(
+ PermValue createInstantInvite = PermValue.Inherit,
+ PermValue manageChannel = PermValue.Inherit,
PermValue addReactions = PermValue.Inherit,
- PermValue readMessages = PermValue.Inherit, PermValue sendMessages = PermValue.Inherit, PermValue sendTTSMessages = PermValue.Inherit, PermValue manageMessages = PermValue.Inherit,
- PermValue embedLinks = PermValue.Inherit, PermValue attachFiles = PermValue.Inherit, PermValue readMessageHistory = PermValue.Inherit, PermValue mentionEveryone = PermValue.Inherit,
- PermValue useExternalEmojis = PermValue.Inherit, PermValue connect = PermValue.Inherit, PermValue speak = PermValue.Inherit, PermValue muteMembers = PermValue.Inherit, PermValue deafenMembers = PermValue.Inherit,
- PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue manageRoles = PermValue.Inherit, PermValue manageWebhooks = PermValue.Inherit)
+ PermValue readMessages = PermValue.Inherit,
+ PermValue sendMessages = PermValue.Inherit,
+ PermValue sendTTSMessages = PermValue.Inherit,
+ PermValue manageMessages = PermValue.Inherit,
+ PermValue embedLinks = PermValue.Inherit,
+ PermValue attachFiles = PermValue.Inherit,
+ PermValue readMessageHistory = PermValue.Inherit,
+ PermValue mentionEveryone = PermValue.Inherit,
+ PermValue useExternalEmojis = PermValue.Inherit,
+ PermValue connect = PermValue.Inherit,
+ PermValue speak = PermValue.Inherit,
+ PermValue muteMembers = PermValue.Inherit,
+ PermValue deafenMembers = PermValue.Inherit,
+ PermValue moveMembers = PermValue.Inherit,
+ PermValue useVoiceActivation = PermValue.Inherit,
+ PermValue manageRoles = PermValue.Inherit,
+ PermValue manageWebhooks = PermValue.Inherit)
: this(0, 0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
moveMembers, useVoiceActivation, manageRoles, manageWebhooks) { }
@@ -134,12 +163,27 @@ namespace Discord
/// Creates a new from this one, changing the provided non-null
/// permissions.
///
- public OverwritePermissions Modify(PermValue? createInstantInvite = null, PermValue? manageChannel = null,
+ public OverwritePermissions Modify(
+ PermValue? createInstantInvite = null,
+ PermValue? manageChannel = null,
PermValue? addReactions = 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? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null,
- PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, PermValue? manageWebhooks = 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? useExternalEmojis = null,
+ PermValue? connect = null,
+ PermValue? speak = null,
+ PermValue? muteMembers = null,
+ PermValue? deafenMembers = null,
+ PermValue? moveMembers = null,
+ PermValue? useVoiceActivation = null,
+ PermValue? manageRoles = null,
+ PermValue? manageWebhooks = null)
=> new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages,
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
moveMembers, useVoiceActivation, manageRoles, manageWebhooks);
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs
index 8e990f7c7..7cad9eff7 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs
@@ -48,7 +48,7 @@ namespace Discord.Rest
/// An representing the snowflake identifier for the updated channel.
///
public ulong ChannelId { get; }
- public ChannelInfo Before { get; set; }
- public ChannelInfo After { get; set; }
+ public ChannelInfo Before { get; }
+ public ChannelInfo After { get; }
}
}
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs
index e06c013ed..0d9a2a708 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs
@@ -8,7 +8,7 @@ namespace Discord.Rest
{
public class MemberRoleAuditLogData : IAuditLogData
{
- private MemberRoleAuditLogData(IReadOnlyCollection roles, IUser target)
+ private MemberRoleAuditLogData(IReadOnlyCollection roles, IUser target)
{
Roles = roles;
Target = target;
@@ -20,7 +20,7 @@ namespace Discord.Rest
var roleInfos = changes.SelectMany(x => x.NewValue.ToObject(),
(model, role) => new { model.ChangedProperty, Role = role })
- .Select(x => new RoleInfo(x.Role.Name, x.Role.Id, x.ChangedProperty == "$add"))
+ .Select(x => new MemberRoleEditInfo(x.Role.Name, x.Role.Id, x.ChangedProperty == "$add"))
.ToList();
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
@@ -29,21 +29,7 @@ namespace Discord.Rest
return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user);
}
- public IReadOnlyCollection Roles { get; }
+ public IReadOnlyCollection Roles { get; }
public IUser Target { get; }
-
- public struct RoleInfo
- {
- internal RoleInfo(string name, ulong roleId, bool added)
- {
- Name = name;
- RoleId = roleId;
- Added = added;
- }
-
- public string Name { get; }
- public ulong RoleId { get; }
- public bool Added { get; }
- }
}
}
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleEditInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleEditInfo.cs
new file mode 100644
index 000000000..4838b75c9
--- /dev/null
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleEditInfo.cs
@@ -0,0 +1,16 @@
+namespace Discord.Rest
+{
+ public struct MemberRoleEditInfo
+ {
+ internal MemberRoleEditInfo(string name, ulong roleId, bool added)
+ {
+ Name = name;
+ RoleId = roleId;
+ Added = added;
+ }
+
+ public string Name { get; }
+ public ulong RoleId { get; }
+ public bool Added { get; }
+ }
+}
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleCreateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleCreateAuditLogData.cs
index aa951d6e7..dcc1c6ab6 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleCreateAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleCreateAuditLogData.cs
@@ -7,7 +7,7 @@ namespace Discord.Rest
{
public class RoleCreateAuditLogData : IAuditLogData
{
- private RoleCreateAuditLogData(ulong id, RoleInfo props)
+ private RoleCreateAuditLogData(ulong id, RoleEditInfo props)
{
RoleId = id;
Properties = props;
@@ -38,10 +38,10 @@ namespace Discord.Rest
permissions = new GuildPermissions(permissionsRaw.Value);
return new RoleCreateAuditLogData(entry.TargetId.Value,
- new RoleInfo(color, mentionable, hoist, name, permissions));
+ new RoleEditInfo(color, mentionable, hoist, name, permissions));
}
public ulong RoleId { get; }
- public RoleInfo Properties { get; }
+ public RoleEditInfo Properties { get; }
}
}
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleDeleteAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleDeleteAuditLogData.cs
index e90d70d4d..263909daf 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleDeleteAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleDeleteAuditLogData.cs
@@ -7,7 +7,7 @@ namespace Discord.Rest
{
public class RoleDeleteAuditLogData : IAuditLogData
{
- private RoleDeleteAuditLogData(ulong id, RoleInfo props)
+ private RoleDeleteAuditLogData(ulong id, RoleEditInfo props)
{
RoleId = id;
Properties = props;
@@ -38,10 +38,10 @@ namespace Discord.Rest
permissions = new GuildPermissions(permissionsRaw.Value);
return new RoleDeleteAuditLogData(entry.TargetId.Value,
- new RoleInfo(color, mentionable, hoist, name, permissions));
+ new RoleEditInfo(color, mentionable, hoist, name, permissions));
}
public ulong RoleId { get; }
- public RoleInfo Properties { get; }
+ public RoleEditInfo Properties { get; }
}
}
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleEditInfo.cs
similarity index 79%
rename from src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleInfo.cs
rename to src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleEditInfo.cs
index a5c83c5eb..186ea8d11 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleInfo.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleEditInfo.cs
@@ -1,8 +1,8 @@
namespace Discord.Rest
{
- public struct RoleInfo
+ public struct RoleEditInfo
{
- internal RoleInfo(Color? color, bool? mentionable, bool? hoist, string name,
+ internal RoleEditInfo(Color? color, bool? mentionable, bool? hoist, string name,
GuildPermissions? permissions)
{
Color = color;
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleUpdateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleUpdateAuditLogData.cs
index be484e2d5..b645ef7ae 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleUpdateAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/RoleUpdateAuditLogData.cs
@@ -7,7 +7,7 @@ namespace Discord.Rest
{
public class RoleUpdateAuditLogData : IAuditLogData
{
- private RoleUpdateAuditLogData(ulong id, RoleInfo oldProps, RoleInfo newProps)
+ private RoleUpdateAuditLogData(ulong id, RoleEditInfo oldProps, RoleEditInfo newProps)
{
RoleId = id;
Before = oldProps;
@@ -49,14 +49,14 @@ namespace Discord.Rest
if (newPermissionsRaw.HasValue)
newPermissions = new GuildPermissions(newPermissionsRaw.Value);
- var oldProps = new RoleInfo(oldColor, oldMentionable, oldHoist, oldName, oldPermissions);
- var newProps = new RoleInfo(newColor, newMentionable, newHoist, newName, newPermissions);
+ var oldProps = new RoleEditInfo(oldColor, oldMentionable, oldHoist, oldName, oldPermissions);
+ var newProps = new RoleEditInfo(newColor, newMentionable, newHoist, newName, newPermissions);
return new RoleUpdateAuditLogData(entry.TargetId.Value, oldProps, newProps);
}
public ulong RoleId { get; }
- public RoleInfo Before { get; }
- public RoleInfo After { get; }
+ public RoleEditInfo Before { get; }
+ public RoleEditInfo After { get; }
}
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
index 62764a05d..b8089824d 100644
--- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
@@ -337,6 +337,16 @@ namespace Discord.Rest
return models.Select(x => RestWebhook.Create(client, channel, x))
.ToImmutableArray();
}
+ // Categories
+ public static async Task GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options)
+ {
+ // if no category id specified, return null
+ if (!channel.CategoryId.HasValue)
+ return null;
+ // CategoryId will contain a value here
+ var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false);
+ return RestCategoryChannel.Create(client, model) as ICategoryChannel;
+ }
//Helpers
private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId)
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs
index eb3fdd94b..9d69d6bdc 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs
@@ -28,14 +28,6 @@ namespace Discord.Rest
// IGuildChannel
///
/// This method is not supported with category channels.
- IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
- => throw new NotSupportedException();
- ///
- /// This method is not supported with category channels.
- Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
- => throw new NotSupportedException();
- ///
- /// This method is not supported with category channels.
Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
=> throw new NotSupportedException();
///
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
index 09c2e75a1..dd190199f 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
@@ -29,6 +29,8 @@ namespace Discord.Rest
case ChannelType.DM:
case ChannelType.Group:
return CreatePrivate(discord, model) as RestChannel;
+ case ChannelType.Category:
+ return RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model);
default:
return new RestChannel(discord, model.Id);
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
index f0ff4d4c4..cc52a9864 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
@@ -23,8 +23,6 @@ namespace Discord.Rest
///
public int Position { get; private set; }
///
- public ulong? CategoryId { get; private set; }
- ///
public ulong GuildId => Guild.Id;
internal RestGuildChannel(BaseDiscordClient discord, IGuild guild, ulong id)
@@ -43,7 +41,6 @@ namespace Discord.Rest
case ChannelType.Category:
return RestCategoryChannel.Create(discord, guild, model);
default:
- // TODO: Channel categories
return new RestGuildChannel(discord, guild, model.Id);
}
}
@@ -75,14 +72,6 @@ namespace Discord.Rest
public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);
- ///
- public async Task GetCategoryAsync()
- {
- if (CategoryId.HasValue)
- return (await Guild.GetChannelAsync(CategoryId.Value).ConfigureAwait(false)) as ICategoryChannel;
- return null;
- }
-
public OverwritePermissions? GetPermissionOverwrite(IUser user)
{
for (int i = 0; i < _overwrites.Length; i++)
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
index f93757c31..5321cc36c 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
@@ -16,6 +16,7 @@ namespace Discord.Rest
{
///
public string Topic { get; private set; }
+ public ulong? CategoryId { get; private set; }
///
public string Mention => MentionUtils.MentionChannel(Id);
@@ -37,7 +38,7 @@ namespace Discord.Rest
internal override void Update(Model model)
{
base.Update(model);
-
+ CategoryId = model.CategoryId;
Topic = model.Topic.Value;
_nsfw = model.Nsfw.GetValueOrDefault();
}
@@ -134,6 +135,9 @@ namespace Discord.Rest
=> ChannelHelper.GetWebhookAsync(this, Discord, id, options);
public Task> GetWebhooksAsync(RequestOptions options = null)
=> ChannelHelper.GetWebhooksAsync(this, Discord, options);
+
+ public Task GetCategoryAsync(RequestOptions options = null)
+ => ChannelHelper.GetCategoryAsync(this, Discord, options);
private string DebuggerDisplay => $"{Name} ({Id}, Text)";
@@ -165,6 +169,7 @@ namespace Discord.Rest
else
return AsyncEnumerable.Empty>();
}
+
///
IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
@@ -234,5 +239,13 @@ namespace Discord.Rest
else
return AsyncEnumerable.Empty>();
}
+
+ // INestedChannel
+ async Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
+ {
+ if (CategoryId.HasValue && mode == CacheMode.AllowDownload)
+ return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel;
+ return null;
+ }
}
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
index 2af6c6768..07da22235 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
@@ -18,6 +18,7 @@ namespace Discord.Rest
public int Bitrate { get; private set; }
///
public int? UserLimit { get; private set; }
+ public ulong? CategoryId { get; private set; }
internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id)
: base(discord, guild, id)
@@ -33,7 +34,7 @@ namespace Discord.Rest
internal override void Update(Model model)
{
base.Update(model);
-
+ CategoryId = model.CategoryId;
Bitrate = model.Bitrate.Value;
UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
}
@@ -45,6 +46,9 @@ namespace Discord.Rest
Update(model);
}
+ public Task GetCategoryAsync(RequestOptions options = null)
+ => ChannelHelper.GetCategoryAsync(this, Discord, options);
+
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
//IAudioChannel
@@ -59,5 +63,13 @@ namespace Discord.Rest
///
IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty>();
+
+ // INestedChannel
+ async Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
+ {
+ if (CategoryId.HasValue && mode == CacheMode.AllowDownload)
+ return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel;
+ return null;
+ }
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs
index 37e6afef1..4c224e09a 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs
@@ -21,7 +21,7 @@ namespace Discord.WebSocket
ChannelPermission.ViewChannel)).ToImmutableArray();
public IReadOnlyCollection Channels
- => Guild.Channels.Where(x => x.CategoryId == Id).ToImmutableArray();
+ => Guild.Channels.Where(x => x is INestedChannel nestedChannel && nestedChannel.CategoryId == Id).ToImmutableArray();
internal SocketCategoryChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
: base(discord, id, guild)
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
index 1151f0141..075b2866c 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
@@ -27,17 +27,7 @@ namespace Discord.WebSocket
///
public string Name { get; private set; }
///
- public int Position { get; private set; }
- ///
- public ulong? CategoryId { get; private set; }
- ///
- /// Gets the parent category of this channel.
- ///
- ///
- /// A parent category ID associated with this channel, or null if none is set.
- ///
- public ICategoryChannel Category
- => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
+ public int Position { get; private set; }
///
public IReadOnlyCollection PermissionOverwrites => _overwrites;
@@ -73,8 +63,7 @@ namespace Discord.WebSocket
{
Name = model.Name.Value;
Position = model.Position.Value;
- CategoryId = model.CategoryId;
-
+
var overwrites = model.PermissionOverwrites.Value;
var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length);
for (int i = 0; i < overwrites.Length; i++)
@@ -168,10 +157,6 @@ namespace Discord.WebSocket
///
ulong IGuildChannel.GuildId => Guild.Id;
- ///
- Task IGuildChannel.GetCategoryAsync()
- => Task.FromResult(Category);
-
///
async Task> IGuildChannel.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options).ConfigureAwait(false);
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
index c06d093e8..c34cee754 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
@@ -20,6 +20,9 @@ namespace Discord.WebSocket
///
public string Topic { get; private set; }
+ public ulong? CategoryId { get; private set; }
+ public ICategoryChannel Category
+ => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
private bool _nsfw;
///
@@ -50,7 +53,7 @@ namespace Discord.WebSocket
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);
-
+ CategoryId = model.CategoryId;
Topic = model.Topic.Value;
_nsfw = model.Nsfw.GetValueOrDefault();
}
@@ -226,5 +229,9 @@ namespace Discord.WebSocket
///
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);
+
+ // INestedChannel
+ Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
+ => Task.FromResult(Category);
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
index 568c5ad7b..ee932e0cd 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
@@ -20,6 +20,9 @@ namespace Discord.WebSocket
public int Bitrate { get; private set; }
///
public int? UserLimit { get; private set; }
+ public ulong? CategoryId { get; private set; }
+ public ICategoryChannel Category
+ => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
///
public override IReadOnlyCollection Users
@@ -38,7 +41,7 @@ namespace Discord.WebSocket
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);
-
+ CategoryId = model.CategoryId;
Bitrate = model.Bitrate.Value;
UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
}
@@ -61,7 +64,7 @@ namespace Discord.WebSocket
return user;
return null;
}
-
+
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel;
@@ -72,5 +75,9 @@ namespace Discord.WebSocket
///
IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create>(Users).ToAsyncEnumerable();
+
+ // INestedChannel
+ Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
+ => Task.FromResult(Category);
}
}
diff --git a/test/Discord.Net.Tests/Tests.ChannelPermissions.cs b/test/Discord.Net.Tests/Tests.ChannelPermissions.cs
index da969b320..51834e30d 100644
--- a/test/Discord.Net.Tests/Tests.ChannelPermissions.cs
+++ b/test/Discord.Net.Tests/Tests.ChannelPermissions.cs
@@ -22,6 +22,27 @@ namespace Discord
var copy = perm.Modify();
Assert.Equal((ulong)0, copy.RawValue);
+ // test modify with no parameters after using all
+ copy = ChannelPermissions.Text;
+ var modified = copy.Modify(); // no params should not change the result
+ Assert.Equal(ChannelPermissions.Text.RawValue, modified.RawValue);
+
+ copy = ChannelPermissions.Voice;
+ modified = copy.Modify(); // no params should not change the result
+ Assert.Equal(ChannelPermissions.Voice.RawValue, modified.RawValue);
+
+ copy = ChannelPermissions.Group;
+ modified = copy.Modify(); // no params should not change the result
+ Assert.Equal(ChannelPermissions.Group.RawValue, modified.RawValue);
+
+ copy = ChannelPermissions.DM;
+ modified = copy.Modify(); // no params should not change the result
+ Assert.Equal(ChannelPermissions.DM.RawValue, modified.RawValue);
+
+ copy = new ChannelPermissions(useExternalEmojis: true);
+ modified = copy.Modify();
+ Assert.Equal(copy.RawValue, modified.RawValue);
+
// test the values that are returned by ChannelPermission.All
Assert.Equal((ulong)0, ChannelPermissions.None.RawValue);
diff --git a/test/Discord.Net.Tests/Tests.Channels.cs b/test/Discord.Net.Tests/Tests.Channels.cs
index cd629faa4..2c189c03f 100644
--- a/test/Discord.Net.Tests/Tests.Channels.cs
+++ b/test/Discord.Net.Tests/Tests.Channels.cs
@@ -1,4 +1,5 @@
using Discord.Rest;
+using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
@@ -15,17 +16,28 @@ namespace Discord
var text4 = await guild.CreateTextChannelAsync("text4");
var text5 = await guild.CreateTextChannelAsync("text5");
+ // create a channel category
+ var cat1 = await guild.CreateCategoryChannelAsync("cat1");
+
+ if (text1 == null)
+ {
+ // the guild did not have a default channel, so make a new one
+ text1 = await guild.CreateTextChannelAsync("default");
+ }
+
//Modify #general
await text1.ModifyAsync(x =>
{
x.Name = "text1";
x.Position = 1;
x.Topic = "Topic1";
+ x.CategoryId = cat1.Id;
});
await text2.ModifyAsync(x =>
{
x.Position = 2;
+ x.CategoryId = cat1.Id;
});
await text3.ModifyAsync(x =>
{
@@ -89,10 +101,13 @@ namespace Discord
var voice2 = await guild.CreateVoiceChannelAsync("voice2");
var voice3 = await guild.CreateVoiceChannelAsync("voice3");
+ var cat2 = await guild.CreateCategoryChannelAsync("cat2");
+
await voice1.ModifyAsync(x =>
{
x.Bitrate = 96000;
x.Position = 1;
+ x.CategoryId = cat2.Id;
});
await voice2.ModifyAsync(x =>
{
@@ -103,6 +118,7 @@ namespace Discord
x.Bitrate = 8000;
x.Position = 1;
x.UserLimit = 16;
+ x.CategoryId = cat2.Id;
});
CheckVoiceChannels(voice1, voice2, voice3);
@@ -140,5 +156,63 @@ namespace Discord
Assert.Equal(1, voice3.Position);
Assert.Equal(16, voice3.UserLimit);
}
+
+ [Fact]
+ public async Task TestChannelCategories()
+ {
+ // (await _guild.GetVoiceChannelsAsync()).ToArray()
+ var channels = await _guild.GetCategoryChannelsAsync();
+
+ await CheckChannelCategories(channels.ToArray(), (await _guild.GetChannelsAsync()).ToArray());
+ }
+
+ private async Task CheckChannelCategories(RestCategoryChannel[] categories, RestGuildChannel[] allChannels)
+ {
+ // 2 categories
+ Assert.Equal(categories.Length, 2);
+
+ var cat1 = categories.Where(x => x.Name == "cat1").FirstOrDefault();
+ var cat2 = categories.Where(x => x.Name == "cat2").FirstOrDefault();
+
+ Assert.NotNull(cat1);
+ Assert.NotNull(cat2);
+
+ // get text1, text2, ensure they have category id == cat1
+ var text1 = allChannels.Where(x => x.Name == "text1").FirstOrDefault() as RestTextChannel;
+ var text2 = allChannels.Where(x => x.Name == "text2").FirstOrDefault() as RestTextChannel;
+
+ Assert.NotNull(text1);
+ Assert.NotNull(text2);
+
+ // check that CategoryID and .GetCategoryAsync work correctly
+ // for both of the text channels
+ Assert.Equal(text1.CategoryId, cat1.Id);
+ var text1Cat = await text1.GetCategoryAsync();
+ Assert.Equal(text1Cat.Id, cat1.Id);
+ Assert.Equal(text1Cat.Name, cat1.Name);
+
+ Assert.Equal(text2.CategoryId, cat1.Id);
+ var text2Cat = await text2.GetCategoryAsync();
+ Assert.Equal(text2Cat.Id, cat1.Id);
+ Assert.Equal(text2Cat.Name, cat1.Name);
+
+ // do the same for the voice channels
+ var voice1 = allChannels.Where(x => x.Name == "voice1").FirstOrDefault() as RestVoiceChannel;
+ var voice3 = allChannels.Where(x => x.Name == "voice3").FirstOrDefault() as RestVoiceChannel;
+
+ Assert.NotNull(voice1);
+ Assert.NotNull(voice3);
+
+ Assert.Equal(voice1.CategoryId, cat2.Id);
+ var voice1Cat = await voice1.GetCategoryAsync();
+ Assert.Equal(voice1Cat.Id, cat2.Id);
+ Assert.Equal(voice1Cat.Name, cat2.Name);
+
+ Assert.Equal(voice3.CategoryId, cat2.Id);
+ var voice3Cat = await voice3.GetCategoryAsync();
+ Assert.Equal(voice3Cat.Id, cat2.Id);
+ Assert.Equal(voice3Cat.Name, cat2.Name);
+
+ }
}
}
diff --git a/test/Discord.Net.Tests/Tests.GuildPermissions.cs b/test/Discord.Net.Tests/Tests.GuildPermissions.cs
index 2b7c39341..defaf4d02 100644
--- a/test/Discord.Net.Tests/Tests.GuildPermissions.cs
+++ b/test/Discord.Net.Tests/Tests.GuildPermissions.cs
@@ -26,6 +26,18 @@ namespace Discord
// ensure that the raw values match
Assert.Equal((ulong)0, copy.RawValue);
+ // test modify with no parameters
+ copy = GuildPermissions.None.Modify();
+ Assert.Equal(GuildPermissions.None.RawValue, copy.RawValue);
+
+ // test modify with no paramters on all permissions
+ copy = GuildPermissions.All.Modify();
+ Assert.Equal(GuildPermissions.All.RawValue, copy.RawValue);
+
+ // test modify with no paramters on webhook permissions
+ copy = GuildPermissions.Webhook.Modify();
+ Assert.Equal(GuildPermissions.Webhook.RawValue, copy.RawValue);
+
// test GuildPermissions.All
ulong sumOfAllGuildPermissions = 0;
foreach(var v in Enum.GetValues(typeof(GuildPermission)))
diff --git a/test/Discord.Net.Tests/Tests.Permissions.cs b/test/Discord.Net.Tests/Tests.Permissions.cs
index 0516337da..5a7b5a16b 100644
--- a/test/Discord.Net.Tests/Tests.Permissions.cs
+++ b/test/Discord.Net.Tests/Tests.Permissions.cs
@@ -702,5 +702,71 @@ namespace Discord
return Task.CompletedTask;
}
+
+ ///
+ /// Tests for the
+ /// method to ensure that the default no-param call does not modify the resulting value
+ /// of the OverwritePermissions.
+ ///
+ ///
+ public Task TestOverwritePermissionModifyNoParam()
+ {
+ // test for all Text allowed, none denied
+ var original = new OverwritePermissions(ChannelPermissions.Text.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, text denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.Text.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // category allowed, none denied
+ original = new OverwritePermissions(ChannelPermissions.Category.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, category denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.Category.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // DM allowed, none denied
+ original = new OverwritePermissions(ChannelPermissions.DM.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, DM denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.DM.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // voice allowed, none denied
+ original = new OverwritePermissions(ChannelPermissions.Voice.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, voice denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.Voice.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // group allowed, none denied
+ original = new OverwritePermissions(ChannelPermissions.Group.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, group denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.Group.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ // none allowed, none denied
+ original = new OverwritePermissions(ChannelPermissions.None.RawValue, ChannelPermissions.None.RawValue);
+ Assert.Equal(original.AllowValue, original.Modify().AllowValue);
+ Assert.Equal(original.DenyValue, original.Modify().DenyValue);
+
+ return Task.CompletedTask;
+ }
}
}