* General cleanup * Add Async suffix to SendAutocompleteResult * Fix more formatting * Fix unused RequestOptions in GetActiveThreadsAsync * Add message to ArgumentNullExceptionpull/1923/head
@@ -1,7 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -1,7 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -9,7 +6,7 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Represents a thread channel inside of a guild. | /// Represents a thread channel inside of a guild. | ||||
/// </summary> | /// </summary> | ||||
public interface IThreadChannel : ITextChannel, IGuildChannel | |||||
public interface IThreadChannel : ITextChannel | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Gets the type of the current thread channel. | /// Gets the type of the current thread channel. | ||||
@@ -56,7 +53,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous join operation. | |||||
/// A task that represents the asynchronous join operation. | |||||
/// </returns> | /// </returns> | ||||
Task JoinAsync(RequestOptions options = null); | Task JoinAsync(RequestOptions options = null); | ||||
@@ -65,7 +62,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous leave operation. | |||||
/// A task that represents the asynchronous leave operation. | |||||
/// </returns> | /// </returns> | ||||
Task LeaveAsync(RequestOptions options = null); | Task LeaveAsync(RequestOptions options = null); | ||||
@@ -75,7 +72,7 @@ namespace Discord | |||||
/// <param name="user">The <see cref="IGuildUser"/> to add.</param> | /// <param name="user">The <see cref="IGuildUser"/> to add.</param> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous operation of adding a member to a thread. | |||||
/// A task that represents the asynchronous operation of adding a member to a thread. | |||||
/// </returns> | /// </returns> | ||||
Task AddUserAsync(IGuildUser user, RequestOptions options = null); | Task AddUserAsync(IGuildUser user, RequestOptions options = null); | ||||
@@ -85,7 +82,7 @@ namespace Discord | |||||
/// <param name="user">The <see cref="IGuildUser"/> to remove from this thread.</param> | /// <param name="user">The <see cref="IGuildUser"/> to remove from this thread.</param> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous operation of removing a user from this thread. | |||||
/// A task that represents the asynchronous operation of removing a user from this thread. | |||||
/// </returns> | /// </returns> | ||||
Task RemoveUserAsync(IGuildUser user, RequestOptions options = null); | Task RemoveUserAsync(IGuildUser user, RequestOptions options = null); | ||||
} | } | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,14 +1,17 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | |||||
/// Specifies the privacy levels of a Stage instance. | |||||
/// </summary> | |||||
public enum StagePrivacyLevel | public enum StagePrivacyLevel | ||||
{ | { | ||||
/// <summary> | |||||
/// The Stage instance is visible publicly, such as on Stage Discovery. | |||||
/// </summary> | |||||
Public = 1, | Public = 1, | ||||
GuildOnly = 2, | |||||
/// <summary> | |||||
/// The Stage instance is visible to only guild members. | |||||
/// </summary> | |||||
GuildOnly = 2 | |||||
} | } | ||||
} | } |
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -24,7 +18,7 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Three days (4320 minutes). | /// Three days (4320 minutes). | ||||
/// <remarks> | /// <remarks> | ||||
/// This option is explicity avaliable to nitro users. | |||||
/// This option is explicitly available to nitro users. | |||||
/// </remarks> | /// </remarks> | ||||
/// </summary> | /// </summary> | ||||
ThreeDays = 4320, | ThreeDays = 4320, | ||||
@@ -32,9 +26,9 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// One week (10080 minutes). | /// One week (10080 minutes). | ||||
/// <remarks> | /// <remarks> | ||||
/// This option is explicity avaliable to nitro users. | |||||
/// This option is explicitly available to nitro users. | |||||
/// </remarks> | /// </remarks> | ||||
/// </summary> | /// </summary> | ||||
OneWeek = 10080, | |||||
OneWeek = 10080 | |||||
} | } | ||||
} | } |
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -24,6 +18,6 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Represents a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission | /// Represents a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission | ||||
/// </summary> | /// </summary> | ||||
PrivateThread = 12, | |||||
PrivateThread = 12 | |||||
} | } | ||||
} | } |
@@ -1,9 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -24,13 +21,13 @@ namespace Discord | |||||
set | set | ||||
{ | { | ||||
if (value == null) | if (value == null) | ||||
throw new ArgumentNullException($"{nameof(Name)} cannot be null!"); | |||||
throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null."); | |||||
if (value.Length > 32) | if (value.Length > 32) | ||||
throw new ArgumentException($"{nameof(Name)} length must be less than or equal to 32"); | |||||
throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 32."); | |||||
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | ||||
throw new ArgumentException($"{nameof(Name)} must match the regex ^[\\w-]{{1,32}}$"); | |||||
throw new FormatException($"{nameof(value)} must match the regex ^[\\w-]{{1,32}}$"); | |||||
_name = value; | _name = value; | ||||
} | } | ||||
@@ -42,14 +39,12 @@ namespace Discord | |||||
public string Description | public string Description | ||||
{ | { | ||||
get => _description; | get => _description; | ||||
set | |||||
set => _description = value?.Length switch | |||||
{ | { | ||||
if (value?.Length > 100) | |||||
throw new ArgumentException("Description length must be less than or equal to 100"); | |||||
if (value?.Length < 1) | |||||
throw new ArgumentException("Description length must at least 1 character in length"); | |||||
_description = value; | |||||
} | |||||
> 100 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be less than or equal to 100."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -19,14 +15,12 @@ namespace Discord | |||||
public string Name | public string Name | ||||
{ | { | ||||
get => _name; | get => _name; | ||||
set | |||||
set => _name = value?.Length switch | |||||
{ | { | ||||
if(value?.Length > 100) | |||||
throw new ArgumentException("Name length must be less than or equal to 100"); | |||||
if (value?.Length < 1) | |||||
throw new ArgumentException("Name length must at least 1 character in length"); | |||||
_name = value; | |||||
} | |||||
> 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -40,11 +34,8 @@ namespace Discord | |||||
get => _value; | get => _value; | ||||
set | set | ||||
{ | { | ||||
if(value != null) | |||||
{ | |||||
if(!(value is int) && !(value is string)) | |||||
throw new ArgumentException("The value of a choice must be a string or int!"); | |||||
} | |||||
if (value != null && value is not int && value is not string) | |||||
throw new ArgumentException("The value of a choice must be a string or int!"); | |||||
_value = value; | _value = value; | ||||
} | } | ||||
} | } | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -37,7 +31,7 @@ namespace Discord | |||||
Boolean = 5, | Boolean = 5, | ||||
/// <summary> | /// <summary> | ||||
/// A <see cref="IGuildUser"/>. | |||||
/// A <see cref="IUser"/>. | |||||
/// </summary> | /// </summary> | ||||
User = 6, | User = 6, | ||||
@@ -55,7 +49,7 @@ namespace Discord | |||||
/// A <see cref="IUser"/> or <see cref="IRole"/>. | /// A <see cref="IUser"/> or <see cref="IRole"/>. | ||||
/// </summary> | /// </summary> | ||||
Mentionable = 9, | Mentionable = 9, | ||||
/// <summary> | /// <summary> | ||||
/// A <see cref="double"/>. | /// A <see cref="double"/>. | ||||
/// </summary> | /// </summary> | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -11,8 +7,8 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public class AutocompleteResult | public class AutocompleteResult | ||||
{ | { | ||||
private object _value { get; set; } | |||||
private string _name { get; set; } | |||||
private object _value; | |||||
private string _name; | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets the name of the result. | /// Gets or sets the name of the result. | ||||
@@ -28,12 +24,13 @@ namespace Discord | |||||
set | set | ||||
{ | { | ||||
if (value == null) | if (value == null) | ||||
throw new ArgumentException("Name cannot be null!"); | |||||
if (value.Length > 100) | |||||
throw new ArgumentException("Name length must be less than or equal to 100 characters in length!"); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Name length must at least 1 character in length!"); | |||||
_name = value; | |||||
throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null."); | |||||
_name = value.Length switch | |||||
{ | |||||
> 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
} | } | ||||
@@ -48,20 +45,15 @@ namespace Discord | |||||
public object Value | public object Value | ||||
{ | { | ||||
get => _value; | get => _value; | ||||
set | |||||
set => _value = value switch | |||||
{ | { | ||||
if (value == null) | |||||
throw new ArgumentNullException("Value cannot be null"); | |||||
_value = value switch | |||||
{ | |||||
string str => str, | |||||
int integer => integer, | |||||
long lng => lng, | |||||
double number => number, | |||||
_ => throw new ArgumentException($"Type {value.GetType().Name} cannot be set as a value! Only string, int, and double allowed!"), | |||||
}; | |||||
} | |||||
string str => str, | |||||
int integer => integer, | |||||
long lng => lng, | |||||
double number => number, | |||||
null => throw new ArgumentNullException(nameof(value), $"{nameof(Value)} cannot be null."), | |||||
_ => throw new ArgumentException($"Type {value.GetType().Name} cannot be set as a value! Only string, int, and double allowed!") | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -1,10 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Text.RegularExpressions; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -12,7 +5,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public class MessageCommandBuilder | public class MessageCommandBuilder | ||||
{ | { | ||||
/// <summary> | |||||
/// <summary> | |||||
/// Returns the maximum length a commands name allowed by Discord | /// Returns the maximum length a commands name allowed by Discord | ||||
/// </summary> | /// </summary> | ||||
public const int MaxNameLength = 32; | public const int MaxNameLength = 32; | ||||
@@ -22,10 +15,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public string Name | public string Name | ||||
{ | { | ||||
get | |||||
{ | |||||
return _name; | |||||
} | |||||
get => _name; | |||||
set | set | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(value, nameof(Name)); | Preconditions.NotNullOrEmpty(value, nameof(Name)); | ||||
@@ -41,7 +31,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDefaultPermission { get; set; } = true; | public bool IsDefaultPermission { get; set; } = true; | ||||
private string _name { get; set; } | |||||
private string _name; | |||||
/// <summary> | /// <summary> | ||||
/// Build the current builder into a <see cref="MessageCommandProperties"/> class. | /// Build the current builder into a <see cref="MessageCommandProperties"/> class. | ||||
@@ -51,14 +41,13 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
public MessageCommandProperties Build() | public MessageCommandProperties Build() | ||||
{ | { | ||||
MessageCommandProperties props = new MessageCommandProperties() | |||||
var props = new MessageCommandProperties | |||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
DefaultPermission = IsDefaultPermission | DefaultPermission = IsDefaultPermission | ||||
}; | }; | ||||
return props; | return props; | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -79,7 +68,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <param name="isDefaultPermission">The default permission value to set.</param> | /// <param name="isDefaultPermission">The default permission value to set.</param> | ||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public MessageCommandBuilder WithDefaultPermission (bool isDefaultPermission) | |||||
public MessageCommandBuilder WithDefaultPermission(bool isDefaultPermission) | |||||
{ | { | ||||
IsDefaultPermission = isDefaultPermission; | IsDefaultPermission = isDefaultPermission; | ||||
return this; | return this; | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,10 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Text.RegularExpressions; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -22,10 +15,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public string Name | public string Name | ||||
{ | { | ||||
get | |||||
{ | |||||
return _name; | |||||
} | |||||
get => _name; | |||||
set | set | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(value, nameof(Name)); | Preconditions.NotNullOrEmpty(value, nameof(Name)); | ||||
@@ -41,7 +31,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDefaultPermission { get; set; } = true; | public bool IsDefaultPermission { get; set; } = true; | ||||
private string _name { get; set; } | |||||
private string _name; | |||||
/// <summary> | /// <summary> | ||||
/// Build the current builder into a <see cref="UserCommandProperties"/> class. | /// Build the current builder into a <see cref="UserCommandProperties"/> class. | ||||
@@ -49,14 +39,13 @@ namespace Discord | |||||
/// <returns>A <see cref="UserCommandProperties"/> that can be used to create user commands.</returns> | /// <returns>A <see cref="UserCommandProperties"/> that can be used to create user commands.</returns> | ||||
public UserCommandProperties Build() | public UserCommandProperties Build() | ||||
{ | { | ||||
UserCommandProperties props = new UserCommandProperties() | |||||
var props = new UserCommandProperties | |||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
DefaultPermission = IsDefaultPermission | DefaultPermission = IsDefaultPermission | ||||
}; | }; | ||||
return props; | return props; | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -77,7 +66,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <param name="isDefaultPermission">The default permission value to set.</param> | /// <param name="isDefaultPermission">The default permission value to set.</param> | ||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public UserCommandBuilder WithDefaultPermission (bool isDefaultPermission) | |||||
public UserCommandBuilder WithDefaultPermission(bool isDefaultPermission) | |||||
{ | { | ||||
IsDefaultPermission = isDefaultPermission; | IsDefaultPermission = isDefaultPermission; | ||||
return this; | return this; | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,7 +1,5 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -17,7 +15,7 @@ namespace Discord | |||||
ulong ApplicationId { get; } | ulong ApplicationId { get; } | ||||
/// <summary> | /// <summary> | ||||
/// The type of the command | |||||
/// The type of the command. | |||||
/// </summary> | /// </summary> | ||||
ApplicationCommandType Type { get; } | ApplicationCommandType Type { get; } | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -33,6 +29,5 @@ namespace Discord | |||||
/// Present if this option is a group or subcommand. | /// Present if this option is a group or subcommand. | ||||
/// </summary> | /// </summary> | ||||
IReadOnlyCollection<IApplicationCommandInteractionDataOption> Options { get; } | IReadOnlyCollection<IApplicationCommandInteractionDataOption> Options { get; } | ||||
} | } | ||||
} | } |
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -39,16 +35,16 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Choices for string and int types for the user to pick from. | /// Choices for string and int types for the user to pick from. | ||||
/// </summary> | /// </summary> | ||||
IReadOnlyCollection<IApplicationCommandOptionChoice>? Choices { get; } | |||||
IReadOnlyCollection<IApplicationCommandOptionChoice> Choices { get; } | |||||
/// <summary> | /// <summary> | ||||
/// If the option is a subcommand or subcommand group type, this nested options will be the parameters. | /// If the option is a subcommand or subcommand group type, this nested options will be the parameters. | ||||
/// </summary> | /// </summary> | ||||
IReadOnlyCollection<IApplicationCommandOption>? Options { get; } | |||||
IReadOnlyCollection<IApplicationCommandOption> Options { get; } | |||||
/// <summary> | /// <summary> | ||||
/// The allowed channel types for this option. | /// The allowed channel types for this option. | ||||
/// </summary> | /// </summary> | ||||
IReadOnlyCollection<ChannelType>? ChannelTypes { get; } | |||||
IReadOnlyCollection<ChannelType> ChannelTypes { get; } | |||||
} | } | ||||
} | } |
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -20,6 +14,5 @@ namespace Discord | |||||
/// value of the choice. | /// value of the choice. | ||||
/// </summary> | /// </summary> | ||||
object Value { get; } | object Value { get; } | ||||
} | } | ||||
} | } |
@@ -1,7 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -51,7 +48,7 @@ namespace Discord | |||||
/// <param name="options">The request options for this response.</param> | /// <param name="options">The request options for this response.</param> | ||||
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response.</param> | /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response.</param> | ||||
/// <param name="embed">A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.</param> | /// <param name="embed">A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.</param> | ||||
Task RespondAsync (string text = null, Embed[] embeds = null, bool isTTS = false, | |||||
Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, | |||||
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | ||||
/// <summary> | /// <summary> | ||||
@@ -68,7 +65,7 @@ namespace Discord | |||||
/// <returns> | /// <returns> | ||||
/// The sent message. | /// The sent message. | ||||
/// </returns> | /// </returns> | ||||
Task<IUserMessage> FollowupAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||||
Task<IUserMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||||
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | ||||
/// <summary> | /// <summary> | ||||
@@ -76,7 +73,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The request options for this <see langword="async"/> request.</param> | /// <param name="options">The request options for this <see langword="async"/> request.</param> | ||||
/// <returns>A <see cref="IUserMessage"/> that represents the initial response.</returns> | /// <returns>A <see cref="IUserMessage"/> that represents the initial response.</returns> | ||||
Task<IUserMessage> GetOriginalResponseAsync (RequestOptions options = null); | |||||
Task<IUserMessage> GetOriginalResponseAsync(RequestOptions options = null); | |||||
/// <summary> | /// <summary> | ||||
/// Edits original response for this interaction. | /// Edits original response for this interaction. | ||||
@@ -84,7 +81,7 @@ namespace Discord | |||||
/// <param name="func">A delegate containing the properties to modify the message with.</param> | /// <param name="func">A delegate containing the properties to modify the message with.</param> | ||||
/// <param name="options">The request options for this <see langword="async"/> request.</param> | /// <param name="options">The request options for this <see langword="async"/> request.</param> | ||||
/// <returns>A <see cref="IUserMessage"/> that represents the initial response.</returns> | /// <returns>A <see cref="IUserMessage"/> that represents the initial response.</returns> | ||||
Task<IUserMessage> ModifyOriginalResponseAsync (Action<MessageProperties> func, RequestOptions options = null); | |||||
Task<IUserMessage> ModifyOriginalResponseAsync(Action<MessageProperties> func, RequestOptions options = null); | |||||
/// <summary> | /// <summary> | ||||
/// Acknowledges this interaction. | /// Acknowledges this interaction. | ||||
@@ -92,6 +89,6 @@ namespace Discord | |||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous operation of acknowledging the interaction. | /// A task that represents the asynchronous operation of acknowledging the interaction. | ||||
/// </returns> | /// </returns> | ||||
Task DeferAsync (bool ephemeral = false, RequestOptions options = null); | |||||
Task DeferAsync(bool ephemeral = false, RequestOptions options = null); | |||||
} | } | ||||
} | } |
@@ -1,13 +1,7 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Represents an interface used to specify classes that they are a vaild data type of a <see cref="IDiscordInteraction"/> class. | |||||
/// Represents an interface used to specify classes that they are a valid data type of a <see cref="IDiscordInteraction"/> class. | |||||
/// </summary> | /// </summary> | ||||
public interface IDiscordInteractionData { } | public interface IDiscordInteractionData { } | ||||
} | } |
@@ -1,8 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -13,7 +9,7 @@ namespace Discord | |||||
/// After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using <see cref="ChannelMessageWithSource"/> | /// After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using <see cref="ChannelMessageWithSource"/> | ||||
/// or you can choose to send a deferred response with <see cref="DeferredChannelMessageWithSource"/>. If choosing a deferred response, the user will see a loading state for the interaction, | /// or you can choose to send a deferred response with <see cref="DeferredChannelMessageWithSource"/>. If choosing a deferred response, the user will see a loading state for the interaction, | ||||
/// and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. | /// and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. | ||||
/// You can read more about Response types <see href="https://discord.com/developers/docs/interactions/slash-commands#interaction-response">Here</see> | |||||
/// You can read more about Response types <see href="https://discord.com/developers/docs/interactions/slash-commands#interaction-response">Here</see>. | |||||
/// </remarks> | /// </remarks> | ||||
public enum InteractionResponseType : byte | public enum InteractionResponseType : byte | ||||
{ | { | ||||
@@ -45,17 +41,17 @@ namespace Discord | |||||
DeferredChannelMessageWithSource = 5, | DeferredChannelMessageWithSource = 5, | ||||
/// <summary> | /// <summary> | ||||
/// For components: ACK an interaction and edit the original message later; the user does not see a loading state | |||||
/// For components: ACK an interaction and edit the original message later; the user does not see a loading state. | |||||
/// </summary> | /// </summary> | ||||
DeferredUpdateMessage = 6, | DeferredUpdateMessage = 6, | ||||
/// <summary> | /// <summary> | ||||
/// For components: edit the message the component was attached to | |||||
/// For components: edit the message the component was attached to. | |||||
/// </summary> | /// </summary> | ||||
UpdateMessage = 7, | UpdateMessage = 7, | ||||
/// <summary> | /// <summary> | ||||
/// Respond with a set of choices to a autocomplete interaction | |||||
/// Respond with a set of choices to a autocomplete interaction. | |||||
/// </summary> | /// </summary> | ||||
ApplicationCommandAutocompleteResult = 8 | ApplicationCommandAutocompleteResult = 8 | ||||
} | } | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -29,6 +23,6 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// An autocomplete request sent from discord. | /// An autocomplete request sent from discord. | ||||
/// </summary> | /// </summary> | ||||
ApplicationCommandAutocomplete = 4, | |||||
ApplicationCommandAutocomplete = 4 | |||||
} | } | ||||
} | } |
@@ -1,28 +1,22 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Represents a <see cref="IMessageComponent"/> Row for child components to live in. | |||||
/// Represents a <see cref="IMessageComponent"/> Row for child components to live in. | |||||
/// </summary> | /// </summary> | ||||
public class ActionRowComponent : IMessageComponent | public class ActionRowComponent : IMessageComponent | ||||
{ | { | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public ComponentType Type { get; } = ComponentType.ActionRow; | |||||
public ComponentType Type => ComponentType.ActionRow; | |||||
/// <summary> | /// <summary> | ||||
/// Gets the child components in this row. | /// Gets the child components in this row. | ||||
/// </summary> | /// </summary> | ||||
public IReadOnlyCollection<IMessageComponent> Components { get; internal set; } | public IReadOnlyCollection<IMessageComponent> Components { get; internal set; } | ||||
internal ActionRowComponent() { } | internal ActionRowComponent() { } | ||||
internal ActionRowComponent(List<IMessageComponent> components) | internal ActionRowComponent(List<IMessageComponent> components) | ||||
{ | { | ||||
Components = components; | Components = components; | ||||
@@ -1,10 +1,3 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -13,7 +6,7 @@ namespace Discord | |||||
public class ButtonComponent : IMessageComponent | public class ButtonComponent : IMessageComponent | ||||
{ | { | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public ComponentType Type { get; } = ComponentType.Button; | |||||
public ComponentType Type => ComponentType.Button; | |||||
/// <summary> | /// <summary> | ||||
/// Gets the <see cref="ButtonStyle"/> of this button, example buttons with each style can be found <see href="https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png">Here</see>. | /// Gets the <see cref="ButtonStyle"/> of this button, example buttons with each style can be found <see href="https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png">Here</see>. | ||||
@@ -34,7 +27,7 @@ namespace Discord | |||||
public string CustomId { get; } | public string CustomId { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the URL for a <see cref="ButtonStyle.Link"/> button. | |||||
/// Gets the URL for a <see cref="ButtonStyle.Link"/> button. | |||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// You cannot have a button with a <b>URL</b> and a <b>CustomId</b>. | /// You cannot have a button with a <b>URL</b> and a <b>CustomId</b>. | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -31,14 +31,14 @@ namespace Discord | |||||
set | set | ||||
{ | { | ||||
if (value == null) | if (value == null) | ||||
throw new ArgumentNullException(paramName: nameof(ActionRows), message: "Cannot set an component builder's components collection to null."); | |||||
throw new ArgumentNullException(nameof(value), $"{nameof(ActionRows)} cannot be null."); | |||||
if (value.Count > MaxActionRowCount) | if (value.Count > MaxActionRowCount) | ||||
throw new ArgumentException(message: $"Action row count must be less than or equal to {MaxActionRowCount}.", paramName: nameof(ActionRows)); | |||||
throw new ArgumentOutOfRangeException(nameof(value), $"Action row count must be less than or equal to {MaxActionRowCount}."); | |||||
_actionRows = value; | _actionRows = value; | ||||
} | } | ||||
} | } | ||||
private List<ActionRowBuilder> _actionRows { get; set; } | |||||
private List<ActionRowBuilder> _actionRows; | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new builder from a message. | /// Creates a new builder from a message. | ||||
@@ -56,7 +56,7 @@ namespace Discord | |||||
public static ComponentBuilder FromComponents(IReadOnlyCollection<IMessageComponent> components) | public static ComponentBuilder FromComponents(IReadOnlyCollection<IMessageComponent> components) | ||||
{ | { | ||||
var builder = new ComponentBuilder(); | var builder = new ComponentBuilder(); | ||||
for(int i = 0; i != components.Count; i++) | |||||
for (int i = 0; i != components.Count; i++) | |||||
{ | { | ||||
var component = components.ElementAt(i); | var component = components.ElementAt(i); | ||||
builder.AddComponent(component, i); | builder.AddComponent(component, i); | ||||
@@ -118,7 +118,7 @@ namespace Discord | |||||
public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0) | public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0) | ||||
{ | { | ||||
Preconditions.LessThan(row, MaxActionRowCount, nameof(row)); | Preconditions.LessThan(row, MaxActionRowCount, nameof(row)); | ||||
if (menu.Options.Distinct().Count() != menu.Options.Count()) | |||||
if (menu.Options.Distinct().Count() != menu.Options.Count) | |||||
throw new InvalidOperationException("Please make sure that there is no duplicates values."); | throw new InvalidOperationException("Please make sure that there is no duplicates values."); | ||||
var builtMenu = menu.Build(); | var builtMenu = menu.Build(); | ||||
@@ -218,7 +218,7 @@ namespace Discord | |||||
else | else | ||||
{ | { | ||||
ActionRowBuilder actionRow; | ActionRowBuilder actionRow; | ||||
if(_actionRows.Count > row) | |||||
if (_actionRows.Count > row) | |||||
actionRow = _actionRows.ElementAt(row); | actionRow = _actionRows.ElementAt(row); | ||||
else | else | ||||
{ | { | ||||
@@ -244,10 +244,9 @@ namespace Discord | |||||
/// <returns>A <see cref="MessageComponent"/> that can be sent with <see cref="IMessageChannel.SendMessageAsync"/>.</returns> | /// <returns>A <see cref="MessageComponent"/> that can be sent with <see cref="IMessageChannel.SendMessageAsync"/>.</returns> | ||||
public MessageComponent Build() | public MessageComponent Build() | ||||
{ | { | ||||
if (_actionRows != null) | |||||
return new MessageComponent(_actionRows.Select(x => x.Build()).ToList()); | |||||
else | |||||
return MessageComponent.Empty; | |||||
return _actionRows != null | |||||
? new MessageComponent(_actionRows.Select(x => x.Build()).ToList()) | |||||
: MessageComponent.Empty; | |||||
} | } | ||||
} | } | ||||
@@ -272,19 +271,18 @@ namespace Discord | |||||
set | set | ||||
{ | { | ||||
if (value == null) | if (value == null) | ||||
throw new ArgumentNullException(message: "Action row components cannot be null!", paramName: nameof(Components)); | |||||
if (value.Count <= 0) | |||||
throw new ArgumentException(message: "There must be at least 1 component in a row", paramName: nameof(Components)); | |||||
if (value.Count > MaxChildCount) | |||||
throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components)); | |||||
throw new ArgumentNullException(nameof(value), $"{nameof(Components)} cannot be null."); | |||||
_components = value; | |||||
_components = value.Count switch | |||||
{ | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "There must be at least 1 component in a row."), | |||||
> MaxChildCount => throw new ArgumentOutOfRangeException(nameof(value), $"Action row can only contain {MaxChildCount} child components!"), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
} | } | ||||
private List<IMessageComponent> _components { get; set; } = new List<IMessageComponent>(); | |||||
private List<IMessageComponent> _components = new List<IMessageComponent>(); | |||||
/// <summary> | /// <summary> | ||||
/// Adds a list of components to the current row. | /// Adds a list of components to the current row. | ||||
@@ -359,18 +357,12 @@ namespace Discord | |||||
public string Label | public string Label | ||||
{ | { | ||||
get => _label; | get => _label; | ||||
set | |||||
set => _label = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > MaxButtonLabelLength) | |||||
throw new ArgumentException($"Button label must be {MaxButtonLabelLength} characters or less!", paramName: nameof(Label)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Button label must be 1 character or more!", paramName: nameof(Label)); | |||||
} | |||||
_label = value; | |||||
} | |||||
> MaxButtonLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxButtonLabelLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -381,17 +373,12 @@ namespace Discord | |||||
public string CustomId | public string CustomId | ||||
{ | { | ||||
get => _customId; | get => _customId; | ||||
set | |||||
set => _customId = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > ComponentBuilder.MaxCustomIdLength) | |||||
throw new ArgumentException($"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Custom Id must be 1 character or more!", paramName: nameof(CustomId)); | |||||
} | |||||
_customId = value; | |||||
} | |||||
> ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -414,7 +401,6 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDisabled { get; set; } | public bool IsDisabled { get; set; } | ||||
private string _label; | private string _label; | ||||
private string _customId; | private string _customId; | ||||
@@ -594,8 +580,7 @@ namespace Discord | |||||
{ | { | ||||
if (string.IsNullOrEmpty(Url)) | if (string.IsNullOrEmpty(Url)) | ||||
throw new InvalidOperationException("Link buttons must have a link associated with them"); | throw new InvalidOperationException("Link buttons must have a link associated with them"); | ||||
else | |||||
UrlValidation.ValidateButton(Url); | |||||
UrlValidation.ValidateButton(Url); | |||||
} | } | ||||
else if (string.IsNullOrEmpty(CustomId)) | else if (string.IsNullOrEmpty(CustomId)) | ||||
throw new InvalidOperationException("Non-link buttons must have a custom id associated with them"); | throw new InvalidOperationException("Non-link buttons must have a custom id associated with them"); | ||||
@@ -632,17 +617,12 @@ namespace Discord | |||||
public string CustomId | public string CustomId | ||||
{ | { | ||||
get => _customId; | get => _customId; | ||||
set | |||||
set => _customId = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > ComponentBuilder.MaxCustomIdLength) | |||||
throw new ArgumentException($"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Custom Id must be 1 character or more!", paramName: nameof(CustomId)); | |||||
} | |||||
_customId = value; | |||||
} | |||||
> ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -653,18 +633,12 @@ namespace Discord | |||||
public string Placeholder | public string Placeholder | ||||
{ | { | ||||
get => _placeholder; | get => _placeholder; | ||||
set | |||||
set => _placeholder = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > MaxPlaceholderLength) | |||||
throw new ArgumentException($"The placeholder must be {MaxPlaceholderLength} characters or less!", paramName: nameof(Placeholder)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("The placeholder must be 1 character or more!", paramName: nameof(Placeholder)); | |||||
} | |||||
_placeholder = value; | |||||
} | |||||
> MaxPlaceholderLength => throw new ArgumentOutOfRangeException(nameof(value), $"Placeholder length must be less or equal to {MaxPlaceholderLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Placeholder length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -708,7 +682,7 @@ namespace Discord | |||||
if (value != null) | if (value != null) | ||||
Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options)); | Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options)); | ||||
else | else | ||||
throw new ArgumentNullException(nameof(value)); | |||||
throw new ArgumentNullException(nameof(value), $"{nameof(Options)} cannot be null."); | |||||
_options = value; | _options = value; | ||||
} | } | ||||
@@ -908,7 +882,7 @@ namespace Discord | |||||
/// The maximum length of a <see cref="SelectMenuOption.Description"/>. | /// The maximum length of a <see cref="SelectMenuOption.Description"/>. | ||||
/// </summary> | /// </summary> | ||||
public const int MaxDescriptionLength = 100; | public const int MaxDescriptionLength = 100; | ||||
/// <summary> | /// <summary> | ||||
/// The maximum length of a <see cref="SelectMenuOption.Value"/>. | /// The maximum length of a <see cref="SelectMenuOption.Value"/>. | ||||
/// </summary> | /// </summary> | ||||
@@ -922,42 +896,28 @@ namespace Discord | |||||
public string Label | public string Label | ||||
{ | { | ||||
get => _label; | get => _label; | ||||
set | |||||
set => _label = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > MaxSelectLabelLength) | |||||
throw new ArgumentException($"Select option label must be {MaxSelectLabelLength} characters or less!", paramName: nameof(Label)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Select option label must be 1 character or more!", paramName: nameof(Label)); | |||||
} | |||||
_label = value; | |||||
} | |||||
> MaxSelectLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxSelectLabelLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Gets or sets the custom id of the current select menu. | |||||
/// Gets or sets the value of the current select menu. | |||||
/// </summary> | /// </summary> | ||||
/// <exception cref="ArgumentException" accessor="set"><see cref="Value"/> length exceeds <see cref="MaxSelectValueLength"/>.</exception> | /// <exception cref="ArgumentException" accessor="set"><see cref="Value"/> length exceeds <see cref="MaxSelectValueLength"/>.</exception> | ||||
/// <exception cref="ArgumentException" accessor="set"><see cref="Value"/> length subceeds 1.</exception> | /// <exception cref="ArgumentException" accessor="set"><see cref="Value"/> length subceeds 1.</exception> | ||||
public string Value | public string Value | ||||
{ | { | ||||
get => _value; | get => _value; | ||||
set | |||||
set => _value = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > MaxSelectValueLength) | |||||
throw new ArgumentException($"Select option value must be {MaxSelectValueLength} characters or less!", paramName: nameof(Label)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("Select option value must be 1 character or more!", paramName: nameof(Label)); | |||||
} | |||||
else | |||||
throw new ArgumentException("Select option value must not be null or empty!", paramName: nameof(Label)); | |||||
_value = value; | |||||
} | |||||
> MaxSelectValueLength => throw new ArgumentOutOfRangeException(nameof(value), $"Value length must be less or equal to {MaxSelectValueLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Value length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -968,18 +928,12 @@ namespace Discord | |||||
public string Description | public string Description | ||||
{ | { | ||||
get => _description; | get => _description; | ||||
set | |||||
set => _description = value?.Length switch | |||||
{ | { | ||||
if (value != null) | |||||
{ | |||||
if (value.Length > MaxDescriptionLength) | |||||
throw new ArgumentException($"The description must be {MaxDescriptionLength} characters or less!", paramName: nameof(Label)); | |||||
if (value.Length < 1) | |||||
throw new ArgumentException("The description must be 1 character or more!", paramName: nameof(Label)); | |||||
} | |||||
_description = value; | |||||
} | |||||
> MaxDescriptionLength => throw new ArgumentOutOfRangeException(nameof(value), $"Description length must be less or equal to {MaxDescriptionLength}."), | |||||
0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."), | |||||
_ => value | |||||
}; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -1,29 +1,23 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Represents a type of a component | |||||
/// Represents a type of a component. | |||||
/// </summary> | /// </summary> | ||||
public enum ComponentType | public enum ComponentType | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// A container for other components | |||||
/// A container for other components. | |||||
/// </summary> | /// </summary> | ||||
ActionRow = 1, | ActionRow = 1, | ||||
/// <summary> | /// <summary> | ||||
/// A clickable button | |||||
/// A clickable button. | |||||
/// </summary> | /// </summary> | ||||
Button = 2, | Button = 2, | ||||
/// <summary> | /// <summary> | ||||
/// A select menu for picking from choices | |||||
/// A select menu for picking from choices. | |||||
/// </summary> | /// </summary> | ||||
SelectMenu = 3, | |||||
SelectMenu = 3 | |||||
} | } | ||||
} | } |
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,8 +1,5 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,9 +1,7 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -30,20 +28,17 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public string Name | public string Name | ||||
{ | { | ||||
get | |||||
{ | |||||
return _name; | |||||
} | |||||
get => _name; | |||||
set | set | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(value, nameof(Name)); | |||||
Preconditions.AtLeast(value.Length, 1, nameof(Name)); | |||||
Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name)); | |||||
Preconditions.NotNullOrEmpty(value, nameof(value)); | |||||
Preconditions.AtLeast(value.Length, 1, nameof(value)); | |||||
Preconditions.AtMost(value.Length, MaxNameLength, nameof(value)); | |||||
// Discord updated the docs, this regex prevents special characters like @!$%(... etc, | // Discord updated the docs, this regex prevents special characters like @!$%(... etc, | ||||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | ||||
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | ||||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!"); | |||||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(value)); | |||||
_name = value; | _name = value; | ||||
} | } | ||||
@@ -55,10 +50,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public string Description | public string Description | ||||
{ | { | ||||
get | |||||
{ | |||||
return _description; | |||||
} | |||||
get => _description; | |||||
set | set | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(value, nameof(Description)); | Preconditions.NotNullOrEmpty(value, nameof(Description)); | ||||
@@ -77,10 +69,7 @@ namespace Discord | |||||
get => _options; | get => _options; | ||||
set | set | ||||
{ | { | ||||
if (value != null) | |||||
if (value.Count > MaxOptionsCount) | |||||
throw new ArgumentException(message: $"Option count must be less than or equal to {MaxOptionsCount}.", paramName: nameof(Options)); | |||||
Preconditions.AtMost(value?.Count ?? 0, MaxOptionsCount, nameof(value)); | |||||
_options = value; | _options = value; | ||||
} | } | ||||
} | } | ||||
@@ -90,9 +79,9 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool DefaultPermission { get; set; } = true; | public bool DefaultPermission { get; set; } = true; | ||||
private string _name { get; set; } | |||||
private string _description { get; set; } | |||||
private List<SlashCommandOptionBuilder> _options { get; set; } | |||||
private string _name; | |||||
private string _description; | |||||
private List<SlashCommandOptionBuilder> _options; | |||||
/// <summary> | /// <summary> | ||||
/// Build the current builder into a <see cref="SlashCommandProperties"/> class. | /// Build the current builder into a <see cref="SlashCommandProperties"/> class. | ||||
@@ -100,11 +89,11 @@ namespace Discord | |||||
/// <returns>A <see cref="SlashCommandProperties"/> that can be used to create slash commands over rest.</returns> | /// <returns>A <see cref="SlashCommandProperties"/> that can be used to create slash commands over rest.</returns> | ||||
public SlashCommandProperties Build() | public SlashCommandProperties Build() | ||||
{ | { | ||||
SlashCommandProperties props = new SlashCommandProperties() | |||||
var props = new SlashCommandProperties | |||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
Description = Description, | Description = Description, | ||||
DefaultPermission = DefaultPermission, | |||||
DefaultPermission = DefaultPermission | |||||
}; | }; | ||||
if (Options != null && Options.Any()) | if (Options != null && Options.Any()) | ||||
@@ -117,7 +106,6 @@ namespace Discord | |||||
} | } | ||||
return props; | return props; | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -163,7 +151,7 @@ namespace Discord | |||||
/// <param name="description">The description of this option.</param> | /// <param name="description">The description of this option.</param> | ||||
/// <param name="required">If this option is required for this command.</param> | /// <param name="required">If this option is required for this command.</param> | ||||
/// <param name="isDefault">If this option is the default option.</param> | /// <param name="isDefault">If this option is the default option.</param> | ||||
/// <param name="isAutocomplete">If this option is set to autocompleate.</param> | |||||
/// <param name="isAutocomplete">If this option is set to autocomplete.</param> | |||||
/// <param name="options">The options of the option to add.</param> | /// <param name="options">The options of the option to add.</param> | ||||
/// <param name="channelTypes">The allowed channel types for this option.</param> | /// <param name="channelTypes">The allowed channel types for this option.</param> | ||||
/// <param name="choices">The choices of this option.</param> | /// <param name="choices">The choices of this option.</param> | ||||
@@ -188,14 +176,10 @@ namespace Discord | |||||
Preconditions.AtMost(description.Length, MaxDescriptionLength, nameof(description)); | Preconditions.AtMost(description.Length, MaxDescriptionLength, nameof(description)); | ||||
// make sure theres only one option with default set to true | // make sure theres only one option with default set to true | ||||
if (isDefault.HasValue && isDefault.Value) | |||||
{ | |||||
if (Options != null) | |||||
if (Options.Any(x => x.Default.HasValue && x.Default.Value)) | |||||
throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); | |||||
} | |||||
if (isDefault == true && Options?.Any(x => x.Default == true) == true) | |||||
throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); | |||||
SlashCommandOptionBuilder option = new SlashCommandOptionBuilder | |||||
var option = new SlashCommandOptionBuilder | |||||
{ | { | ||||
Name = name, | Name = name, | ||||
Description = description, | Description = description, | ||||
@@ -204,8 +188,8 @@ namespace Discord | |||||
Options = options, | Options = options, | ||||
Type = type, | Type = type, | ||||
Autocomplete = isAutocomplete, | Autocomplete = isAutocomplete, | ||||
Choices = choices != null ? new List<ApplicationCommandOptionChoiceProperties>(choices) : null, | |||||
ChannelTypes = channelTypes, | |||||
Choices = (choices ?? Array.Empty<ApplicationCommandOptionChoiceProperties>()).ToList(), | |||||
ChannelTypes = channelTypes | |||||
}; | }; | ||||
return AddOption(option); | return AddOption(option); | ||||
@@ -228,14 +212,12 @@ namespace Discord | |||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option) | public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option) | ||||
{ | { | ||||
if (Options == null) | |||||
Options = new List<SlashCommandOptionBuilder>(); | |||||
Options ??= new List<SlashCommandOptionBuilder>(); | |||||
if (Options.Count >= MaxOptionsCount) | if (Options.Count >= MaxOptionsCount) | ||||
throw new ArgumentOutOfRangeException(nameof(Options), $"Cannot have more than {MaxOptionsCount} options!"); | |||||
throw new InvalidOperationException($"Cannot have more than {MaxOptionsCount} options!"); | |||||
if (option == null) | |||||
throw new ArgumentNullException(nameof(option), "Option cannot be null"); | |||||
Preconditions.NotNull(option, nameof(option)); | |||||
Options.Add(option); | Options.Add(option); | ||||
return this; | return this; | ||||
@@ -251,10 +233,9 @@ namespace Discord | |||||
throw new ArgumentNullException(nameof(options), "Options cannot be null!"); | throw new ArgumentNullException(nameof(options), "Options cannot be null!"); | ||||
if (options.Length == 0) | if (options.Length == 0) | ||||
throw new ArgumentException(nameof(options), "Options cannot be empty!"); | |||||
throw new ArgumentException("Options cannot be empty!", nameof(options)); | |||||
if (Options == null) | |||||
Options = new List<SlashCommandOptionBuilder>(); | |||||
Options ??= new List<SlashCommandOptionBuilder>(); | |||||
if (Options.Count + options.Length > MaxOptionsCount) | if (Options.Count + options.Length > MaxOptionsCount) | ||||
throw new ArgumentOutOfRangeException(nameof(options), $"Cannot have more than {MaxOptionsCount} options!"); | throw new ArgumentOutOfRangeException(nameof(options), $"Cannot have more than {MaxOptionsCount} options!"); | ||||
@@ -290,14 +271,13 @@ namespace Discord | |||||
get => _name; | get => _name; | ||||
set | set | ||||
{ | { | ||||
if (value?.Length > SlashCommandBuilder.MaxNameLength) | |||||
throw new ArgumentException($"Name length must be less than or equal to {SlashCommandBuilder.MaxNameLength}"); | |||||
if (value?.Length < 1) | |||||
throw new ArgumentException("Name length must at least 1 characters in length"); | |||||
if (value != null) | if (value != null) | ||||
{ | |||||
Preconditions.AtLeast(value.Length, 1, nameof(value)); | |||||
Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxNameLength, nameof(value)); | |||||
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) | ||||
throw new ArgumentException("Option name cannot contain any special characters or whitespaces!"); | |||||
throw new ArgumentException("Option name cannot contain any special characters or whitespaces!", nameof(value)); | |||||
} | |||||
_name = value; | _name = value; | ||||
} | } | ||||
@@ -311,10 +291,11 @@ namespace Discord | |||||
get => _description; | get => _description; | ||||
set | set | ||||
{ | { | ||||
if (value?.Length > SlashCommandBuilder.MaxDescriptionLength) | |||||
throw new ArgumentException($"Description length must be less than or equal to {SlashCommandBuilder.MaxDescriptionLength}"); | |||||
if (value?.Length < 1) | |||||
throw new ArgumentException("Description length must at least 1 character in length"); | |||||
if (value != null) | |||||
{ | |||||
Preconditions.AtLeast(value.Length, 1, nameof(value)); | |||||
Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(value)); | |||||
} | |||||
_description = value; | _description = value; | ||||
} | } | ||||
@@ -333,7 +314,7 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets if the option is required. | /// Gets or sets if the option is required. | ||||
/// </summary> | /// </summary> | ||||
public bool? Required { get; set; } = null; | |||||
public bool? Required { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets whether or not this option supports autocomplete. | /// Gets or sets whether or not this option supports autocomplete. | ||||
@@ -364,19 +345,19 @@ namespace Discord | |||||
bool isSubType = Type == ApplicationCommandOptionType.SubCommandGroup; | bool isSubType = Type == ApplicationCommandOptionType.SubCommandGroup; | ||||
if (isSubType && (Options == null || !Options.Any())) | if (isSubType && (Options == null || !Options.Any())) | ||||
throw new ArgumentException(nameof(Options), "SubCommands/SubCommandGroups must have at least one option"); | |||||
throw new InvalidOperationException("SubCommands/SubCommandGroups must have at least one option"); | |||||
if (!isSubType && (Options != null && Options.Any()) && Type != ApplicationCommandOptionType.SubCommand) | |||||
throw new ArgumentException(nameof(Options), $"Cannot have options on {Type} type"); | |||||
if (!isSubType && Options != null && Options.Any() && Type != ApplicationCommandOptionType.SubCommand) | |||||
throw new InvalidOperationException($"Cannot have options on {Type} type"); | |||||
return new ApplicationCommandOptionProperties() | |||||
return new ApplicationCommandOptionProperties | |||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
Description = Description, | Description = Description, | ||||
Default = Default, | Default = Default, | ||||
Required = Required, | Required = Required, | ||||
Type = Type, | Type = Type, | ||||
Options = Options?.Count > 0 ? new List<ApplicationCommandOptionProperties>(Options.Select(x => x.Build())) : null, | |||||
Options = Options?.Count > 0 ? Options.Select(x => x.Build()).ToList() : new List<ApplicationCommandOptionProperties>(), | |||||
Choices = Choices, | Choices = Choices, | ||||
Autocomplete = Autocomplete, | Autocomplete = Autocomplete, | ||||
ChannelTypes = ChannelTypes | ChannelTypes = ChannelTypes | ||||
@@ -416,14 +397,10 @@ namespace Discord | |||||
Preconditions.AtMost(description.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(description)); | Preconditions.AtMost(description.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(description)); | ||||
// make sure theres only one option with default set to true | // make sure theres only one option with default set to true | ||||
if (isDefault) | |||||
{ | |||||
if (Options != null) | |||||
if (Options.Any(x => x.Default.HasValue && x.Default.Value)) | |||||
throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); | |||||
} | |||||
if (isDefault && Options?.Any(x => x.Default == true) == true) | |||||
throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); | |||||
SlashCommandOptionBuilder option = new SlashCommandOptionBuilder | |||||
var option = new SlashCommandOptionBuilder | |||||
{ | { | ||||
Name = name, | Name = name, | ||||
Description = description, | Description = description, | ||||
@@ -432,8 +409,8 @@ namespace Discord | |||||
Autocomplete = isAutocomplete, | Autocomplete = isAutocomplete, | ||||
Options = options, | Options = options, | ||||
Type = type, | Type = type, | ||||
Choices = choices != null ? new List<ApplicationCommandOptionChoiceProperties>(choices) : null, | |||||
ChannelTypes = channelTypes, | |||||
Choices = (choices ?? Array.Empty<ApplicationCommandOptionChoiceProperties>()).ToList(), | |||||
ChannelTypes = channelTypes | |||||
}; | }; | ||||
return AddOption(option); | return AddOption(option); | ||||
@@ -445,14 +422,12 @@ namespace Discord | |||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public SlashCommandOptionBuilder AddOption(SlashCommandOptionBuilder option) | public SlashCommandOptionBuilder AddOption(SlashCommandOptionBuilder option) | ||||
{ | { | ||||
if (Options == null) | |||||
Options = new List<SlashCommandOptionBuilder>(); | |||||
Options ??= new List<SlashCommandOptionBuilder>(); | |||||
if (Options.Count >= SlashCommandBuilder.MaxOptionsCount) | if (Options.Count >= SlashCommandBuilder.MaxOptionsCount) | ||||
throw new ArgumentOutOfRangeException(nameof(Choices), $"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!"); | |||||
throw new InvalidOperationException($"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!"); | |||||
if (option == null) | |||||
throw new ArgumentNullException(nameof(option), "Option cannot be null"); | |||||
Preconditions.NotNull(option, nameof(option)); | |||||
Options.Add(option); | Options.Add(option); | ||||
return this; | return this; | ||||
@@ -466,19 +441,17 @@ namespace Discord | |||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public SlashCommandOptionBuilder AddChoice(string name, int value) | public SlashCommandOptionBuilder AddChoice(string name, int value) | ||||
{ | { | ||||
if (Choices == null) | |||||
Choices = new List<ApplicationCommandOptionChoiceProperties>(); | |||||
Choices ??= new List<ApplicationCommandOptionChoiceProperties>(); | |||||
if (Choices.Count >= MaxChoiceCount) | if (Choices.Count >= MaxChoiceCount) | ||||
throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!"); | |||||
throw new InvalidOperationException($"Cannot add more than {MaxChoiceCount} choices!"); | |||||
if (name == null) | |||||
throw new ArgumentNullException($"{nameof(name)} cannot be null!"); | |||||
Preconditions.NotNull(name, nameof(name)); | |||||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | Preconditions.AtLeast(name.Length, 1, nameof(name)); | ||||
Preconditions.AtMost(name.Length, 100, nameof(name)); | Preconditions.AtMost(name.Length, 100, nameof(name)); | ||||
Choices.Add(new ApplicationCommandOptionChoiceProperties() | |||||
Choices.Add(new ApplicationCommandOptionChoiceProperties | |||||
{ | { | ||||
Name = name, | Name = name, | ||||
Value = value | Value = value | ||||
@@ -495,17 +468,13 @@ namespace Discord | |||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public SlashCommandOptionBuilder AddChoice(string name, string value) | public SlashCommandOptionBuilder AddChoice(string name, string value) | ||||
{ | { | ||||
if (Choices == null) | |||||
Choices = new List<ApplicationCommandOptionChoiceProperties>(); | |||||
Choices ??= new List<ApplicationCommandOptionChoiceProperties>(); | |||||
if (Choices.Count >= MaxChoiceCount) | if (Choices.Count >= MaxChoiceCount) | ||||
throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!"); | |||||
if (name == null) | |||||
throw new ArgumentNullException($"{nameof(name)} cannot be null!"); | |||||
throw new InvalidOperationException($"Cannot add more than {MaxChoiceCount} choices!"); | |||||
if (value == null) | |||||
throw new ArgumentNullException($"{nameof(value)} cannot be null!"); | |||||
Preconditions.NotNull(name, nameof(name)); | |||||
Preconditions.NotNull(value, nameof(value)); | |||||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | Preconditions.AtLeast(name.Length, 1, nameof(name)); | ||||
Preconditions.AtMost(name.Length, 100, nameof(name)); | Preconditions.AtMost(name.Length, 100, nameof(name)); | ||||
@@ -513,7 +482,7 @@ namespace Discord | |||||
Preconditions.AtLeast(value.Length, 1, nameof(value)); | Preconditions.AtLeast(value.Length, 1, nameof(value)); | ||||
Preconditions.AtMost(value.Length, 100, nameof(value)); | Preconditions.AtMost(value.Length, 100, nameof(value)); | ||||
Choices.Add(new ApplicationCommandOptionChoiceProperties() | |||||
Choices.Add(new ApplicationCommandOptionChoiceProperties | |||||
{ | { | ||||
Name = name, | Name = name, | ||||
Value = value | Value = value | ||||
@@ -523,14 +492,13 @@ namespace Discord | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Adds a channnel type to the current option. | |||||
/// Adds a channel type to the current option. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="channelType">The <see cref="ChannelType"/> to add.</param> | /// <param name="channelType">The <see cref="ChannelType"/> to add.</param> | ||||
/// <returns>The current builder.</returns> | /// <returns>The current builder.</returns> | ||||
public SlashCommandOptionBuilder AddChannelType(ChannelType channelType) | public SlashCommandOptionBuilder AddChannelType(ChannelType channelType) | ||||
{ | { | ||||
if (ChannelTypes == null) | |||||
ChannelTypes = new List<ChannelType>(); | |||||
ChannelTypes ??= new List<ChannelType>(); | |||||
ChannelTypes.Add(channelType); | ChannelTypes.Add(channelType); | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,15 +1,25 @@ | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> Defines the types of formats for stickers. </summary> | |||||
/// <summary> | |||||
/// Defines the types of formats for stickers. | |||||
/// </summary> | |||||
public enum StickerFormatType | public enum StickerFormatType | ||||
{ | { | ||||
/// <summary> Default value for a sticker format type. </summary> | |||||
/// <summary> | |||||
/// Default value for a sticker format type. | |||||
/// </summary> | |||||
None = 0, | None = 0, | ||||
/// <summary> The sticker format type is png. </summary> | |||||
/// <summary> | |||||
/// The sticker format type is png. | |||||
/// </summary> | |||||
Png = 1, | Png = 1, | ||||
/// <summary> The sticker format type is apng. </summary> | |||||
/// <summary> | |||||
/// The sticker format type is apng. | |||||
/// </summary> | |||||
Apng = 2, | Apng = 2, | ||||
/// <summary> The sticker format type is lottie. </summary> | |||||
Lottie = 3, | |||||
/// <summary> | |||||
/// The sticker format type is lottie. | |||||
/// </summary> | |||||
Lottie = 3 | |||||
} | } | ||||
} | } |
@@ -1,8 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -24,18 +20,13 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Converts the current timestamp tag to the string representation supported by discord. | /// Converts the current timestamp tag to the string representation supported by discord. | ||||
/// <para> | /// <para> | ||||
/// If the <see cref="TimestampTag.Time"/> is null then the default 0 will be used. | |||||
/// If the <see cref="Time"/> is null then the default 0 will be used. | |||||
/// </para> | /// </para> | ||||
/// </summary> | /// </summary> | ||||
/// <returns>A string thats compatible in a discord message, ex: <code><t:1625944201:f></code></returns> | |||||
/// <returns>A string that is compatible in a discord message, ex: <code><t:1625944201:f></code></returns> | |||||
public override string ToString() | public override string ToString() | ||||
{ | { | ||||
if (Time == null) | |||||
return $"<t:0:{(char)Style}>"; | |||||
var offset = (DateTimeOffset)this.Time; | |||||
return $"<t:{offset.ToUnixTimeSeconds()}:{(char)Style}>"; | |||||
return $"<t:{((DateTimeOffset)Time).ToUnixTimeSeconds()}:{(char)Style}>"; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -46,7 +37,7 @@ namespace Discord | |||||
/// <returns>The newly create timestamp tag.</returns> | /// <returns>The newly create timestamp tag.</returns> | ||||
public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime) | public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime) | ||||
{ | { | ||||
return new TimestampTag() | |||||
return new TimestampTag | |||||
{ | { | ||||
Style = style, | Style = style, | ||||
Time = time | Time = time | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -18,6 +12,6 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// The target of the permission is a user. | /// The target of the permission is a user. | ||||
/// </summary> | /// </summary> | ||||
User = 2, | |||||
User = 2 | |||||
} | } | ||||
} | } |
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,7 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -1,6 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -57,12 +55,12 @@ namespace Discord | |||||
new StickerFormatType Format { get; } | new StickerFormatType Format { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets whether this guild sticker can be used, may be false due to loss of Server Boosts | |||||
/// Gets whether this guild sticker can be used, may be false due to loss of Server Boosts. | |||||
/// </summary> | /// </summary> | ||||
bool? IsAvailable { get; } | bool? IsAvailable { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the standard sticker's sort order within its pack | |||||
/// Gets the standard sticker's sort order within its pack. | |||||
/// </summary> | /// </summary> | ||||
int? SortOrder { get; } | int? SortOrder { get; } | ||||
/// <summary> | /// <summary> | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,16 +1,12 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Represents a discord sticker pack. | /// Represents a discord sticker pack. | ||||
/// </summary> | /// </summary> | ||||
/// <typeparam name="TSticker">The type of the stickers within the collection</typeparam> | |||||
/// <typeparam name="TSticker">The type of the stickers within the collection.</typeparam> | |||||
public class StickerPack<TSticker> where TSticker : ISticker | public class StickerPack<TSticker> where TSticker : ISticker | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -1,13 +1,7 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Represents a type of sticker | |||||
/// Represents a type of sticker.. | |||||
/// </summary> | /// </summary> | ||||
public enum StickerType | public enum StickerType | ||||
{ | { | ||||
@@ -19,6 +13,6 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Represents a sticker that was created within a guild. | /// Represents a sticker that was created within a guild. | ||||
/// </summary> | /// </summary> | ||||
Guild = 2, | |||||
Guild = 2 | |||||
} | } | ||||
} | } |
@@ -1,8 +1,4 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.Net | namespace Discord.Net | ||||
{ | { | ||||
@@ -2,38 +2,38 @@ using System; | |||||
namespace Discord.Utils | namespace Discord.Utils | ||||
{ | { | ||||
static class UrlValidation | |||||
internal static class UrlValidation | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Not full URL validation right now. Just ensures protocol is present and that it's either http or https | /// Not full URL validation right now. Just ensures protocol is present and that it's either http or https | ||||
/// <see cref="ValidateButton(string)"/> should be used for url buttons | |||||
/// <see cref="ValidateButton(string)"/> should be used for url buttons. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="url">url to validate before sending to Discord.</param> | |||||
/// <param name="url">The URL to validate before sending to Discord.</param> | |||||
/// <exception cref="InvalidOperationException">A URL must include a protocol (http or https).</exception> | /// <exception cref="InvalidOperationException">A URL must include a protocol (http or https).</exception> | ||||
/// <returns>true if url is valid by our standard, false if null, throws an error upon invalid </returns> | |||||
/// <returns>true if URL is valid by our standard, false if null, throws an error upon invalid.</returns> | |||||
public static bool Validate(string url) | public static bool Validate(string url) | ||||
{ | { | ||||
if (string.IsNullOrEmpty(url)) | if (string.IsNullOrEmpty(url)) | ||||
return false; | return false; | ||||
if(!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))) | |||||
if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))) | |||||
throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP or HTTPS)"); | throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP or HTTPS)"); | ||||
return true; | return true; | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Not full URL validation right now. Just Ensures the protocol is either http, https, or discord | /// Not full URL validation right now. Just Ensures the protocol is either http, https, or discord | ||||
/// <see cref="Validate(string)"/> should be used everything other than url buttons | |||||
/// <see cref="Validate(string)"/> should be used everything other than url buttons. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="url">the url to validate before sending to discord</param> | |||||
/// <param name="url">The URL to validate before sending to discord.</param> | |||||
/// <exception cref="InvalidOperationException">A URL must include a protocol (either http, https, or discord).</exception> | /// <exception cref="InvalidOperationException">A URL must include a protocol (either http, https, or discord).</exception> | ||||
/// <returns>true if the url is valid by our standard, false if null, throws an error upon invalid</returns> | |||||
/// <returns>true if the URL is valid by our standard, false if null, throws an error upon invalid.</returns> | |||||
public static bool ValidateButton(string url) | public static bool ValidateButton(string url) | ||||
{ | { | ||||
if (string.IsNullOrEmpty(url)) | if (string.IsNullOrEmpty(url)) | ||||
return false; | return false; | ||||
if(!((url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) || | |||||
(url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) || | |||||
(url.StartsWith("discord://", StringComparison.OrdinalIgnoreCase)))) | |||||
if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || | |||||
url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || | |||||
url.StartsWith("discord://", StringComparison.OrdinalIgnoreCase))) | |||||
throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP, HTTPS, or DISCORD)"); | throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP, HTTPS, or DISCORD)"); | ||||
return true; | return true; | ||||
} | } | ||||
@@ -1,10 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using Newtonsoft.Json.Linq; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -26,7 +21,7 @@ namespace Discord.API | |||||
{ | { | ||||
ComponentType.Button => new ButtonComponent(x as Discord.ButtonComponent), | ComponentType.Button => new ButtonComponent(x as Discord.ButtonComponent), | ||||
ComponentType.SelectMenu => new SelectMenuComponent(x as Discord.SelectMenuComponent), | ComponentType.SelectMenu => new SelectMenuComponent(x as Discord.SelectMenuComponent), | ||||
_ => null, | |||||
_ => null | |||||
}; | }; | ||||
}).ToArray(); | }).ToArray(); | ||||
} | } | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,5 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System.Collections.Generic; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -19,6 +18,5 @@ namespace Discord.API | |||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
public ApplicationCommandType Type { get; set; } | public ApplicationCommandType Type { get; set; } | ||||
} | } | ||||
} | } |
@@ -1,5 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System.Collections.Generic; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -40,7 +36,7 @@ namespace Discord.API | |||||
public ApplicationCommandOption(IApplicationCommandOption cmd) | public ApplicationCommandOption(IApplicationCommandOption cmd) | ||||
{ | { | ||||
Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice() | |||||
Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice | |||||
{ | { | ||||
Name = x.Name, | Name = x.Name, | ||||
Value = x.Value | Value = x.Value | ||||
@@ -50,42 +46,28 @@ namespace Discord.API | |||||
ChannelTypes = cmd.ChannelTypes.ToArray(); | ChannelTypes = cmd.ChannelTypes.ToArray(); | ||||
Required = cmd.IsRequired.HasValue | |||||
? cmd.IsRequired.Value | |||||
: Optional<bool>.Unspecified; | |||||
Default = cmd.IsDefault.HasValue | |||||
? cmd.IsDefault.Value | |||||
: Optional<bool>.Unspecified; | |||||
Required = cmd.IsRequired ?? Optional<bool>.Unspecified; | |||||
Default = cmd.IsDefault ?? Optional<bool>.Unspecified; | |||||
Name = cmd.Name; | Name = cmd.Name; | ||||
Type = cmd.Type; | Type = cmd.Type; | ||||
Description = cmd.Description; | Description = cmd.Description; | ||||
} | } | ||||
public ApplicationCommandOption(Discord.ApplicationCommandOptionProperties option) | |||||
public ApplicationCommandOption(ApplicationCommandOptionProperties option) | |||||
{ | { | ||||
Choices = option.Choices != null | |||||
? option.Choices.Select(x => new ApplicationCommandOptionChoice() | |||||
{ | |||||
Name = x.Name, | |||||
Value = x.Value | |||||
}).ToArray() | |||||
: Optional<ApplicationCommandOptionChoice[]>.Unspecified; | |||||
Options = option.Options != null | |||||
? option.Options.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
Required = option.Required.HasValue | |||||
? option.Required.Value | |||||
: Optional<bool>.Unspecified; | |||||
Default = option.Default.HasValue | |||||
? option.Default.Value | |||||
: Optional<bool>.Unspecified; | |||||
ChannelTypes = option.ChannelTypes != null | |||||
? option.ChannelTypes.ToArray() | |||||
: Optional<ChannelType[]>.Unspecified; | |||||
Choices = option.Choices?.Select(x => new ApplicationCommandOptionChoice | |||||
{ | |||||
Name = x.Name, | |||||
Value = x.Value | |||||
}).ToArray() ?? Optional<ApplicationCommandOptionChoice[]>.Unspecified; | |||||
Options = option.Options?.Select(x => new ApplicationCommandOption(x)).ToArray() ?? Optional<ApplicationCommandOption[]>.Unspecified; | |||||
Required = option.Required ?? Optional<bool>.Unspecified; | |||||
Default = option.Default ?? Optional<bool>.Unspecified; | |||||
ChannelTypes = option.ChannelTypes?.ToArray() ?? Optional<ChannelType[]>.Unspecified; | |||||
Name = option.Name; | Name = option.Name; | ||||
Type = option.Type; | Type = option.Type; | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -45,16 +40,16 @@ namespace Discord.API | |||||
{ | { | ||||
if (c.Emote is Emote e) | if (c.Emote is Emote e) | ||||
{ | { | ||||
Emote = new Emoji() | |||||
Emote = new Emoji | |||||
{ | { | ||||
Name = e.Name, | Name = e.Name, | ||||
Animated = e.Animated, | Animated = e.Animated, | ||||
Id = e.Id, | |||||
Id = e.Id | |||||
}; | }; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Emote = new Emoji() | |||||
Emote = new Emoji | |||||
{ | { | ||||
Name = c.Emote.Name | Name = c.Emote.Name | ||||
}; | }; | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -19,6 +14,6 @@ namespace Discord.API | |||||
public ulong GuildId { get; set; } | public ulong GuildId { get; set; } | ||||
[JsonProperty("permissions")] | [JsonProperty("permissions")] | ||||
public API.ApplicationCommandPermissions[] Permissions { get; set; } | |||||
public ApplicationCommandPermissions[] Permissions { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -11,7 +11,7 @@ namespace Discord.API | |||||
public Optional<string> Content { get; set; } | public Optional<string> Content { get; set; } | ||||
[JsonProperty("embeds")] | [JsonProperty("embeds")] | ||||
public Optional<API.Embed[]> Embeds { get; set; } | |||||
public Optional<Embed[]> Embeds { get; set; } | |||||
[JsonProperty("allowed_mentions")] | [JsonProperty("allowed_mentions")] | ||||
public Optional<AllowedMentions> AllowedMentions { get; set; } | public Optional<AllowedMentions> AllowedMentions { get; set; } | ||||
@@ -20,9 +20,9 @@ namespace Discord.API | |||||
public Optional<MessageFlags> Flags { get; set; } | public Optional<MessageFlags> Flags { get; set; } | ||||
[JsonProperty("components")] | [JsonProperty("components")] | ||||
public Optional<API.ActionRowComponent[]> Components { get; set; } | |||||
public Optional<ActionRowComponent[]> Components { get; set; } | |||||
[JsonProperty("choices")] | [JsonProperty("choices")] | ||||
public Optional<API.ApplicationCommandOptionChoice[]> Choices { get; set; } | |||||
public Optional<ApplicationCommandOptionChoice[]> Choices { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -36,23 +31,23 @@ namespace Discord.API | |||||
{ | { | ||||
if (option.Emote is Emote e) | if (option.Emote is Emote e) | ||||
{ | { | ||||
Emoji = new Emoji() | |||||
Emoji = new Emoji | |||||
{ | { | ||||
Name = e.Name, | Name = e.Name, | ||||
Animated = e.Animated, | Animated = e.Animated, | ||||
Id = e.Id, | |||||
Id = e.Id | |||||
}; | }; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Emoji = new Emoji() | |||||
Emoji = new Emoji | |||||
{ | { | ||||
Name = option.Emote.Name | Name = option.Emote.Name | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
Default = option.Default.HasValue ? option.Default.Value : Optional<bool>.Unspecified; | |||||
Default = option.Default ?? Optional<bool>.Unspecified; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -11,7 +11,7 @@ namespace Discord.API | |||||
[JsonProperty("name")] | [JsonProperty("name")] | ||||
public string Name { get; set; } | public string Name { get; set; } | ||||
[JsonProperty("description")] | [JsonProperty("description")] | ||||
public string Desription { get; set; } | |||||
public string Description { get; set; } | |||||
[JsonProperty("tags")] | [JsonProperty("tags")] | ||||
public Optional<string> Tags { get; set; } | public Optional<string> Tags { get; set; } | ||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,9 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -18,7 +14,7 @@ namespace Discord.API | |||||
[JsonProperty("join_timestamp")] | [JsonProperty("join_timestamp")] | ||||
public DateTimeOffset JoinTimestamp { get; set; } | public DateTimeOffset JoinTimestamp { get; set; } | ||||
[JsonProperty("presense")] | |||||
[JsonProperty("presence")] | |||||
public Optional<Presence> Presence { get; set; } | public Optional<Presence> Presence { get; set; } | ||||
[JsonProperty("member")] | [JsonProperty("member")] | ||||
@@ -1,9 +1,5 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API | namespace Discord.API | ||||
{ | { | ||||
@@ -1,10 +1,4 @@ | |||||
using Discord.API; | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -30,7 +24,7 @@ namespace Discord.API.Rest | |||||
{ | { | ||||
Name = name; | Name = name; | ||||
Description = description; | Description = description; | ||||
Options = Optional.Create<ApplicationCommandOption[]>(options); | |||||
Options = Optional.Create(options); | |||||
Type = type; | Type = type; | ||||
} | } | ||||
} | } | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,12 +1,6 @@ | |||||
using Discord.Net.Rest; | using Discord.Net.Rest; | ||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | using System.IO; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
internal class CreateStickerParams | internal class CreateStickerParams | ||||
@@ -30,7 +24,7 @@ namespace Discord.API.Rest | |||||
if (File is FileStream fileStream) | if (File is FileStream fileStream) | ||||
contentType = $"image/{Path.GetExtension(fileStream.Name)}"; | contentType = $"image/{Path.GetExtension(fileStream.Name)}"; | ||||
else if(FileName != null) | |||||
else if (FileName != null) | |||||
contentType = $"image/{Path.GetExtension(FileName)}"; | contentType = $"image/{Path.GetExtension(FileName)}"; | ||||
d["file"] = new MultipartFile(File, FileName ?? "image", contentType.Replace(".", "")); | d["file"] = new MultipartFile(File, FileName ?? "image", contentType.Replace(".", "")); | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -19,7 +14,7 @@ namespace Discord.API.Rest | |||||
public Optional<AllowedMentions> AllowedMentions { get; set; } | public Optional<AllowedMentions> AllowedMentions { get; set; } | ||||
[JsonProperty("components")] | [JsonProperty("components")] | ||||
public Optional<API.ActionRowComponent[]> Components { get; set; } | |||||
public Optional<ActionRowComponent[]> Components { get; set; } | |||||
[JsonProperty("flags")] | [JsonProperty("flags")] | ||||
public Optional<MessageFlags?> Flags { get; set; } | public Optional<MessageFlags?> Flags { get; set; } | ||||
@@ -1,15 +1,9 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
internal class ModifyStageInstanceParams | internal class ModifyStageInstanceParams | ||||
{ | { | ||||
[JsonProperty("topic")] | [JsonProperty("topic")] | ||||
public Optional<string> Topic { get; set; } | public Optional<string> Topic { get; set; } | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Discord; | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
@@ -1,9 +1,4 @@ | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
{ | { | ||||
@@ -194,17 +194,17 @@ namespace Discord.Rest | |||||
}; | }; | ||||
} | } | ||||
public static async Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(BaseDiscordClient client, | |||||
public static async Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommandsAsync(BaseDiscordClient client, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var response = await client.ApiClient.GetGlobalApplicationCommandsAsync(options).ConfigureAwait(false); | var response = await client.ApiClient.GetGlobalApplicationCommandsAsync(options).ConfigureAwait(false); | ||||
if (!response.Any()) | if (!response.Any()) | ||||
return new RestGlobalCommand[0]; | |||||
return Array.Empty<RestGlobalCommand>(); | |||||
return response.Select(x => RestGlobalCommand.Create(client, x)).ToArray(); | return response.Select(x => RestGlobalCommand.Create(client, x)).ToArray(); | ||||
} | } | ||||
public static async Task<RestGlobalCommand> GetGlobalApplicationCommand(BaseDiscordClient client, ulong id, | |||||
public static async Task<RestGlobalCommand> GetGlobalApplicationCommandAsync(BaseDiscordClient client, ulong id, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options); | var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options); | ||||
@@ -212,55 +212,55 @@ namespace Discord.Rest | |||||
return model != null ? RestGlobalCommand.Create(client, model) : null; | return model != null ? RestGlobalCommand.Create(client, model) : null; | ||||
} | } | ||||
public static async Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(BaseDiscordClient client, ulong guildId, | |||||
public static async Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommandsAsync(BaseDiscordClient client, ulong guildId, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var response = await client.ApiClient.GetGuildApplicationCommandsAsync(guildId, options).ConfigureAwait(false); | var response = await client.ApiClient.GetGuildApplicationCommandsAsync(guildId, options).ConfigureAwait(false); | ||||
if (!response.Any()) | if (!response.Any()) | ||||
return new RestGuildCommand[0].ToImmutableArray(); | |||||
return ImmutableArray.Create<RestGuildCommand>(); | |||||
return response.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); | return response.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); | ||||
} | } | ||||
public static async Task<RestGuildCommand> GetGuildApplicationCommand(BaseDiscordClient client, ulong id, ulong guildId, | |||||
public static async Task<RestGuildCommand> GetGuildApplicationCommandAsync(BaseDiscordClient client, ulong id, ulong guildId, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var model = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, id, options); | var model = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, id, options); | ||||
return model != null ? RestGuildCommand.Create(client, model, guildId) : null; | return model != null ? RestGuildCommand.Create(client, model, guildId) : null; | ||||
} | } | ||||
public static async Task<RestGuildCommand> CreateGuildApplicationCommand(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties, | |||||
public static async Task<RestGuildCommand> CreateGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var model = await InteractionHelper.CreateGuildCommand(client, guildId, properties, options); | |||||
var model = await InteractionHelper.CreateGuildCommandAsync(client, guildId, properties, options); | |||||
return RestGuildCommand.Create(client, model, guildId); | return RestGuildCommand.Create(client, model, guildId); | ||||
} | } | ||||
public static async Task<RestGlobalCommand> CreateGlobalApplicationCommand(BaseDiscordClient client, ApplicationCommandProperties properties, | |||||
public static async Task<RestGlobalCommand> CreateGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties properties, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var model = await InteractionHelper.CreateGlobalCommand(client, properties, options); | |||||
var model = await InteractionHelper.CreateGlobalCommandAsync(client, properties, options); | |||||
return RestGlobalCommand.Create(client, model); | return RestGlobalCommand.Create(client, model); | ||||
} | } | ||||
public static async Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalApplicationCommand(BaseDiscordClient client, ApplicationCommandProperties[] properties, | |||||
public static async Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties[] properties, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var models = await InteractionHelper.BulkOverwriteGlobalCommands(client, properties, options); | |||||
var models = await InteractionHelper.BulkOverwriteGlobalCommandsAsync(client, properties, options); | |||||
return models.Select(x => RestGlobalCommand.Create(client, x)).ToImmutableArray(); | return models.Select(x => RestGlobalCommand.Create(client, x)).ToImmutableArray(); | ||||
} | } | ||||
public static async Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildApplicationCommand(BaseDiscordClient client, ulong guildId, | |||||
public static async Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, | |||||
ApplicationCommandProperties[] properties, RequestOptions options = null) | ApplicationCommandProperties[] properties, RequestOptions options = null) | ||||
{ | { | ||||
var models = await InteractionHelper.BulkOverwriteGuildCommands(client, guildId, properties, options); | |||||
var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(client, guildId, properties, options); | |||||
return models.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); | return models.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); | ||||
} | } | ||||
public static Task AddRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) | public static Task AddRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) | ||||
=> client.ApiClient.AddRoleAsync(guildId, userId, roleId, options); | => client.ApiClient.AddRoleAsync(guildId, userId, roleId, options); | ||||
public static Task RemoveRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) | public static Task RemoveRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) | ||||
=> client.ApiClient.RemoveRoleAsync(guildId, userId, roleId, options); | => client.ApiClient.RemoveRoleAsync(guildId, userId, roleId, options); | ||||
#endregion | #endregion | ||||
@@ -534,7 +534,7 @@ namespace Discord.API | |||||
var bucket = new BucketIds(channelId: channelId); | var bucket = new BucketIds(channelId: channelId); | ||||
return await SendAsync<ChannelThreads>("GET", () => $"channels/{channelId}/threads/active", bucket); | |||||
return await SendAsync<ChannelThreads>("GET", () => $"channels/{channelId}/threads/active", bucket, options: options); | |||||
} | } | ||||
public async Task<ChannelThreads> GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) | public async Task<ChannelThreads> GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) | ||||
@@ -609,7 +609,6 @@ namespace Discord.API | |||||
#region Stage | #region Stage | ||||
public async Task<StageInstance> CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) | public async Task<StageInstance> CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) | ||||
{ | { | ||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
var bucket = new BucketIds(); | var bucket = new BucketIds(); | ||||
@@ -110,17 +110,17 @@ namespace Discord.Rest | |||||
=> ClientHelper.GetWebhookAsync(this, id, options); | => ClientHelper.GetWebhookAsync(this, id, options); | ||||
public Task<RestGlobalCommand> CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null) | public Task<RestGlobalCommand> CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null) | ||||
=> ClientHelper.CreateGlobalApplicationCommand(this, properties, options); | |||||
=> ClientHelper.CreateGlobalApplicationCommandAsync(this, properties, options); | |||||
public Task<RestGuildCommand> CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null) | public Task<RestGuildCommand> CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null) | ||||
=> ClientHelper.CreateGuildApplicationCommand(this, guildId, properties, options); | |||||
=> ClientHelper.CreateGuildApplicationCommandAsync(this, guildId, properties, options); | |||||
public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(RequestOptions options = null) | public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(RequestOptions options = null) | ||||
=> ClientHelper.GetGlobalApplicationCommands(this, options); | |||||
=> ClientHelper.GetGlobalApplicationCommandsAsync(this, options); | |||||
public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) | public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) | ||||
=> ClientHelper.GetGuildApplicationCommands(this, guildId, options); | |||||
=> ClientHelper.GetGuildApplicationCommandsAsync(this, guildId, options); | |||||
public Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null) | public Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null) | ||||
=> ClientHelper.BulkOverwriteGlobalApplicationCommand(this, commandProperties, options); | |||||
=> ClientHelper.BulkOverwriteGlobalApplicationCommandAsync(this, commandProperties, options); | |||||
public Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null) | public Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null) | ||||
=> ClientHelper.BulkOverwriteGuildApplicationCommand(this, guildId, commandProperties, options); | |||||
=> ClientHelper.BulkOverwriteGuildApplicationCommandAsync(this, guildId, commandProperties, options); | |||||
public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null) | public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null) | ||||
=> InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); | => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); | ||||
public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) | public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) | ||||
@@ -231,7 +231,7 @@ namespace Discord.Rest | |||||
=> await GetGlobalApplicationCommands(options).ConfigureAwait(false); | => await GetGlobalApplicationCommands(options).ConfigureAwait(false); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IApplicationCommand> IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) | async Task<IApplicationCommand> IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) | ||||
=> await ClientHelper.GetGlobalApplicationCommand(this, id, options).ConfigureAwait(false); | |||||
=> await ClientHelper.GetGlobalApplicationCommandAsync(this, id, options).ConfigureAwait(false); | |||||
#endregion | #endregion | ||||
} | } | ||||
} | } |
@@ -1,9 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.Rest | namespace Discord.Rest | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -28,9 +22,9 @@ namespace Discord.Rest | |||||
internal StageInfo(IUser user, StagePrivacyLevel? level, string topic) | internal StageInfo(IUser user, StagePrivacyLevel? level, string topic) | ||||
{ | { | ||||
this.Topic = topic; | |||||
this.PrivacyLevel = level; | |||||
this.User = user; | |||||
Topic = topic; | |||||
PrivacyLevel = level; | |||||
User = user; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -1,9 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.AuditLog; | using Model = Discord.API.AuditLog; | ||||
using EntryModel = Discord.API.AuditLogEntry; | using EntryModel = Discord.API.AuditLogEntry; | ||||
@@ -1,9 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.AuditLog; | using Model = Discord.API.AuditLog; | ||||
using EntryModel = Discord.API.AuditLogEntry; | using EntryModel = Discord.API.AuditLogEntry; | ||||
@@ -1,8 +1,4 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.AuditLog; | using Model = Discord.API.AuditLog; | ||||
using EntryModel = Discord.API.AuditLogEntry; | using EntryModel = Discord.API.AuditLogEntry; | ||||
@@ -1,10 +1,8 @@ | |||||
using Discord.API; | |||||
using Discord.API.Rest; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.Channel; | using Model = Discord.API.Channel; | ||||
using StageInstance = Discord.API.StageInstance; | |||||
namespace Discord.Rest | namespace Discord.Rest | ||||
{ | { | ||||
@@ -25,12 +23,9 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public bool IsLive { get; private set; } | public bool IsLive { get; private set; } | ||||
internal RestStageChannel(BaseDiscordClient discord, IGuild guild, ulong id) | internal RestStageChannel(BaseDiscordClient discord, IGuild guild, ulong id) | ||||
: base(discord, guild, id) | |||||
{ | |||||
} | |||||
: base(discord, guild, id) { } | |||||
internal static new RestStageChannel Create(BaseDiscordClient discord, IGuild guild, Model model) | |||||
internal new static RestStageChannel Create(BaseDiscordClient discord, IGuild guild, Model model) | |||||
{ | { | ||||
var entity = new RestStageChannel(discord, guild, model.Id); | var entity = new RestStageChannel(discord, guild, model.Id); | ||||
entity.Update(model); | entity.Update(model); | ||||
@@ -65,7 +60,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public async Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null) | public async Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.CreateStageInstanceParams() | |||||
var args = new CreateStageInstanceParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
PrivacyLevel = privacyLevel, | PrivacyLevel = privacyLevel, | ||||
@@ -82,7 +77,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
await Discord.ApiClient.DeleteStageInstanceAsync(Id, options); | await Discord.ApiClient.DeleteStageInstanceAsync(Id, options); | ||||
Update(null, false); | |||||
Update(null); | |||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -98,7 +93,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task RequestToSpeakAsync(RequestOptions options = null) | public Task RequestToSpeakAsync(RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.ModifyVoiceStateParams() | |||||
var args = new ModifyVoiceStateParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
RequestToSpeakTimestamp = DateTimeOffset.UtcNow | RequestToSpeakTimestamp = DateTimeOffset.UtcNow | ||||
@@ -109,7 +104,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task BecomeSpeakerAsync(RequestOptions options = null) | public Task BecomeSpeakerAsync(RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.ModifyVoiceStateParams() | |||||
var args = new ModifyVoiceStateParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
Suppressed = false | Suppressed = false | ||||
@@ -120,7 +115,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task StopSpeakingAsync(RequestOptions options = null) | public Task StopSpeakingAsync(RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.ModifyVoiceStateParams() | |||||
var args = new ModifyVoiceStateParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
Suppressed = true | Suppressed = true | ||||
@@ -131,7 +126,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null) | public Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.ModifyVoiceStateParams() | |||||
var args = new ModifyVoiceStateParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
Suppressed = false | Suppressed = false | ||||
@@ -143,7 +138,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null) | public Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null) | ||||
{ | { | ||||
var args = new API.Rest.ModifyVoiceStateParams() | |||||
var args = new ModifyVoiceStateParams | |||||
{ | { | ||||
ChannelId = Id, | ChannelId = Id, | ||||
Suppressed = true | Suppressed = true | ||||
@@ -2,8 +2,6 @@ using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.IO; | using System.IO; | ||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.Channel; | using Model = Discord.API.Channel; | ||||
@@ -42,10 +40,7 @@ namespace Discord.Rest | |||||
public ulong ParentChannelId { get; private set; } | public ulong ParentChannelId { get; private set; } | ||||
internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id) | internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id) | ||||
: base(discord, guild, id) | |||||
{ | |||||
} | |||||
: base(discord, guild, id) { } | |||||
internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model) | internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model) | ||||
{ | { | ||||
@@ -66,7 +61,6 @@ namespace Discord.Rest | |||||
AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; | AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; | ||||
ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; | ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; | ||||
IsLocked = model.ThreadMetadata.Value.Locked.GetValueOrDefault(false); | IsLocked = model.ThreadMetadata.Value.Locked.GetValueOrDefault(false); | ||||
} | } | ||||
MemberCount = model.MemberCount.GetValueOrDefault(0); | MemberCount = model.MemberCount.GetValueOrDefault(0); | ||||
@@ -110,107 +104,106 @@ namespace Discord.Rest | |||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) | public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) | public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | public override Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | public override Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | public override Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) | public override Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | public override Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | public override Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override OverwritePermissions? GetPermissionOverwrite(IRole role) | public override OverwritePermissions? GetPermissionOverwrite(IRole role) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override OverwritePermissions? GetPermissionOverwrite(IUser user) | public override OverwritePermissions? GetPermissionOverwrite(IUser user) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | public override Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | public override Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) | public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) | public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
/// <remarks> | /// <remarks> | ||||
/// <b>This method is not supported in threads.</b> | /// <b>This method is not supported in threads.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public override IReadOnlyCollection<Overwrite> PermissionOverwrites | public override IReadOnlyCollection<Overwrite> PermissionOverwrites | ||||
=> throw new NotImplementedException(); | |||||
=> throw new NotSupportedException("This method is not supported in threads."); | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public Task JoinAsync(RequestOptions options = null) | public Task JoinAsync(RequestOptions options = null) | ||||
=> Discord.ApiClient.JoinThreadAsync(Id, options); | => Discord.ApiClient.JoinThreadAsync(Id, options); | ||||
@@ -1,8 +1,6 @@ | |||||
using Discord.API.Rest; | using Discord.API.Rest; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.Channel; | using Model = Discord.API.Channel; | ||||
@@ -14,22 +12,22 @@ namespace Discord.Rest | |||||
ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, RequestOptions options = null) | ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, RequestOptions options = null) | ||||
{ | { | ||||
if (autoArchiveDuration == ThreadArchiveDuration.OneWeek && !channel.Guild.Features.Contains("SEVEN_DAY_THREAD_ARCHIVE")) | if (autoArchiveDuration == ThreadArchiveDuration.OneWeek && !channel.Guild.Features.Contains("SEVEN_DAY_THREAD_ARCHIVE")) | ||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the SEVEN_DAY_THREAD_ARCHIVE feature!"); | |||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the SEVEN_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration)); | |||||
if (autoArchiveDuration == ThreadArchiveDuration.ThreeDays && !channel.Guild.Features.Contains("THREE_DAY_THREAD_ARCHIVE")) | if (autoArchiveDuration == ThreadArchiveDuration.ThreeDays && !channel.Guild.Features.Contains("THREE_DAY_THREAD_ARCHIVE")) | ||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the THREE_DAY_THREAD_ARCHIVE feature!"); | |||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the THREE_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration)); | |||||
if (type == ThreadType.PrivateThread && !channel.Guild.Features.Contains("PRIVATE_THREADS")) | if (type == ThreadType.PrivateThread && !channel.Guild.Features.Contains("PRIVATE_THREADS")) | ||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the PRIVATE_THREADS feature!"); | |||||
throw new ArgumentException($"The guild {channel.Guild.Name} does not have the PRIVATE_THREADS feature!", nameof(type)); | |||||
var args = new StartThreadParams() | |||||
var args = new StartThreadParams | |||||
{ | { | ||||
Name = name, | Name = name, | ||||
Duration = autoArchiveDuration, | Duration = autoArchiveDuration, | ||||
Type = type | Type = type | ||||
}; | }; | ||||
Model model = null; | |||||
Model model; | |||||
if (message != null) | if (message != null) | ||||
model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false); | model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false); | ||||
@@ -45,7 +43,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
var args = new TextChannelProperties(); | var args = new TextChannelProperties(); | ||||
func(args); | func(args); | ||||
var apiArgs = new API.Rest.ModifyThreadParams | |||||
var apiArgs = new ModifyThreadParams | |||||
{ | { | ||||
Name = args.Name, | Name = args.Name, | ||||
Archived = args.Archived, | Archived = args.Archived, | ||||
@@ -63,7 +61,7 @@ namespace Discord.Rest | |||||
return users.Select(x => RestThreadUser.Create(client, channel.Guild, x, channel)).ToArray(); | return users.Select(x => RestThreadUser.Create(client, channel.Guild, x, channel)).ToArray(); | ||||
} | } | ||||
public static async Task<RestThreadUser> GetUserAsync(ulong userdId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null) | |||||
=> (await GetUsersAsync(channel, client, options).ConfigureAwait(false)).FirstOrDefault(x => x.Id == userdId); | |||||
public static async Task<RestThreadUser> GetUserAsync(ulong userId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null) | |||||
=> (await GetUsersAsync(channel, client, options).ConfigureAwait(false)).FirstOrDefault(x => x.Id == userId); | |||||
} | } | ||||
} | } |
@@ -922,7 +922,7 @@ namespace Discord.Rest | |||||
/// of application commands found within the guild. | /// of application commands found within the guild. | ||||
/// </returns> | /// </returns> | ||||
public async Task<IReadOnlyCollection<RestGuildCommand>> GetApplicationCommandsAsync (RequestOptions options = null) | public async Task<IReadOnlyCollection<RestGuildCommand>> GetApplicationCommandsAsync (RequestOptions options = null) | ||||
=> await ClientHelper.GetGuildApplicationCommands(Discord, Id, options).ConfigureAwait(false); | |||||
=> await ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, options).ConfigureAwait(false); | |||||
/// <summary> | /// <summary> | ||||
/// Gets an application command within this guild with the specified id. | /// Gets an application command within this guild with the specified id. | ||||
/// </summary> | /// </summary> | ||||
@@ -933,7 +933,7 @@ namespace Discord.Rest | |||||
/// if found, otherwise <see langword="null"/>. | /// if found, otherwise <see langword="null"/>. | ||||
/// </returns> | /// </returns> | ||||
public async Task<RestGuildCommand> GetApplicationCommandAsync(ulong id, RequestOptions options = null) | public async Task<RestGuildCommand> GetApplicationCommandAsync(ulong id, RequestOptions options = null) | ||||
=> await ClientHelper.GetGuildApplicationCommand(Discord, id, Id, options); | |||||
=> await ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options); | |||||
/// <summary> | /// <summary> | ||||
/// Creates an application command within this guild. | /// Creates an application command within this guild. | ||||
/// </summary> | /// </summary> | ||||
@@ -944,7 +944,7 @@ namespace Discord.Rest | |||||
/// </returns> | /// </returns> | ||||
public async Task<RestGuildCommand> CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) | public async Task<RestGuildCommand> CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) | ||||
{ | { | ||||
var model = await InteractionHelper.CreateGuildCommand(Discord, Id, properties, options); | |||||
var model = await InteractionHelper.CreateGuildCommandAsync(Discord, Id, properties, options); | |||||
return RestGuildCommand.Create(Discord, model, Id); | return RestGuildCommand.Create(Discord, model, Id); | ||||
} | } | ||||
@@ -959,7 +959,7 @@ namespace Discord.Rest | |||||
public async Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, | public async Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, | ||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var models = await InteractionHelper.BulkOverwriteGuildCommands(Discord, Id, properties, options); | |||||
var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(Discord, Id, properties, options); | |||||
return models.Select(x => RestGuildCommand.Create(Discord, x, Id)).ToImmutableArray(); | return models.Select(x => RestGuildCommand.Create(Discord, x, Id)).ToImmutableArray(); | ||||
} | } | ||||
@@ -4,6 +4,7 @@ using Discord.Net; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Net; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Rest | namespace Discord.Rest | ||||
@@ -13,15 +14,15 @@ namespace Discord.Rest | |||||
#region InteractionHelper | #region InteractionHelper | ||||
public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) | public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) | ||||
{ | { | ||||
return client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, new CreateApplicationCommandParams[0], options); | |||||
return client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, Array.Empty<CreateApplicationCommandParams>(), options); | |||||
} | } | ||||
public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null) | public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null) | ||||
{ | { | ||||
return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(new CreateApplicationCommandParams[0], options); | |||||
return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty<CreateApplicationCommandParams>(), options); | |||||
} | } | ||||
public static Task SendInteractionResponse(BaseDiscordClient client, InteractionResponse response, | |||||
public static Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response, | |||||
ulong interactionId, string interactionToken, RequestOptions options = null) | ulong interactionId, string interactionToken, RequestOptions options = null) | ||||
{ | { | ||||
return client.ApiClient.CreateInteractionResponseAsync(response, interactionId, interactionToken, options); | return client.ApiClient.CreateInteractionResponseAsync(response, interactionId, interactionToken, options); | ||||
@@ -39,7 +40,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false); | ||||
RestFollowupMessage entity = RestFollowupMessage.Create(client, model, token, channel); | |||||
var entity = RestFollowupMessage.Create(client, model, token, channel); | |||||
return entity; | return entity; | ||||
} | } | ||||
#endregion | #endregion | ||||
@@ -50,22 +51,21 @@ namespace Discord.Rest | |||||
{ | { | ||||
var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options).ConfigureAwait(false); | var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options).ConfigureAwait(false); | ||||
return RestGlobalCommand.Create(client, model); | return RestGlobalCommand.Create(client, model); | ||||
} | } | ||||
public static Task<ApplicationCommand> CreateGlobalCommand<TArg>(BaseDiscordClient client, | |||||
public static Task<ApplicationCommand> CreateGlobalCommandAsync<TArg>(BaseDiscordClient client, | |||||
Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | ||||
{ | { | ||||
var args = Activator.CreateInstance(typeof(TArg)); | var args = Activator.CreateInstance(typeof(TArg)); | ||||
func((TArg)args); | func((TArg)args); | ||||
return CreateGlobalCommand(client, (TArg)args, options); | |||||
return CreateGlobalCommandAsync(client, (TArg)args, options); | |||||
} | } | ||||
public static async Task<ApplicationCommand> CreateGlobalCommand(BaseDiscordClient client, | |||||
public static async Task<ApplicationCommand> CreateGlobalCommandAsync(BaseDiscordClient client, | |||||
ApplicationCommandProperties arg, RequestOptions options = null) | ApplicationCommandProperties arg, RequestOptions options = null) | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | ||||
var model = new CreateApplicationCommandParams() | |||||
var model = new CreateApplicationCommandParams | |||||
{ | { | ||||
Name = arg.Name.Value, | Name = arg.Name.Value, | ||||
Type = arg.Type, | Type = arg.Type, | ||||
@@ -81,25 +81,25 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description.Value; | model.Description = slashProps.Description.Value; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); | return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task<ApplicationCommand[]> BulkOverwriteGlobalCommands(BaseDiscordClient client, | |||||
public static async Task<ApplicationCommand[]> BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client, | |||||
ApplicationCommandProperties[] args, RequestOptions options = null) | ApplicationCommandProperties[] args, RequestOptions options = null) | ||||
{ | { | ||||
Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
var models = new List<CreateApplicationCommandParams>(); | |||||
foreach (var arg in args) | foreach (var arg in args) | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | ||||
var model = new CreateApplicationCommandParams() | |||||
var model = new CreateApplicationCommandParams | |||||
{ | { | ||||
Name = arg.Name.Value, | Name = arg.Name.Value, | ||||
Type = arg.Type, | Type = arg.Type, | ||||
@@ -115,28 +115,28 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description.Value; | model.Description = slashProps.Description.Value; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
models.Add(model); | models.Add(model); | ||||
} | } | ||||
return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false); | |||||
return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false); | |||||
} | } | ||||
public static async Task<IReadOnlyCollection<ApplicationCommand>> BulkOverwriteGuildCommands(BaseDiscordClient client, ulong guildId, | |||||
public static async Task<IReadOnlyCollection<ApplicationCommand>> BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId, | |||||
ApplicationCommandProperties[] args, RequestOptions options = null) | ApplicationCommandProperties[] args, RequestOptions options = null) | ||||
{ | { | ||||
Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
var models = new List<CreateApplicationCommandParams>(); | |||||
foreach (var arg in args) | foreach (var arg in args) | ||||
{ | { | ||||
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | ||||
var model = new CreateApplicationCommandParams() | |||||
var model = new CreateApplicationCommandParams | |||||
{ | { | ||||
Name = arg.Name.Value, | Name = arg.Name.Value, | ||||
Type = arg.Type, | Type = arg.Type, | ||||
@@ -152,8 +152,8 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description.Value; | model.Description = slashProps.Description.Value; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
models.Add(model); | models.Add(model); | ||||
@@ -180,15 +180,15 @@ namespace Discord.Rest | |||||
} | } | ||||
} | } | ||||
public static Task<ApplicationCommand> ModifyGlobalCommand<TArg>(BaseDiscordClient client, IApplicationCommand command, | |||||
public static Task<ApplicationCommand> ModifyGlobalCommandAsync<TArg>(BaseDiscordClient client, IApplicationCommand command, | |||||
Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | ||||
{ | { | ||||
var arg = GetApplicationCommandProperties<TArg>(command); | var arg = GetApplicationCommandProperties<TArg>(command); | ||||
func(arg); | func(arg); | ||||
return ModifyGlobalCommand(client, command, arg, options); | |||||
return ModifyGlobalCommandAsync(client, command, arg, options); | |||||
} | } | ||||
public static async Task<ApplicationCommand> ModifyGlobalCommand(BaseDiscordClient client, IApplicationCommand command, | |||||
public static async Task<ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, | |||||
ApplicationCommandProperties args, RequestOptions options = null) | ApplicationCommandProperties args, RequestOptions options = null) | ||||
{ | { | ||||
if (args.Name.IsSpecified) | if (args.Name.IsSpecified) | ||||
@@ -197,7 +197,7 @@ namespace Discord.Rest | |||||
Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); | Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); | ||||
} | } | ||||
var model = new Discord.API.Rest.ModifyApplicationCommandParams() | |||||
var model = new ModifyApplicationCommandParams | |||||
{ | { | ||||
Name = args.Name, | Name = args.Name, | ||||
DefaultPermission = args.DefaultPermission.IsSpecified | DefaultPermission = args.DefaultPermission.IsSpecified | ||||
@@ -205,7 +205,7 @@ namespace Discord.Rest | |||||
: Optional<bool>.Unspecified | : Optional<bool>.Unspecified | ||||
}; | }; | ||||
if(args is SlashCommandProperties slashProps) | |||||
if (args is SlashCommandProperties slashProps) | |||||
{ | { | ||||
if (slashProps.Description.IsSpecified) | if (slashProps.Description.IsSpecified) | ||||
{ | { | ||||
@@ -222,15 +222,14 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description; | model.Description = slashProps.Description; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task DeleteGlobalCommand(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) | |||||
public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) | |||||
{ | { | ||||
Preconditions.NotNull(command, nameof(command)); | Preconditions.NotNull(command, nameof(command)); | ||||
Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); | Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); | ||||
@@ -240,18 +239,18 @@ namespace Discord.Rest | |||||
#endregion | #endregion | ||||
#region Guild Commands | #region Guild Commands | ||||
public static Task<ApplicationCommand> CreateGuildCommand<TArg>(BaseDiscordClient client, ulong guildId, | |||||
public static Task<ApplicationCommand> CreateGuildCommandAsync<TArg>(BaseDiscordClient client, ulong guildId, | |||||
Action<TArg> func, RequestOptions options) where TArg : ApplicationCommandProperties | Action<TArg> func, RequestOptions options) where TArg : ApplicationCommandProperties | ||||
{ | { | ||||
var args = Activator.CreateInstance(typeof(TArg)); | var args = Activator.CreateInstance(typeof(TArg)); | ||||
func((TArg)args); | func((TArg)args); | ||||
return CreateGuildCommand(client, guildId, (TArg)args, options); | |||||
return CreateGuildCommandAsync(client, guildId, (TArg)args, options); | |||||
} | } | ||||
public static async Task<ApplicationCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, | |||||
public static async Task<ApplicationCommand> CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, | |||||
ApplicationCommandProperties arg, RequestOptions options = null) | ApplicationCommandProperties arg, RequestOptions options = null) | ||||
{ | { | ||||
var model = new CreateApplicationCommandParams() | |||||
var model = new CreateApplicationCommandParams | |||||
{ | { | ||||
Name = arg.Name.Value, | Name = arg.Name.Value, | ||||
Type = arg.Type, | Type = arg.Type, | ||||
@@ -267,25 +266,25 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description.Value; | model.Description = slashProps.Description.Value; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); | return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); | ||||
} | } | ||||
public static Task<ApplicationCommand> ModifyGuildCommand<TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId, | |||||
public static Task<ApplicationCommand> ModifyGuildCommandAsync<TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId, | |||||
Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | Action<TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties | ||||
{ | { | ||||
var arg = GetApplicationCommandProperties<TArg>(command); | var arg = GetApplicationCommandProperties<TArg>(command); | ||||
func(arg); | func(arg); | ||||
return ModifyGuildCommand(client, command, guildId, arg, options); | |||||
return ModifyGuildCommandAsync(client, command, guildId, arg, options); | |||||
} | } | ||||
public static async Task<ApplicationCommand> ModifyGuildCommand(BaseDiscordClient client, IApplicationCommand command, ulong guildId, | |||||
public static async Task<ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, | |||||
ApplicationCommandProperties arg, RequestOptions options = null) | ApplicationCommandProperties arg, RequestOptions options = null) | ||||
{ | { | ||||
var model = new ModifyApplicationCommandParams() | |||||
var model = new ModifyApplicationCommandParams | |||||
{ | { | ||||
Name = arg.Name, | Name = arg.Name, | ||||
DefaultPermission = arg.DefaultPermission.IsSpecified | DefaultPermission = arg.DefaultPermission.IsSpecified | ||||
@@ -300,14 +299,14 @@ namespace Discord.Rest | |||||
model.Description = slashProps.Description.Value; | model.Description = slashProps.Description.Value; | ||||
model.Options = slashProps.Options.IsSpecified | model.Options = slashProps.Options.IsSpecified | ||||
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | |||||
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; | |||||
? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() | |||||
: Optional<ApplicationCommandOption[]>.Unspecified; | |||||
} | } | ||||
return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task DeleteGuildCommand(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null) | |||||
public static async Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null) | |||||
{ | { | ||||
Preconditions.NotNull(command, nameof(command)); | Preconditions.NotNull(command, nameof(command)); | ||||
Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); | Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); | ||||
@@ -315,21 +314,16 @@ namespace Discord.Rest | |||||
await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); | await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); | ||||
} | } | ||||
public static Task DeleteUnknownApplicationCommand(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null) | |||||
public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null) | |||||
{ | { | ||||
if (guildId.HasValue) | |||||
{ | |||||
return DeleteGuildCommand(client, guildId.Value, command, options); | |||||
} | |||||
else | |||||
{ | |||||
return DeleteGlobalCommand(client, command, options); | |||||
} | |||||
return guildId.HasValue | |||||
? DeleteGuildCommandAsync(client, guildId.Value, command, options) | |||||
: DeleteGlobalCommandAsync(client, command, options); | |||||
} | } | ||||
#endregion | #endregion | ||||
#region Responses | #region Responses | ||||
public static async Task<Discord.API.Message> ModifyFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func, | |||||
public static async Task<Message> ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var args = new MessageProperties(); | var args = new MessageProperties(); | ||||
@@ -359,21 +353,19 @@ namespace Discord.Rest | |||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | ||||
var apiArgs = new API.Rest.ModifyInteractionResponseParams | |||||
var apiArgs = new ModifyInteractionResponseParams | |||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | ||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | ||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | |||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified | |||||
}; | }; | ||||
return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false); | return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task DeleteFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) | |||||
public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) | |||||
=> await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); | => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); | ||||
public static async Task<Message> ModifyInteractionResponse(BaseDiscordClient client, string token, Action<MessageProperties> func, | |||||
public static async Task<Message> ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action<MessageProperties> func, | |||||
RequestOptions options = null) | RequestOptions options = null) | ||||
{ | { | ||||
var args = new MessageProperties(); | var args = new MessageProperties(); | ||||
@@ -415,25 +407,24 @@ namespace Discord.Rest | |||||
return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false); | return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task DeletedInteractionResponse(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) | |||||
public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) | |||||
=> await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); | => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); | ||||
public static Task SendAutocompleteResult(BaseDiscordClient client, IEnumerable<AutocompleteResult> result, ulong interactionId, | |||||
public static Task SendAutocompleteResultAsync(BaseDiscordClient client, IEnumerable<AutocompleteResult> result, ulong interactionId, | |||||
string interactionToken, RequestOptions options) | string interactionToken, RequestOptions options) | ||||
{ | { | ||||
if (result == null) | |||||
result = new AutocompleteResult[0]; | |||||
result ??= Array.Empty<AutocompleteResult>(); | |||||
Preconditions.AtMost(result.Count(), 20, nameof(result), "A maximum of 20 choices are allowed!"); | Preconditions.AtMost(result.Count(), 20, nameof(result), "A maximum of 20 choices are allowed!"); | ||||
var apiArgs = new InteractionResponse() | |||||
var apiArgs = new InteractionResponse | |||||
{ | { | ||||
Type = InteractionResponseType.ApplicationCommandAutocompleteResult, | Type = InteractionResponseType.ApplicationCommandAutocompleteResult, | ||||
Data = new InteractionCallbackData() | |||||
Data = new InteractionCallbackData | |||||
{ | { | ||||
Choices = result.Any() | Choices = result.Any() | ||||
? result.Select(x => new API.ApplicationCommandOptionChoice() { Name = x.Name, Value = x.Value }).ToArray() | |||||
: new ApplicationCommandOptionChoice[0] | |||||
? result.Select(x => new ApplicationCommandOptionChoice { Name = x.Name, Value = x.Value }).ToArray() | |||||
: Array.Empty<ApplicationCommandOptionChoice>() | |||||
} | } | ||||
}; | }; | ||||
@@ -448,7 +439,7 @@ namespace Discord.Rest | |||||
var models = await client.ApiClient.GetGuildApplicationCommandPermissionsAsync(guildId, options); | var models = await client.ApiClient.GetGuildApplicationCommandPermissionsAsync(guildId, options); | ||||
return models.Select(x => | return models.Select(x => | ||||
new GuildApplicationCommandPermission(x.Id, x.ApplicationId, guildId, x.Permissions.Select( | new GuildApplicationCommandPermission(x.Id, x.ApplicationId, guildId, x.Permissions.Select( | ||||
y => new Discord.ApplicationCommandPermission(y.Id, y.Type, y.Permission)) | |||||
y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)) | |||||
.ToArray()) | .ToArray()) | ||||
).ToArray(); | ).ToArray(); | ||||
} | } | ||||
@@ -464,7 +455,7 @@ namespace Discord.Rest | |||||
} | } | ||||
catch (HttpException x) | catch (HttpException x) | ||||
{ | { | ||||
if (x.HttpCode == System.Net.HttpStatusCode.NotFound) | |||||
if (x.HttpCode == HttpStatusCode.NotFound) | |||||
return null; | return null; | ||||
throw; | throw; | ||||
} | } | ||||
@@ -477,11 +468,11 @@ namespace Discord.Rest | |||||
Preconditions.AtMost(args.Length, 10, nameof(args)); | Preconditions.AtMost(args.Length, 10, nameof(args)); | ||||
Preconditions.AtLeast(args.Length, 0, nameof(args)); | Preconditions.AtLeast(args.Length, 0, nameof(args)); | ||||
List<ApplicationCommandPermissions> permissionsList = new List<ApplicationCommandPermissions>(); | |||||
var permissionsList = new List<ApplicationCommandPermissions>(); | |||||
foreach (var arg in args) | foreach (var arg in args) | ||||
{ | { | ||||
var permissions = new ApplicationCommandPermissions() | |||||
var permissions = new ApplicationCommandPermissions | |||||
{ | { | ||||
Id = arg.TargetId, | Id = arg.TargetId, | ||||
Permission = arg.Permission, | Permission = arg.Permission, | ||||
@@ -491,7 +482,7 @@ namespace Discord.Rest | |||||
permissionsList.Add(permissions); | permissionsList.Add(permissions); | ||||
} | } | ||||
ModifyGuildApplicationCommandPermissionsParams model = new ModifyGuildApplicationCommandPermissionsParams() | |||||
var model = new ModifyGuildApplicationCommandPermissionsParams | |||||
{ | { | ||||
Permissions = permissionsList.ToArray() | Permissions = permissionsList.ToArray() | ||||
}; | }; | ||||
@@ -508,16 +499,16 @@ namespace Discord.Rest | |||||
Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
Preconditions.NotEqual(args.Count, 0, nameof(args)); | Preconditions.NotEqual(args.Count, 0, nameof(args)); | ||||
List<ModifyGuildApplicationCommandPermissions> models = new List<ModifyGuildApplicationCommandPermissions>(); | |||||
var models = new List<ModifyGuildApplicationCommandPermissions>(); | |||||
foreach (var arg in args) | foreach (var arg in args) | ||||
{ | { | ||||
Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); | Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); | ||||
var model = new ModifyGuildApplicationCommandPermissions() | |||||
var model = new ModifyGuildApplicationCommandPermissions | |||||
{ | { | ||||
Id = arg.Key, | Id = arg.Key, | ||||
Permissions = arg.Value.Select(x => new ApplicationCommandPermissions() | |||||
Permissions = arg.Value.Select(x => new ApplicationCommandPermissions | |||||
{ | { | ||||
Id = x.TargetId, | Id = x.TargetId, | ||||
Permission = x.Permission, | Permission = x.Permission, | ||||
@@ -2,7 +2,6 @@ using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.ApplicationCommand; | using Model = Discord.API.ApplicationCommand; | ||||
@@ -38,21 +37,13 @@ namespace Discord.Rest | |||||
=> SnowflakeUtils.FromSnowflake(Id); | => SnowflakeUtils.FromSnowflake(Id); | ||||
internal RestApplicationCommand(BaseDiscordClient client, ulong id) | internal RestApplicationCommand(BaseDiscordClient client, ulong id) | ||||
: base(client, id) | |||||
{ | |||||
} | |||||
: base(client, id) { } | |||||
internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong? guildId) | internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong? guildId) | ||||
{ | { | ||||
if (guildId.HasValue) | |||||
{ | |||||
return RestGuildCommand.Create(client, model, guildId.Value); | |||||
} | |||||
else | |||||
{ | |||||
return RestGlobalCommand.Create(client, model); | |||||
} | |||||
return guildId.HasValue | |||||
? RestGuildCommand.Create(client, model, guildId.Value) | |||||
: RestGlobalCommand.Create(client, model); | |||||
} | } | ||||
internal virtual void Update(Model model) | internal virtual void Update(Model model) | ||||
@@ -64,7 +55,7 @@ namespace Discord.Rest | |||||
IsDefaultPermission = model.DefaultPermissions.GetValueOrDefault(true); | IsDefaultPermission = model.DefaultPermissions.GetValueOrDefault(true); | ||||
Options = model.Options.IsSpecified | Options = model.Options.IsSpecified | ||||
? model.Options.Value.Select(x => RestApplicationCommandOption.Create(x)).ToImmutableArray() | |||||
? model.Options.Value.Select(RestApplicationCommandOption.Create).ToImmutableArray() | |||||
: ImmutableArray.Create<RestApplicationCommandOption>(); | : ImmutableArray.Create<RestApplicationCommandOption>(); | ||||
} | } | ||||
@@ -76,7 +67,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
return ModifyAsync<ApplicationCommandProperties>(func, options); | return ModifyAsync<ApplicationCommandProperties>(func, options); | ||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public abstract Task ModifyAsync<TArg>(Action<TArg> func, RequestOptions options = null) | public abstract Task ModifyAsync<TArg>(Action<TArg> func, RequestOptions options = null) | ||||
where TArg : ApplicationCommandProperties; | where TArg : ApplicationCommandProperties; | ||||
@@ -1,8 +1,3 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.ApplicationCommandOptionChoice; | using Model = Discord.API.ApplicationCommandOptionChoice; | ||||
namespace Discord.Rest | namespace Discord.Rest | ||||