@@ -761,6 +761,18 @@ namespace Discord | |||
/// </returns> | |||
Task<ICategoryChannel> CreateCategoryAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null); | |||
/// <summary> | |||
/// Creates a new channel forum in this guild. | |||
/// </summary> | |||
/// <param name="name">The new name for the forum.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <returns> | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// forum channel. | |||
/// </returns> | |||
Task<IForumChannel> CreateForumChannelAsync(string name, Action<ForumChannelProperties> func = null, RequestOptions options = null); | |||
/// <summary> | |||
/// Gets a collection of all the voice regions this guild can access. | |||
/// </summary> | |||
@@ -23,6 +23,8 @@ namespace Discord.API.Rest | |||
public Optional<bool> IsNsfw { get; set; } | |||
[JsonProperty("rate_limit_per_user")] | |||
public Optional<int> SlowModeInterval { get; set; } | |||
[JsonProperty("default_auto_archive_duration")] | |||
public Optional<ThreadArchiveDuration> DefaultAutoArchiveDuration { get; set; } | |||
//Voice channels | |||
[JsonProperty("bitrate")] | |||
@@ -30,6 +32,14 @@ namespace Discord.API.Rest | |||
[JsonProperty("user_limit")] | |||
public Optional<int?> UserLimit { get; set; } | |||
//Forum channels | |||
[JsonProperty("default_reaction_emoji")] | |||
public Optional<ModifyForumReactionEmojiParams> DefaultReactionEmoji { get; set; } | |||
[JsonProperty("default_thread_rate_limit_per_user")] | |||
public Optional<int> ThreadRateLimitPerUser { get; set; } | |||
[JsonProperty("available_tags")] | |||
public Optional<ModifyForumTagParams[]> AvailableTags { get; set; } | |||
public CreateGuildChannelParams(string name, ChannelType type) | |||
{ | |||
Name = name; | |||
@@ -1,3 +1,4 @@ | |||
using Discord.API; | |||
using Discord.API.Rest; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -252,6 +253,7 @@ namespace Discord.Rest | |||
Deny = overwrite.Permissions.DenyValue.ToString() | |||
}).ToArray() | |||
: Optional.Create<API.Overwrite[]>(), | |||
DefaultAutoArchiveDuration = props.AutoArchiveDuration | |||
}; | |||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
return RestTextChannel.Create(client, guild, model); | |||
@@ -338,6 +340,62 @@ namespace Discord.Rest | |||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
return RestCategoryChannel.Create(client, guild, model); | |||
} | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
public static async Task<RestForumChannel> CreateForumChannelAsync(IGuild guild, BaseDiscordClient client, | |||
string name, RequestOptions options, Action<ForumChannelProperties> func = null) | |||
{ | |||
if (name == null) | |||
throw new ArgumentNullException(paramName: nameof(name)); | |||
var props = new ForumChannelProperties(); | |||
func?.Invoke(props); | |||
var args = new CreateGuildChannelParams(name, ChannelType.Forum) | |||
{ | |||
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.ToString(), | |||
Deny = overwrite.Permissions.DenyValue.ToString() | |||
}).ToArray() | |||
: Optional.Create<API.Overwrite[]>(), | |||
SlowModeInterval = props.ThreadCreationInterval, | |||
AvailableTags = props.Tags.GetValueOrDefault().Select( | |||
x => new ModifyForumTagParams | |||
{ | |||
Id = x.Id, | |||
Name = x.Name, | |||
EmojiId = x.Emoji is Emote emote | |||
? emote.Id | |||
: Optional<ulong?>.Unspecified, | |||
EmojiName = x.Emoji is Emoji emoji | |||
? emoji.Name | |||
: Optional<string>.Unspecified, | |||
Moderated = x.IsModerated | |||
}).ToArray(), | |||
DefaultReactionEmoji = props.DefaultReactionEmoji.IsSpecified | |||
? new API.ModifyForumReactionEmojiParams | |||
{ | |||
EmojiId = props.DefaultReactionEmoji.Value is Emote emote ? | |||
emote.Id : Optional<ulong?>.Unspecified, | |||
EmojiName = props.DefaultReactionEmoji.Value is Emoji emoji ? | |||
emoji.Name : Optional<string>.Unspecified | |||
} | |||
: Optional<ModifyForumReactionEmojiParams>.Unspecified, | |||
ThreadRateLimitPerUser = props.DefaultSlowModeInterval, | |||
CategoryId = props.CategoryId, | |||
IsNsfw = props.IsNsfw, | |||
Topic = props.Topic, | |||
DefaultAutoArchiveDuration = props.AutoArchiveDuration | |||
}; | |||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
return RestForumChannel.Create(client, guild, model); | |||
} | |||
#endregion | |||
#region Voice Regions | |||
@@ -710,6 +710,19 @@ namespace Discord.Rest | |||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, Action<GuildChannelProperties> func = null, RequestOptions options = null) | |||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); | |||
/// <summary> | |||
/// Creates a category channel with the provided name. | |||
/// </summary> | |||
/// <param name="name">The name of the new channel.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <exception cref="ArgumentNullException"><paramref name="name" /> is <see langword="null"/>.</exception> | |||
/// <returns> | |||
/// The created category channel. | |||
/// </returns> | |||
public Task<RestForumChannel> CreateForumChannelAsync(string name, Action<ForumChannelProperties> func = null, RequestOptions options = null) | |||
=> GuildHelper.CreateForumChannelAsync(this, Discord, name, options, func); | |||
/// <summary> | |||
/// Gets a collection of all the voice regions this guild can access. | |||
/// </summary> | |||
@@ -1370,6 +1383,9 @@ namespace Discord.Rest | |||
/// <inheritdoc /> | |||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, Action<GuildChannelProperties> func, RequestOptions options) | |||
=> await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
async Task<IForumChannel> IGuild.CreateForumChannelAsync(string name, Action<ForumChannelProperties> func, RequestOptions options) | |||
=> await CreateForumChannelAsync(name, func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
async Task<IReadOnlyCollection<IVoiceRegion>> IGuild.GetVoiceRegionsAsync(RequestOptions options) | |||
@@ -790,6 +790,7 @@ namespace Discord.WebSocket | |||
/// </returns> | |||
public Task<RestStageChannel> CreateStageChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||
=> GuildHelper.CreateStageChannelAsync(this, Discord, name, options, func); | |||
/// <summary> | |||
/// Creates a new channel category in this guild. | |||
/// </summary> | |||
@@ -801,9 +802,24 @@ 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) | |||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, | |||
Action<GuildChannelProperties> func = null, RequestOptions options = null) | |||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); | |||
/// <summary> | |||
/// Creates a new channel forum in this guild. | |||
/// </summary> | |||
/// <param name="name">The new name for the forum.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception> | |||
/// <returns> | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// forum channel. | |||
/// </returns> | |||
public Task<RestForumChannel> CreateForumChannelAsync(string name, Action<ForumChannelProperties> func = null, RequestOptions options = null) | |||
=> GuildHelper.CreateForumChannelAsync(this, Discord, name, options, func); | |||
internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) | |||
{ | |||
var channel = SocketGuildChannel.Create(this, state, model); | |||
@@ -1897,6 +1913,9 @@ namespace Discord.WebSocket | |||
/// <inheritdoc /> | |||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, Action<GuildChannelProperties> func, RequestOptions options) | |||
=> await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
async Task<IForumChannel> IGuild.CreateForumChannelAsync(string name, Action<ForumChannelProperties> func, RequestOptions options) | |||
=> await CreateForumChannelAsync(name, func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
async Task<IReadOnlyCollection<IVoiceRegion>> IGuild.GetVoiceRegionsAsync(RequestOptions options) | |||