@@ -0,0 +1,29 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | |||||
{ | |||||
class CreateChannelPermissionsParams | |||||
{ | |||||
[JsonProperty("id")] | |||||
public ulong Id { get; set; } | |||||
[JsonProperty("type")] | |||||
public string Type { get; } | |||||
[JsonProperty("allow")] | |||||
public ulong Allow { get; } | |||||
[JsonProperty("deny")] | |||||
public ulong Deny { get; } | |||||
public CreateChannelPermissionsParams(ulong id, string type, ulong allow, ulong deny) | |||||
{ | |||||
Id = id; | |||||
Type = type; | |||||
Allow = allow; | |||||
Deny = deny; | |||||
} | |||||
} | |||||
} |
@@ -1,5 +1,6 @@ | |||||
#pragma warning disable CS1591 | #pragma warning disable CS1591 | ||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System.Collections.Generic; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -14,6 +15,8 @@ namespace Discord.API.Rest | |||||
public Optional<ulong?> CategoryId { get; set; } | public Optional<ulong?> CategoryId { get; set; } | ||||
[JsonProperty("position")] | [JsonProperty("position")] | ||||
public Optional<int> Position { get; set; } | public Optional<int> Position { get; set; } | ||||
[JsonProperty("permission_overwrite")] | |||||
public Optional<IEnumerable<CreateChannelPermissionsParams>> PermissionOverwrite {get;set;} | |||||
//Text channels | //Text channels | ||||
[JsonProperty("topic")] | [JsonProperty("topic")] | ||||
@@ -164,54 +164,63 @@ namespace Discord.Rest | |||||
} | } | ||||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||||
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | ||||
string name, RequestOptions options, Action<TextChannelProperties> func = null) | |||||
string name, RequestOptions options, Action<TextChannelProperties> func = null, IEnumerable<Overwrite> overwrites = null) | |||||
{ | { | ||||
if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | ||||
var props = new TextChannelProperties(); | var props = new TextChannelProperties(); | ||||
func?.Invoke(props); | func?.Invoke(props); | ||||
var perms = overwrites?.Select(perm => new CreateChannelPermissionsParams(perm.TargetId, perm.TargetType == PermissionTarget.Role ? "role" : "member", perm.Permissions.AllowValue, perm.Permissions.DenyValue)); | |||||
var args = new CreateGuildChannelParams(name, ChannelType.Text) | var args = new CreateGuildChannelParams(name, ChannelType.Text) | ||||
{ | { | ||||
CategoryId = props.CategoryId, | CategoryId = props.CategoryId, | ||||
Topic = props.Topic, | Topic = props.Topic, | ||||
IsNsfw = props.IsNsfw, | IsNsfw = props.IsNsfw, | ||||
Position = props.Position | |||||
Position = props.Position, | |||||
PermissionOverwrite = new Optional<IEnumerable<CreateChannelPermissionsParams>>(perms) | |||||
}; | }; | ||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
return RestTextChannel.Create(client, guild, model); | return RestTextChannel.Create(client, guild, model); | ||||
} | } | ||||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | ||||
string name, RequestOptions options, Action<VoiceChannelProperties> func = null) | |||||
string name, RequestOptions options, Action<VoiceChannelProperties> func = null, IEnumerable<Overwrite> overwrites = null) | |||||
{ | { | ||||
if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | ||||
var props = new VoiceChannelProperties(); | var props = new VoiceChannelProperties(); | ||||
func?.Invoke(props); | func?.Invoke(props); | ||||
var perms = overwrites?.Select(perm => new CreateChannelPermissionsParams(perm.TargetId, perm.TargetType == PermissionTarget.Role ? "role" : "member", perm.Permissions.AllowValue, perm.Permissions.DenyValue)); | |||||
var args = new CreateGuildChannelParams(name, ChannelType.Voice) | var args = new CreateGuildChannelParams(name, ChannelType.Voice) | ||||
{ | { | ||||
CategoryId = props.CategoryId, | CategoryId = props.CategoryId, | ||||
Bitrate = props.Bitrate, | Bitrate = props.Bitrate, | ||||
UserLimit = props.UserLimit, | UserLimit = props.UserLimit, | ||||
Position = props.Position | |||||
Position = props.Position, | |||||
PermissionOverwrite = new Optional<IEnumerable<CreateChannelPermissionsParams>>(perms) | |||||
}; | }; | ||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
return RestVoiceChannel.Create(client, guild, model); | return RestVoiceChannel.Create(client, guild, model); | ||||
} | } | ||||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||||
public static async Task<RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, | public static async Task<RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, | ||||
string name, RequestOptions options, Action<GuildChannelProperties> func = null) | |||||
string name, RequestOptions options, Action<GuildChannelProperties> func = null, IEnumerable<Overwrite> overwrites = null) | |||||
{ | { | ||||
if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | ||||
var props = new GuildChannelProperties(); | var props = new GuildChannelProperties(); | ||||
func?.Invoke(props); | func?.Invoke(props); | ||||
var perms = overwrites?.Select(perm => new CreateChannelPermissionsParams(perm.TargetId, perm.TargetType == PermissionTarget.Role ? "role" : "member", perm.Permissions.AllowValue, perm.Permissions.DenyValue)); | |||||
var args = new CreateGuildChannelParams(name, ChannelType.Category) | var args = new CreateGuildChannelParams(name, ChannelType.Category) | ||||
{ | { | ||||
Position = props.Position | |||||
Position = props.Position, | |||||
PermissionOverwrite = new Optional<IEnumerable<CreateChannelPermissionsParams>>(perms) | |||||
}; | }; | ||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
@@ -450,8 +450,8 @@ namespace Discord.Rest | |||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// text channel. | /// text channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
/// <summary> | /// <summary> | ||||
/// Creates a voice channel with the provided name. | /// Creates a voice channel with the provided name. | ||||
/// </summary> | /// </summary> | ||||
@@ -462,8 +462,8 @@ namespace Discord.Rest | |||||
/// <returns> | /// <returns> | ||||
/// The created voice channel. | /// The created voice channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
/// <summary> | /// <summary> | ||||
/// Creates a category channel with the provided name. | /// Creates a category channel with the provided name. | ||||
/// </summary> | /// </summary> | ||||
@@ -474,8 +474,8 @@ namespace Discord.Rest | |||||
/// <returns> | /// <returns> | ||||
/// The created category channel. | /// The created category channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of all the voice regions this guild can access. | /// Gets a collection of all the voice regions this guild can access. | ||||
@@ -581,8 +581,8 @@ namespace Discord.WebSocket | |||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// text channel. | /// text channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new voice channel in this guild. | /// Creates a new voice channel in this guild. | ||||
/// </summary> | /// </summary> | ||||
@@ -594,8 +594,8 @@ namespace Discord.WebSocket | |||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// voice channel. | /// voice channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new channel category in this guild. | /// Creates a new channel category in this guild. | ||||
/// </summary> | /// </summary> | ||||
@@ -607,8 +607,8 @@ namespace Discord.WebSocket | |||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// category channel. | /// category channel. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null, IEnumerable<Overwrite> overwritePermissions = null) | |||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func, overwritePermissions); | |||||
internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) | internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) | ||||
{ | { | ||||