Skip to content

Commit

Permalink
feature: Add missing channel properties (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
SubZero0 authored Aug 1, 2020
1 parent 42ba372 commit 2d80037
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace Discord
{
/// <summary>
Expand Down Expand Up @@ -30,5 +32,9 @@ public class GuildChannelProperties
/// is set.
/// </remarks>
public Optional<ulong?> CategoryId { get; set; }
/// <summary>
/// Gets or sets the permission overwrites for this channel.
/// </summary>
public Optional<IEnumerable<Overwrite>> PermissionOverwrites { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ internal class CreateGuildChannelParams
public Optional<ulong?> CategoryId { get; set; }
[JsonProperty("position")]
public Optional<int> Position { get; set; }
[JsonProperty("permission_overwrites")]
public Optional<Overwrite[]> Overwrites { get; set; }

//Text channels
[JsonProperty("topic")]
public Optional<string> Topic { get; set; }
[JsonProperty("nsfw")]
public Optional<bool> IsNsfw { get; set; }
[JsonProperty("rate_limit_per_user")]
public Optional<int> SlowModeInterval { get; set; }

//Voice channels
[JsonProperty("bitrate")]
Expand Down
12 changes: 11 additions & 1 deletion src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordCli
Topic = args.Topic,
IsNsfw = args.IsNsfw,
SlowModeInterval = args.SlowModeInterval,
Overwrites = args.PermissionOverwrites.IsSpecified
? args.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
{
TargetId = overwrite.TargetId,
TargetType = overwrite.TargetType,
Allow = overwrite.Permissions.AllowValue,
Deny = overwrite.Permissions.DenyValue
}).ToArray()
: Optional.Create<API.Overwrite[]>(),
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}
Expand Down Expand Up @@ -413,7 +422,8 @@ public static async Task SyncPermissionsAsync(INestedChannel channel, BaseDiscor
var apiArgs = new ModifyGuildChannelParams
{
Overwrites = category.PermissionOverwrites
.Select(overwrite => new API.Overwrite{
.Select(overwrite => new API.Overwrite
{
TargetId = overwrite.TargetId,
TargetType = overwrite.TargetType,
Allow = overwrite.Permissions.AllowValue,
Expand Down
34 changes: 31 additions & 3 deletions src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,17 @@ public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, B
CategoryId = props.CategoryId,
Topic = props.Topic,
IsNsfw = props.IsNsfw,
Position = props.Position
Position = props.Position,
SlowModeInterval = props.SlowModeInterval,
Overwrites = props.PermissionOverwrites.IsSpecified
? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
{
TargetId = overwrite.TargetId,
TargetType = overwrite.TargetType,
Allow = overwrite.Permissions.AllowValue,
Deny = overwrite.Permissions.DenyValue
}).ToArray()
: Optional.Create<API.Overwrite[]>(),
};
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestTextChannel.Create(client, guild, model);
Expand All @@ -195,7 +205,16 @@ public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild,
CategoryId = props.CategoryId,
Bitrate = props.Bitrate,
UserLimit = props.UserLimit,
Position = props.Position
Position = props.Position,
Overwrites = props.PermissionOverwrites.IsSpecified
? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
{
TargetId = overwrite.TargetId,
TargetType = overwrite.TargetType,
Allow = overwrite.Permissions.AllowValue,
Deny = overwrite.Permissions.DenyValue
}).ToArray()
: Optional.Create<API.Overwrite[]>(),
};
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestVoiceChannel.Create(client, guild, model);
Expand All @@ -211,7 +230,16 @@ public static async Task<RestCategoryChannel> CreateCategoryChannelAsync(IGuild

var args = new CreateGuildChannelParams(name, ChannelType.Category)
{
Position = props.Position
Position = props.Position,
Overwrites = props.PermissionOverwrites.IsSpecified
? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
{
TargetId = overwrite.TargetId,
TargetType = overwrite.TargetType,
Allow = overwrite.Permissions.AllowValue,
Deny = overwrite.Permissions.DenyValue
}).ToArray()
: Optional.Create<API.Overwrite[]>(),
};

var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
Expand Down

0 comments on commit 2d80037

Please sign in to comment.