@@ -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 | |||
using Newtonsoft.Json; | |||
using System.Collections.Generic; | |||
namespace Discord.API.Rest | |||
{ | |||
@@ -14,6 +15,8 @@ namespace Discord.API.Rest | |||
public Optional<ulong?> CategoryId { get; set; } | |||
[JsonProperty("position")] | |||
public Optional<int> Position { get; set; } | |||
[JsonProperty("permission_overwrite")] | |||
public Optional<IEnumerable<CreateChannelPermissionsParams>> PermissionOverwrite {get;set;} | |||
//Text channels | |||
[JsonProperty("topic")] | |||
@@ -164,54 +164,63 @@ namespace Discord.Rest | |||
} | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
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)); | |||
var props = new TextChannelProperties(); | |||
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) | |||
{ | |||
CategoryId = props.CategoryId, | |||
Topic = props.Topic, | |||
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); | |||
return RestTextChannel.Create(client, guild, model); | |||
} | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
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)); | |||
var props = new VoiceChannelProperties(); | |||
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) | |||
{ | |||
CategoryId = props.CategoryId, | |||
Bitrate = props.Bitrate, | |||
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); | |||
return RestVoiceChannel.Create(client, guild, model); | |||
} | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
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)); | |||
var props = new GuildChannelProperties(); | |||
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) | |||
{ | |||
Position = props.Position | |||
Position = props.Position, | |||
PermissionOverwrite = new Optional<IEnumerable<CreateChannelPermissionsParams>>(perms) | |||
}; | |||
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 | |||
/// text channel. | |||
/// </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> | |||
/// Creates a voice channel with the provided name. | |||
/// </summary> | |||
@@ -462,8 +462,8 @@ namespace Discord.Rest | |||
/// <returns> | |||
/// The created voice channel. | |||
/// </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> | |||
/// Creates a category channel with the provided name. | |||
/// </summary> | |||
@@ -474,8 +474,8 @@ namespace Discord.Rest | |||
/// <returns> | |||
/// The created category channel. | |||
/// </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> | |||
/// 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 | |||
/// text channel. | |||
/// </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> | |||
/// Creates a new voice channel in this guild. | |||
/// </summary> | |||
@@ -594,8 +594,8 @@ namespace Discord.WebSocket | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// voice channel. | |||
/// </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> | |||
/// Creates a new channel category in this guild. | |||
/// </summary> | |||
@@ -607,8 +607,8 @@ namespace Discord.WebSocket | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// category channel. | |||
/// </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) | |||
{ | |||