commit 07bca5b31a
Author: Joe4evr <jii.geugten@gmail.com>
Date: Fri Apr 6 09:44:50 2018 +0200
Add ability to specify parameters on channel creation
pull/1042/merge
@@ -109,9 +109,9 @@ namespace Discord | |||
Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
/// <summary> Creates a new text channel. </summary> | |||
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null); | |||
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null, Action<TextChannelProperties> func = null); | |||
/// <summary> Creates a new voice channel. </summary> | |||
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null); | |||
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null, Action<VoiceChannelProperties> func = null); | |||
/// <summary> Creates a new channel category. </summary> | |||
Task<ICategoryChannel> CreateCategoryAsync(string name, RequestOptions options = null); | |||
@@ -1,4 +1,4 @@ | |||
#pragma warning disable CS1591 | |||
#pragma warning disable CS1591 | |||
using Newtonsoft.Json; | |||
namespace Discord.API.Rest | |||
@@ -10,9 +10,20 @@ namespace Discord.API.Rest | |||
public string Name { get; } | |||
[JsonProperty("type")] | |||
public ChannelType Type { get; } | |||
[JsonProperty("parent_id")] | |||
public Optional<ulong?> CategoryId { get; set; } | |||
//Text channels | |||
[JsonProperty("topic")] | |||
public Optional<string> Topic { get; set; } | |||
[JsonProperty("nsfw")] | |||
public Optional<bool> IsNsfw { get; set; } | |||
//Voice channels | |||
[JsonProperty("bitrate")] | |||
public Optional<int> Bitrate { get; set; } | |||
[JsonProperty("user_limit")] | |||
public Optional<int?> UserLimit { get; set; } | |||
public CreateGuildChannelParams(string name, ChannelType type) | |||
{ | |||
@@ -145,20 +145,36 @@ namespace Discord.Rest | |||
return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray(); | |||
} | |||
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | |||
string name, RequestOptions options) | |||
string name, RequestOptions options, Action<TextChannelProperties> func = null) | |||
{ | |||
if (name == null) throw new ArgumentNullException(nameof(name)); | |||
var args = new CreateGuildChannelParams(name, ChannelType.Text); | |||
var props = new TextChannelProperties(); | |||
func?.Invoke(props); | |||
var args = new CreateGuildChannelParams(name, ChannelType.Text) | |||
{ | |||
CategoryId = props.CategoryId, | |||
Topic = props.Topic, | |||
IsNsfw = props.IsNsfw | |||
}; | |||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
return RestTextChannel.Create(client, guild, model); | |||
} | |||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | |||
string name, RequestOptions options) | |||
string name, RequestOptions options, Action<VoiceChannelProperties> func = null) | |||
{ | |||
if (name == null) throw new ArgumentNullException(nameof(name)); | |||
var args = new CreateGuildChannelParams(name, ChannelType.Voice); | |||
var props = new VoiceChannelProperties(); | |||
func?.Invoke(props); | |||
var args = new CreateGuildChannelParams(name, ChannelType.Voice) | |||
{ | |||
CategoryId = props.CategoryId, | |||
Bitrate = props.Bitrate, | |||
UserLimit = props.UserLimit | |||
}; | |||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
return RestVoiceChannel.Create(client, guild, model); | |||
} | |||
@@ -222,10 +222,10 @@ namespace Discord.Rest | |||
} | |||
return null; | |||
} | |||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | |||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | |||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null, Action<TextChannelProperties> func = null) | |||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null, Action<VoiceChannelProperties> func = null) | |||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | |||
@@ -383,10 +383,10 @@ namespace Discord.Rest | |||
else | |||
return null; | |||
} | |||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options) | |||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | |||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | |||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options, Action<TextChannelProperties> func) | |||
=> await CreateTextChannelAsync(name, options, func).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options, Action<VoiceChannelProperties> func) | |||
=> await CreateVoiceChannelAsync(name, options, func).ConfigureAwait(false); | |||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | |||
=> await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | |||
@@ -315,10 +315,10 @@ namespace Discord.WebSocket | |||
=> GetChannel(id) as SocketTextChannel; | |||
public SocketVoiceChannel GetVoiceChannel(ulong id) | |||
=> GetChannel(id) as SocketVoiceChannel; | |||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | |||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | |||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null, Action<TextChannelProperties> func = null) | |||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null, Action<VoiceChannelProperties> func = null) | |||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | |||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | |||
@@ -678,10 +678,10 @@ namespace Discord.WebSocket | |||
=> Task.FromResult<IGuildChannel>(EmbedChannel); | |||
Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) | |||
=> Task.FromResult<ITextChannel>(SystemChannel); | |||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options) | |||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | |||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | |||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options, Action<TextChannelProperties> func) | |||
=> await CreateTextChannelAsync(name, options, func).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options, Action<VoiceChannelProperties> func) | |||
=> await CreateVoiceChannelAsync(name, options, func).ConfigureAwait(false); | |||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | |||
=> await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | |||