| @@ -1,4 +1,4 @@ | |||||
| namespace Discord | |||||
| namespace Discord | |||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// Modify an IGuildChannel with the specified changes. | /// Modify an IGuildChannel with the specified changes. | ||||
| @@ -30,5 +30,9 @@ | |||||
| /// Sets the category for this channel | /// Sets the category for this channel | ||||
| /// </summary> | /// </summary> | ||||
| public Optional<ulong?> CategoryId { get; set; } | public Optional<ulong?> CategoryId { get; set; } | ||||
| /// <summary> | |||||
| /// Syncs the permission with the channel's parent (category). | |||||
| /// </summary> | |||||
| public Optional<bool> SyncWithParent { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| #pragma warning disable CS1591 | |||||
| #pragma warning disable CS1591 | |||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
| namespace Discord.API | namespace Discord.API | ||||
| @@ -13,5 +13,13 @@ namespace Discord.API | |||||
| public ulong Deny { get; set; } | public ulong Deny { get; set; } | ||||
| [JsonProperty("allow"), Int53] | [JsonProperty("allow"), Int53] | ||||
| public ulong Allow { get; set; } | public ulong Allow { get; set; } | ||||
| public Overwrite(ulong targetId, PermissionTarget targetType, ulong allowValue, ulong denyValue) | |||||
| { | |||||
| TargetId = targetId; | |||||
| TargetType = targetType; | |||||
| Allow = allowValue; | |||||
| Deny = denyValue; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -12,5 +12,7 @@ namespace Discord.API.Rest | |||||
| public Optional<int> Position { get; set; } | public Optional<int> Position { get; set; } | ||||
| [JsonProperty("parent_id")] | [JsonProperty("parent_id")] | ||||
| public Optional<ulong?> CategoryId { get; set; } | public Optional<ulong?> CategoryId { get; set; } | ||||
| [JsonProperty("permission_overwrites")] | |||||
| public Optional<Overwrite[]> Overwrites { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,17 +19,25 @@ namespace Discord.Rest | |||||
| { | { | ||||
| await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); | await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client, | public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client, | ||||
| Action<GuildChannelProperties> func, | Action<GuildChannelProperties> func, | ||||
| IEnumerable<Overwrite> overwrites, | |||||
| RequestOptions options) | RequestOptions options) | ||||
| { | { | ||||
| var args = new GuildChannelProperties(); | var args = new GuildChannelProperties(); | ||||
| func(args); | func(args); | ||||
| var apiArgs = new API.Rest.ModifyGuildChannelParams | |||||
| var apiArgs = new ModifyGuildChannelParams | |||||
| { | { | ||||
| Name = args.Name, | Name = args.Name, | ||||
| Position = args.Position, | Position = args.Position, | ||||
| CategoryId = args.CategoryId | |||||
| CategoryId = args.CategoryId, | |||||
| Overwrites = args.SyncWithParent.Value | |||||
| ? overwrites | |||||
| .Select(overwrite => new API.Overwrite(overwrite.TargetId, overwrite.TargetType, | |||||
| overwrite.Permissions.AllowValue, overwrite.Permissions.DenyValue)) | |||||
| .ToArray() | |||||
| : null | |||||
| }; | }; | ||||
| return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| using System; | |||||
| using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| using System.Linq; | using System.Linq; | ||||
| @@ -58,7 +58,8 @@ namespace Discord.Rest | |||||
| } | } | ||||
| public async Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) | public async Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) | ||||
| { | { | ||||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); | |||||
| var categoryChannel = await GetCategoryAsync().ConfigureAwait(false); | |||||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, categoryChannel.PermissionOverwrites, options).ConfigureAwait(false); | |||||
| Update(model); | Update(model); | ||||
| } | } | ||||
| public Task DeleteAsync(RequestOptions options = null) | public Task DeleteAsync(RequestOptions options = null) | ||||
| @@ -1,4 +1,4 @@ | |||||
| using Discord.Rest; | |||||
| using Discord.Rest; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| @@ -58,7 +58,7 @@ namespace Discord.WebSocket | |||||
| } | } | ||||
| public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) | public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) | ||||
| => ChannelHelper.ModifyAsync(this, Discord, func, options); | |||||
| => ChannelHelper.ModifyAsync(this, Discord, func, Category.PermissionOverwrites, options); | |||||
| public Task DeleteAsync(RequestOptions options = null) | public Task DeleteAsync(RequestOptions options = null) | ||||
| => ChannelHelper.DeleteAsync(this, Discord, options); | => ChannelHelper.DeleteAsync(this, Discord, options); | ||||