@@ -12,5 +12,10 @@ namespace Discord | |||||
ulong? CategoryId { get; } | ulong? CategoryId { get; } | ||||
/// <summary> Gets the parent channel (category) of this channel, if it is set. If unset, returns null.</summary> | /// <summary> Gets the parent channel (category) of this channel, if it is set. If unset, returns null.</summary> | ||||
Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
/// <summary> | |||||
/// Syncs the permissions of this nested channel with its parent's. | |||||
/// </summary> | |||||
Task SyncPermissionsAsync(RequestOptions options = null); | |||||
} | } | ||||
} | } |
@@ -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; | |||||
} | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
@@ -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; } | |||||
} | } | ||||
} | } |
@@ -326,6 +326,20 @@ namespace Discord.Rest | |||||
var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); | var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); | ||||
return RestCategoryChannel.Create(client, model) as ICategoryChannel; | return RestCategoryChannel.Create(client, model) as ICategoryChannel; | ||||
} | } | ||||
public static async Task SyncPermissionsAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) | |||||
{ | |||||
var category = await GetCategoryAsync(channel, client, options).ConfigureAwait(false); | |||||
if (category == null) return; | |||||
var apiArgs = new ModifyGuildChannelParams | |||||
{ | |||||
Overwrites = category.PermissionOverwrites | |||||
.Select(overwrite => new API.Overwrite(overwrite.TargetId, overwrite.TargetType, | |||||
overwrite.Permissions.AllowValue, overwrite.Permissions.DenyValue)) | |||||
.ToArray() | |||||
}; | |||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | |||||
} | |||||
//Helpers | //Helpers | ||||
private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) | private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) | ||||
@@ -92,6 +92,8 @@ namespace Discord.Rest | |||||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | => ChannelHelper.GetCategoryAsync(this, Discord, options); | ||||
public Task SyncPermissionsAsync(RequestOptions options = null) | |||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | ||||
@@ -41,6 +41,8 @@ namespace Discord.Rest | |||||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | => ChannelHelper.GetCategoryAsync(this, Discord, options); | ||||
public Task SyncPermissionsAsync(RequestOptions options = null) | |||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | ||||
@@ -19,6 +19,8 @@ namespace Discord.WebSocket | |||||
public ulong? CategoryId { get; private set; } | public ulong? CategoryId { get; private set; } | ||||
public ICategoryChannel Category | public ICategoryChannel Category | ||||
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; | => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; | ||||
public Task SyncPermissionsAsync(RequestOptions options = null) | |||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | |||||
private bool _nsfw; | private bool _nsfw; | ||||
public bool IsNsfw => _nsfw; | public bool IsNsfw => _nsfw; | ||||
@@ -18,6 +18,8 @@ namespace Discord.WebSocket | |||||
public ulong? CategoryId { get; private set; } | public ulong? CategoryId { get; private set; } | ||||
public ICategoryChannel Category | public ICategoryChannel Category | ||||
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; | => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; | ||||
public Task SyncPermissionsAsync(RequestOptions options = null) | |||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | |||||
public override IReadOnlyCollection<SocketGuildUser> Users | public override IReadOnlyCollection<SocketGuildUser> Users | ||||
=> Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); | => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); | ||||