Format the project with 'dotnet format' (#2551)

* Sync and Re-Format

* Fix Title string.

* Fix indentation.
This commit is contained in:
NaN
2023-02-13 14:45:59 -03:00
committed by GitHub
parent 71e9ecb21e
commit 257f246d1d
401 changed files with 3178 additions and 2671 deletions

View File

@@ -48,8 +48,8 @@ namespace Discord
{
var result = new Override();
using(var textReader = new StringReader(json))
using(var reader = new JsonTextReader(textReader))
using (var textReader = new StringReader(json))
using (var reader = new JsonTextReader(textReader))
{
var obj = JObject.ReadFrom(reader);
result.Id = obj["id"].ToObject<Guid>();
@@ -100,7 +100,7 @@ namespace Discord
/// Gets a read-only dictionary containing the currently loaded overrides.
/// </summary>
public IReadOnlyDictionary<Override, IReadOnlyCollection<LoadedOverride>> LoadedOverrides
=> _loadedOverrides.Select(x => new KeyValuePair<Override, IReadOnlyCollection<LoadedOverride>> (x.Key, x.Value)).ToDictionary(x => x.Key, x => x.Value);
=> _loadedOverrides.Select(x => new KeyValuePair<Override, IReadOnlyCollection<LoadedOverride>>(x.Key, x.Value)).ToDictionary(x => x.Key, x => x.Value);
private static AssemblyLoadContext _overrideDomain;
private static List<Func<Override, string, Task>> _logEvents = new();
@@ -258,14 +258,14 @@ namespace Discord
private static async Task<Assembly> GetDependencyAsync(Guid id, string name)
{
using(var client = new HttpClient())
using (var client = new HttpClient())
{
var result = await client.PostAsync($"{ApiUrl}/overrides/{id}/dependency", new StringContent($"{{ \"info\": \"{name}\"}}", Encoding.UTF8, "application/json"));
if (!result.IsSuccessStatusCode)
throw new Exception("Failed to get dependency");
using(var ms = new MemoryStream())
using (var ms = new MemoryStream())
{
var innerStream = await result.Content.ReadAsStreamAsync();
await innerStream.CopyToAsync(ms);

View File

@@ -1,8 +1,8 @@
using Discord;
using Discord.WebSocket;
using System;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
namespace BasicBot
{
@@ -112,7 +112,8 @@ namespace BasicBot
if (component.Data.CustomId == "unique-id")
await interaction.RespondAsync("Thank you for clicking my button!");
else Console.WriteLine("An ID has been received that has no handler!");
else
Console.WriteLine("An ID has been received that has no handler!");
}
}
}

View File

@@ -30,7 +30,8 @@ namespace InteractionFramework.Attributes
? Task.FromResult(PreconditionResult.FromSuccess())
: Task.FromResult(PreconditionResult.FromError("User ID does not match component ID!"));
else return Task.FromResult(PreconditionResult.FromError("Parse cannot be done if no userID exists."));
else
return Task.FromResult(PreconditionResult.FromError("Parse cannot be done if no userID exists."));
}
}
}

View File

@@ -10,7 +10,7 @@ namespace InteractionFramework.Attributes
{
public class RequireOwnerAttribute : PreconditionAttribute
{
public override async Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
public override async Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
{
switch (context.Client.TokenType)
{

View File

@@ -26,7 +26,7 @@ namespace InteractionFramework.Modules
// [Summary] lets you customize the name and the description of a parameter
[SlashCommand("echo", "Repeat the input")]
public async Task Echo(string echo, [Summary(description: "mention the user")]bool mention = false)
public async Task Echo(string echo, [Summary(description: "mention the user")] bool mention = false)
=> await RespondAsync(echo + (mention ? Context.User.Mention : string.Empty));
[SlashCommand("ping", "Pings the bot and returns its latency.")]

View File

@@ -64,11 +64,11 @@ namespace InteractionFramework
public static bool IsDebug()
{
#if DEBUG
return true;
#else
return false;
#endif
#if DEBUG
return true;
#else
return false;
#endif
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Discord.Commands;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Discord.Commands;
using System;
using System.Collections.Immutable;
using System.Linq;
namespace Discord.Analyzers
{

View File

@@ -1,6 +1,6 @@
using System;
using Microsoft.CodeAnalysis;
using Discord.Commands;
using Microsoft.CodeAnalysis;
using System;
namespace Discord.Analyzers
{

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Discord.Commands.Builders
{

View File

@@ -20,7 +20,9 @@ namespace Discord.Commands.Builders
public string Name { get; set; }
public string Summary { get; set; }
public string Remarks { get; set; }
public string Group { get => _group;
public string Group
{
get => _group;
set
{
_aliases.Remove(_group);

View File

@@ -1,11 +1,10 @@
using Discord.Commands.Builders;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Discord.Commands.Builders;
namespace Discord.Commands
{
internal static class ModuleClassBuilder

View File

@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
namespace Discord.Commands.Builders
{
public class ParameterBuilder
@@ -25,7 +24,7 @@ namespace Discord.Commands.Builders
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions => _preconditions;
public IReadOnlyList<Attribute> Attributes => _attributes;
#endregion
#endregion
#region Automatic
internal ParameterBuilder(CommandBuilder command)

View File

@@ -1,3 +1,5 @@
using Discord.Commands.Builders;
using Discord.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -6,8 +8,6 @@ using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Discord.Commands.Builders;
using Discord.Logging;
namespace Discord.Commands
{
@@ -653,7 +653,7 @@ namespace Discord.Commands
var bestCandidate = preconditionResults
.OrderByDescending(x => x.Key.Command.Priority)
.FirstOrDefault(x => !x.Value.IsSuccess);
return MatchResult.FromSuccess(bestCandidate.Key,bestCandidate.Value);
return MatchResult.FromSuccess(bestCandidate.Key, bestCandidate.Value);
}
var parseResults = new Dictionary<CommandMatch, ParseResult>();
@@ -685,7 +685,7 @@ namespace Discord.Commands
.Where(x => x.Value.IsSuccess)
.ToArray();
if(successfulParses.Length == 0)
if (successfulParses.Length == 0)
{
var bestMatch = parseResults
.FirstOrDefault(x => !x.Value.IsSuccess);

View File

@@ -45,13 +45,17 @@ namespace Discord.Commands
public static bool HasMentionPrefix(this IUserMessage msg, IUser user, ref int argPos)
{
var text = msg.Content;
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@') return false;
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@')
return false;
int endPos = text.IndexOf('>');
if (endPos == -1) return false;
if (text.Length < endPos + 2 || text[endPos + 1] != ' ') return false; //Must end in "> "
if (endPos == -1)
return false;
if (text.Length < endPos + 2 || text[endPos + 1] != ' ')
return false; //Must end in "> "
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId)) return false;
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId))
return false;
if (userId == user.Id)
{
argPos = endPos + 2;

View File

@@ -1,8 +1,8 @@
using Discord.Commands.Builders;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

View File

@@ -1,8 +1,8 @@
using Discord.Commands.Builders;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Immutable;
using Discord.Commands.Builders;
using System.Linq;
namespace Discord.Commands
{

View File

@@ -1,6 +1,6 @@
using Discord.Commands.Builders;
using System;
using System.Threading.Tasks;
using Discord.Commands.Builders;
namespace Discord.Commands
{

View File

@@ -27,7 +27,7 @@ namespace Discord.Commands
//By Id (0.9)
if (ulong.TryParse(input, NumberStyles.None, CultureInfo.InvariantCulture, out id))
AddResult(results, context.Guild.GetRole(id) as T, 0.90f);
AddResult(results, context.Guild.GetRole(id) as T, 0.90f);
//By Name (0.7-0.8)
foreach (var role in roles.Where(x => string.Equals(input, x.Name, StringComparison.OrdinalIgnoreCase)))

View File

@@ -30,13 +30,13 @@ namespace Discord.Commands
}
public static MatchResult FromSuccess(CommandMatch match, IResult pipeline)
=> new MatchResult(match,pipeline,null, null);
=> new MatchResult(match, pipeline, null, null);
public static MatchResult FromError(CommandError error, string reason)
=> new MatchResult(null,null,error, reason);
=> new MatchResult(null, null, error, reason);
public static MatchResult FromError(Exception ex)
=> FromError(CommandError.Exception, ex.Message);
public static MatchResult FromError(IResult result)
=> new MatchResult(null, null,result.Error, result.ErrorReason);
=> new MatchResult(null, null, result.Error, result.ErrorReason);
public static MatchResult FromError(IResult pipeline, CommandError error, string reason)
=> new MatchResult(null, pipeline, error, reason);

View File

@@ -24,7 +24,7 @@ namespace Discord.Commands
args[i] = GetMember(commands, services, parameters[i].ParameterType, typeInfo);
var obj = InvokeConstructor<T>(constructor, args, typeInfo);
foreach(var property in properties)
foreach (var property in properties)
property.SetValue(obj, GetMember(commands, services, property.PropertyType, typeInfo));
return obj;
};

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -146,10 +146,10 @@ namespace Discord
/// </returns>
public static string GetGuildBannerUrl(ulong guildId, string bannerId, ImageFormat format, ushort? size = null)
{
if (string.IsNullOrEmpty(bannerId))
return null;
string extension = FormatToExtension(format, bannerId);
return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.{extension}" + (size.HasValue ? $"?size={size}" : string.Empty);
if (string.IsNullOrEmpty(bannerId))
return null;
string extension = FormatToExtension(format, bannerId);
return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.{extension}" + (size.HasValue ? $"?size={size}" : string.Empty);
}
/// <summary>
/// Returns an emoji URL.

View File

@@ -175,23 +175,23 @@ namespace Discord
/// </remarks>
internal bool DisplayInitialLog { get; set; } = true;
/// <summary>
/// Gets or sets whether or not rate-limits should use the system clock.
/// </summary>
/// <remarks>
/// If set to <c>false</c>, we will use the X-RateLimit-Reset-After header
/// to determine when a rate-limit expires, rather than comparing the
/// X-RateLimit-Reset timestamp to the system time.
///
/// This should only be changed to false if the system is known to have
/// a clock that is out of sync. Relying on the Reset-After header will
/// incur network lag.
///
/// Regardless of this property, we still rely on the system's wall-clock
/// to determine if a bucket is rate-limited; we do not use any monotonic
/// clock. Your system will still need a stable clock.
/// </remarks>
public bool UseSystemClock { get; set; } = true;
/// <summary>
/// Gets or sets whether or not rate-limits should use the system clock.
/// </summary>
/// <remarks>
/// If set to <c>false</c>, we will use the X-RateLimit-Reset-After header
/// to determine when a rate-limit expires, rather than comparing the
/// X-RateLimit-Reset timestamp to the system time.
///
/// This should only be changed to false if the system is known to have
/// a clock that is out of sync. Relying on the Reset-After header will
/// incur network lag.
///
/// Regardless of this property, we still rely on the system's wall-clock
/// to determine if a bucket is rate-limited; we do not use any monotonic
/// clock. Your system will still need a stable clock.
/// </remarks>
public bool UseSystemClock { get; set; } = true;
/// <summary>
/// Gets or sets whether or not the internal experation check uses the system date

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Discord;

View File

@@ -38,7 +38,7 @@ public class RoleConnectionProperties
get => _platformUsername;
set
{
if(value is not null)
if (value is not null)
Preconditions.AtMost(value.Length, MaxPlatformUsernameLength, nameof(PlatformUsername), $"Platform username length must be less or equal to {MaxPlatformUsernameLength}");
_platformUsername = value;
}
@@ -103,7 +103,7 @@ public class RoleConnectionProperties
internal RoleConnectionProperties AddMetadataRecord(string key, string value)
{
Metadata ??= new Dictionary<string, string>();
if(!Metadata.ContainsKey(key))
if (!Metadata.ContainsKey(key))
Preconditions.AtMost(Metadata.Count + 1, MaxPlatformUsernameLength, nameof(Metadata), $"Metadata records count must be less or equal to {MaxMetadataRecords}");
_metadata[key] = value;
@@ -126,7 +126,7 @@ public class RoleConnectionProperties
/// <summary>
/// Initializes a new instance of <see cref="RoleConnectionProperties"/>.
/// </summary>
public RoleConnectionProperties() {}
public RoleConnectionProperties() { }
/// <summary>
/// Initializes a new <see cref="RoleConnectionProperties"/> with the data from provided <see cref="RoleConnection"/>.

View File

@@ -1,4 +1,4 @@
namespace Discord
namespace Discord
{
/// <summary>
/// Provides properties that are used to modify an <see cref="IAudioChannel" /> with the specified changes.

View File

@@ -172,7 +172,7 @@ namespace Discord
public Task<IThreadChannel> CreatePostWithFileAsync(string title, Stream stream, string filename, ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay,
int? slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, bool isSpoiler = false,
AllowedMentions allowedMentions = null, MessageComponent components = null,
ISticker[] stickers = null, Embed[] embeds = null,MessageFlags flags = MessageFlags.None, ForumTag[] tags = null);
ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null);
/// <summary>
/// Creates a new post (thread) within the forum.

View File

@@ -1,6 +1,6 @@
using System;
using System.Globalization;
using System.Diagnostics;
using System.Globalization;
namespace Discord
{
@@ -44,11 +44,14 @@ namespace Discord
/// <param name="other">The object to compare with the current object.</param>
public override bool Equals(object other)
{
if (other == null) return false;
if (other == this) return true;
if (other == null)
return false;
if (other == this)
return true;
var otherEmote = other as Emote;
if (otherEmote == null) return false;
if (otherEmote == null)
return false;
return Id == otherEmote.Id;
}

View File

@@ -110,8 +110,8 @@ public class ForumTagBuilder
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false, ulong? emoteId = null)
{
Name = name;
if(emoteId is not null)
Emoji = new Emote(emoteId.Value, null, false);
if (emoteId is not null)
Emoji = new Emote(emoteId.Value, null, false);
IsModerated = isModerated;
Id = id;
}
@@ -180,12 +180,12 @@ public class ForumTagBuilder
=> builder is not null &&
Id == builder.Id &&
Name == builder.Name &&
(Emoji is Emoji emoji && builder.Emoji is Emoji otherEmoji && emoji.Equals(otherEmoji) ||
(Emoji is Emoji emoji && builder.Emoji is Emoji otherEmoji && emoji.Equals(otherEmoji) ||
Emoji is Emote emote && builder.Emoji is Emote otherEmote && emote.Equals(otherEmote)) &&
IsModerated == builder.IsModerated;
public static bool operator ==(ForumTagBuilder? left, ForumTagBuilder? right)
=> left?.Equals(right) ?? right is null ;
=> left?.Equals(right) ?? right is null;
public static bool operator !=(ForumTagBuilder? left, ForumTagBuilder? right) => !(left == right);
}

View File

@@ -50,5 +50,5 @@ public class WelcomeScreenChannelProperties : ISnowflakeEntity
/// <param name="channel">A welcome screen channel to modify.</param>
/// <returns>A new instance of <see cref="WelcomeScreenChannelProperties"/>.</returns>
public static WelcomeScreenChannelProperties FromWelcomeScreenChannel(WelcomeScreenChannel channel)
=> new (channel.Id, channel.Description, channel.Emoji);
=> new(channel.Id, channel.Description, channel.Emoji);
}

View File

@@ -34,7 +34,7 @@ namespace Discord
/// <summary>
/// Gets the icon URL of the application.
/// </summary>
string IconUrl { get; }
string IconUrl { get; }
/// <summary>
/// Gets if the bot is public.
/// </summary>

View File

@@ -110,7 +110,7 @@ namespace Discord
{
foreach (var (locale, name) in value)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidOptionName(name);
@@ -134,7 +134,7 @@ namespace Discord
{
foreach (var (locale, description) in value)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidOptionDescription(description);

View File

@@ -49,7 +49,7 @@ namespace Discord
/// <summary>
/// Gets or sets whether or not this command is age restricted.
/// </summary>
public bool IsNsfw{ get; set; } = false;
public bool IsNsfw { get; set; } = false;
/// <summary>
/// Gets or sets the default permission required to use this slash command.
@@ -118,7 +118,7 @@ namespace Discord
foreach (var (locale, name) in nameLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);
@@ -159,7 +159,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public MessageCommandBuilder AddNameLocalization(string locale, string name)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);

View File

@@ -116,7 +116,7 @@ namespace Discord
foreach (var (locale, name) in nameLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);
@@ -157,7 +157,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public UserCommandBuilder AddNameLocalization(string locale, string name)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);

View File

@@ -130,7 +130,7 @@ namespace Discord
async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
{
using(var file = new FileAttachment(fileStream, fileName))
using (var file = new FileAttachment(fileStream, fileName))
{
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
}
@@ -249,7 +249,7 @@ namespace Discord
async Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
{
using(var file = new FileAttachment(fileStream, fileName))
using (var file = new FileAttachment(fileStream, fileName))
{
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
}

View File

@@ -1,4 +1,4 @@
namespace Discord
namespace Discord
{
public enum TextInputStyle
{

View File

@@ -263,6 +263,6 @@ namespace Discord
/// </summary>
/// <returns>A <see cref="ModalComponent"/> representing the builder.</returns>
public ModalComponent Build()
=> new (ActionRows?.Select(x => x.Build()).ToList());
=> new(ActionRows?.Select(x => x.Build()).ToList());
}
}

View File

@@ -312,7 +312,7 @@ namespace Discord
foreach (var (locale, name) in nameLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);
@@ -336,7 +336,7 @@ namespace Discord
foreach (var (locale, description) in descriptionLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandDescription(description);
@@ -355,7 +355,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public SlashCommandBuilder AddNameLocalization(string locale, string name)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandName(name);
@@ -375,7 +375,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public SlashCommandBuilder AddDescriptionLocalization(string locale, string description)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandDescription(description);
@@ -549,7 +549,7 @@ namespace Discord
if (isIntType && MaxValue != null && MaxValue % 1 != 0)
throw new InvalidOperationException("MaxValue cannot have decimals on Integer command options.");
if(isStrType && MinLength is not null && MinLength < 0)
if (isStrType && MinLength is not null && MinLength < 0)
throw new InvalidOperationException("MinLength cannot be smaller than 0.");
if (isStrType && MaxLength is not null && MaxLength < 1)
@@ -627,10 +627,10 @@ namespace Discord
ChannelTypes = channelTypes,
};
if(nameLocalizations is not null)
if (nameLocalizations is not null)
option.WithNameLocalizations(nameLocalizations);
if(descriptionLocalizations is not null)
if (descriptionLocalizations is not null)
option.WithDescriptionLocalizations(descriptionLocalizations);
return AddOption(option);
@@ -749,7 +749,7 @@ namespace Discord
Preconditions.AtLeast(name.Length, 1, nameof(name));
Preconditions.AtMost(name.Length, 100, nameof(name));
if(value is string str)
if (value is string str)
{
Preconditions.AtLeast(str.Length, 1, nameof(value));
Preconditions.AtMost(str.Length, 100, nameof(value));
@@ -904,7 +904,7 @@ namespace Discord
foreach (var (locale, name) in nameLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandOptionName(name);
@@ -928,7 +928,7 @@ namespace Discord
foreach (var (locale, description) in descriptionLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandOptionDescription(description);
@@ -947,7 +947,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public SlashCommandOptionBuilder AddNameLocalization(string locale, string name)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandOptionName(name);
@@ -967,7 +967,7 @@ namespace Discord
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
public SlashCommandOptionBuilder AddDescriptionLocalization(string locale, string description)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
EnsureValidCommandOptionDescription(description);

View File

@@ -17,18 +17,18 @@ namespace Discord
/// It will always be present and does not mean mentions will not be allowed.
/// </note>
/// </remarks>
None = 0,
None = 0,
/// <summary>
/// Controls role mentions.
/// </summary>
Roles = 1,
Roles = 1,
/// <summary>
/// Controls user mentions.
/// </summary>
Users = 2,
Users = 2,
/// <summary>
/// Controls <code>@everyone</code> and <code>@here</code> mentions.
/// </summary>
Everyone = 4,
Everyone = 4,
}
}

View File

@@ -128,7 +128,7 @@ namespace Discord
{
var hash = 17;
hash = hash * 23 + (Type, Title, Description, Timestamp, Color, Image, Video, Author, Footer, Provider, Thumbnail).GetHashCode();
foreach(var field in Fields)
foreach (var field in Fields)
hash = hash * 23 + field.GetHashCode();
return hash;
}

View File

@@ -1,9 +1,9 @@
using Discord.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Discord.Utils;
using Newtonsoft.Json;
namespace Discord
{
@@ -50,7 +50,8 @@ namespace Discord
get => _title;
set
{
if (value?.Length > MaxTitleLength) throw new ArgumentException(message: $"Title length must be less than or equal to {MaxTitleLength}.", paramName: nameof(Title));
if (value?.Length > MaxTitleLength)
throw new ArgumentException(message: $"Title length must be less than or equal to {MaxTitleLength}.", paramName: nameof(Title));
_title = value;
}
}
@@ -63,7 +64,8 @@ namespace Discord
get => _description;
set
{
if (value?.Length > MaxDescriptionLength) throw new ArgumentException(message: $"Description length must be less than or equal to {MaxDescriptionLength}.", paramName: nameof(Description));
if (value?.Length > MaxDescriptionLength)
throw new ArgumentException(message: $"Description length must be less than or equal to {MaxDescriptionLength}.", paramName: nameof(Description));
_description = value;
}
}
@@ -100,8 +102,10 @@ namespace Discord
get => _fields;
set
{
if (value == null) throw new ArgumentNullException(paramName: nameof(Fields), message: "Cannot set an embed builder's fields collection to null.");
if (value.Count > MaxFieldCount) throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(Fields));
if (value == null)
throw new ArgumentNullException(paramName: nameof(Fields), message: "Cannot set an embed builder's fields collection to null.");
if (value.Count > MaxFieldCount)
throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(Fields));
_fields = value;
}
}
@@ -470,7 +474,7 @@ namespace Discord
if (!string.IsNullOrEmpty(Author.IconUrl))
UrlValidation.Validate(Author.IconUrl, true);
}
if(Footer != null)
if (Footer != null)
{
if (!string.IsNullOrEmpty(Footer.IconUrl))
UrlValidation.Validate(Footer.IconUrl, true);
@@ -564,8 +568,10 @@ namespace Discord
get => _name;
set
{
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(message: "Field name must not be null, empty or entirely whitespace.", paramName: nameof(Name));
if (value.Length > MaxFieldNameLength) throw new ArgumentException(message: $"Field name length must be less than or equal to {MaxFieldNameLength}.", paramName: nameof(Name));
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException(message: "Field name must not be null, empty or entirely whitespace.", paramName: nameof(Name));
if (value.Length > MaxFieldNameLength)
throw new ArgumentException(message: $"Field name length must be less than or equal to {MaxFieldNameLength}.", paramName: nameof(Name));
_name = value;
}
}
@@ -587,8 +593,10 @@ namespace Discord
set
{
var stringValue = value?.ToString();
if (string.IsNullOrWhiteSpace(stringValue)) throw new ArgumentException(message: "Field value must not be null or empty.", paramName: nameof(Value));
if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException(message: $"Field value length must be less than or equal to {MaxFieldValueLength}.", paramName: nameof(Value));
if (string.IsNullOrWhiteSpace(stringValue))
throw new ArgumentException(message: "Field value must not be null or empty.", paramName: nameof(Value));
if (stringValue.Length > MaxFieldValueLength)
throw new ArgumentException(message: $"Field value length must be less than or equal to {MaxFieldValueLength}.", paramName: nameof(Value));
_value = stringValue;
}
}
@@ -704,7 +712,8 @@ namespace Discord
get => _name;
set
{
if (value?.Length > MaxAuthorNameLength) throw new ArgumentException(message: $"Author name length must be less than or equal to {MaxAuthorNameLength}.", paramName: nameof(Name));
if (value?.Length > MaxAuthorNameLength)
throw new ArgumentException(message: $"Author name length must be less than or equal to {MaxAuthorNameLength}.", paramName: nameof(Name));
_name = value;
}
}
@@ -836,7 +845,8 @@ namespace Discord
get => _text;
set
{
if (value?.Length > MaxFooterTextLength) throw new ArgumentException(message: $"Footer text length must be less than or equal to {MaxFooterTextLength}.", paramName: nameof(Text));
if (value?.Length > MaxFooterTextLength)
throw new ArgumentException(message: $"Footer text length must be less than or equal to {MaxFooterTextLength}.", paramName: nameof(Text));
_text = value;
}
}

View File

@@ -1,4 +1,4 @@
namespace Discord
namespace Discord
{
public interface ITag
{

View File

@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
namespace Discord
{

View File

@@ -10,105 +10,105 @@ namespace Discord
/// <summary>
/// Allows creation of instant invites.
/// </summary>
CreateInstantInvite = 0x00_00_00_00_01,
CreateInstantInvite = 0x00_00_00_00_01,
/// <summary>
/// Allows management and editing of channels.
/// </summary>
ManageChannels = 0x00_00_00_00_10,
ManageChannels = 0x00_00_00_00_10,
// Text
/// <summary>
/// Allows for the addition of reactions to messages.
/// </summary>
AddReactions = 0x00_00_00_00_40,
AddReactions = 0x00_00_00_00_40,
/// <summary>
/// Allows guild members to view a channel, which includes reading messages in text channels.
/// </summary>
ViewChannel = 0x00_00_00_04_00,
ViewChannel = 0x00_00_00_04_00,
/// <summary>
/// Allows for sending messages in a channel.
/// </summary>
SendMessages = 0x00_00_00_08_00,
SendMessages = 0x00_00_00_08_00,
/// <summary>
/// Allows for sending of text-to-speech messages.
/// </summary>
SendTTSMessages = 0x00_00_00_10_00,
SendTTSMessages = 0x00_00_00_10_00,
/// <summary>
/// Allows for deletion of other users messages.
/// </summary>
ManageMessages = 0x00_00_00_20_00,
ManageMessages = 0x00_00_00_20_00,
/// <summary>
/// Allows links sent by users with this permission will be auto-embedded.
/// </summary>
EmbedLinks = 0x00_00_00_40_00,
EmbedLinks = 0x00_00_00_40_00,
/// <summary>
/// Allows for uploading images and files.
/// </summary>
AttachFiles = 0x00_00_00_80_00,
AttachFiles = 0x00_00_00_80_00,
/// <summary>
/// Allows for reading of message history.
/// </summary>
ReadMessageHistory = 0x00_00_01_00_00,
ReadMessageHistory = 0x00_00_01_00_00,
/// <summary>
/// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all
/// online users in a channel.
/// </summary>
MentionEveryone = 0x00_00_02_00_00,
MentionEveryone = 0x00_00_02_00_00,
/// <summary>
/// Allows the usage of custom emojis from other servers.
/// </summary>
UseExternalEmojis = 0x00_00_04_00_00,
UseExternalEmojis = 0x00_00_04_00_00,
// Voice
/// <summary>
/// Allows for joining of a voice channel.
/// </summary>
Connect = 0x00_00_10_00_00,
Connect = 0x00_00_10_00_00,
/// <summary>
/// Allows for speaking in a voice channel.
/// </summary>
Speak = 0x00_00_20_00_00,
Speak = 0x00_00_20_00_00,
/// <summary>
/// Allows for muting members in a voice channel.
/// </summary>
MuteMembers = 0x00_00_40_00_00,
MuteMembers = 0x00_00_40_00_00,
/// <summary>
/// Allows for deafening of members in a voice channel.
/// </summary>
DeafenMembers = 0x00_00_80_00_00,
DeafenMembers = 0x00_00_80_00_00,
/// <summary>
/// Allows for moving of members between voice channels.
/// </summary>
MoveMembers = 0x00_01_00_00_00,
MoveMembers = 0x00_01_00_00_00,
/// <summary>
/// Allows for using voice-activity-detection in a voice channel.
/// </summary>
UseVAD = 0x00_02_00_00_00,
UseVAD = 0x00_02_00_00_00,
/// <summary>
/// Allows for using priority speaker in a voice channel.
/// </summary>
PrioritySpeaker = 0x00_00_00_01_00,
PrioritySpeaker = 0x00_00_00_01_00,
/// <summary>
/// Allows video streaming in a voice channel.
/// </summary>
Stream = 0x00_00_00_02_00,
Stream = 0x00_00_00_02_00,
// More General
/// <summary>
/// Allows management and editing of roles.
/// </summary>
ManageRoles = 0x00_10_00_00_00,
ManageRoles = 0x00_10_00_00_00,
/// <summary>
/// Allows management and editing of webhooks.
/// </summary>
ManageWebhooks = 0x00_20_00_00_00,
ManageWebhooks = 0x00_20_00_00_00,
/// <summary>
/// Allows management and editing of emojis.
/// </summary>
ManageEmojis = 0x00_40_00_00_00,
ManageEmojis = 0x00_40_00_00_00,
/// <summary>
/// Allows members to use slash commands in text channels.
@@ -118,12 +118,12 @@ namespace Discord
/// <summary>
/// Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.)
/// </summary>
RequestToSpeak = 0x01_00_00_00_00,
RequestToSpeak = 0x01_00_00_00_00,
/// <summary>
/// Allows for deleting and archiving threads, and viewing all private threads
/// </summary>
ManageThreads = 0x04_00_00_00_00,
ManageThreads = 0x04_00_00_00_00,
/// <summary>
/// Allows for creating public threads.

View File

@@ -10,7 +10,7 @@ namespace Discord
/// <summary>
/// Allows creation of instant invites.
/// </summary>
CreateInstantInvite = 0x00_00_00_01,
CreateInstantInvite = 0x00_00_00_01,
/// <summary>
/// Allows kicking members.
/// </summary>
@@ -18,7 +18,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
KickMembers = 0x00_00_00_02,
KickMembers = 0x00_00_00_02,
/// <summary>
/// Allows banning members.
/// </summary>
@@ -26,7 +26,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
BanMembers = 0x00_00_00_04,
BanMembers = 0x00_00_00_04,
/// <summary>
/// Allows all permissions and bypasses channel permission overwrites.
/// </summary>
@@ -34,7 +34,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
Administrator = 0x00_00_00_08,
Administrator = 0x00_00_00_08,
/// <summary>
/// Allows management and editing of channels.
/// </summary>
@@ -42,7 +42,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageChannels = 0x00_00_00_10,
ManageChannels = 0x00_00_00_10,
/// <summary>
/// Allows management and editing of the guild.
/// </summary>
@@ -50,33 +50,33 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageGuild = 0x00_00_00_20,
ManageGuild = 0x00_00_00_20,
/// <summary>
/// Allows for viewing of guild insights
/// </summary>
ViewGuildInsights = 0x00_08_00_00,
ViewGuildInsights = 0x00_08_00_00,
// Text
/// <summary>
/// Allows for the addition of reactions to messages.
/// </summary>
AddReactions = 0x00_00_00_40,
/// <summary>
/// Allows for viewing of audit logs.
/// </summary>
ViewAuditLog = 0x00_00_00_80,
/// <summary>
/// Allows for the addition of reactions to messages.
/// </summary>
AddReactions = 0x00_00_00_40,
/// <summary>
/// Allows for viewing of audit logs.
/// </summary>
ViewAuditLog = 0x00_00_00_80,
/// <summary>
/// Allows guild members to view a channel, which includes reading messages in text channels.
/// </summary>
ViewChannel = 0x00_00_04_00,
ViewChannel = 0x00_00_04_00,
/// <summary>
/// Allows for sending messages in a channel
/// </summary>
SendMessages = 0x00_00_08_00,
/// <summary>
/// Allows for sending of text-to-speech messages.
/// </summary>
SendTTSMessages = 0x00_00_10_00,
SendMessages = 0x00_00_08_00,
/// <summary>
/// Allows for sending of text-to-speech messages.
/// </summary>
SendTTSMessages = 0x00_00_10_00,
/// <summary>
/// Allows for deletion of other users messages.
/// </summary>
@@ -84,55 +84,55 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageMessages = 0x00_00_20_00,
ManageMessages = 0x00_00_20_00,
/// <summary>
/// Allows links sent by users with this permission will be auto-embedded.
/// </summary>
EmbedLinks = 0x00_00_40_00,
EmbedLinks = 0x00_00_40_00,
/// <summary>
/// Allows for uploading images and files.
/// </summary>
AttachFiles = 0x00_00_80_00,
AttachFiles = 0x00_00_80_00,
/// <summary>
/// Allows for reading of message history.
/// </summary>
ReadMessageHistory = 0x00_01_00_00,
ReadMessageHistory = 0x00_01_00_00,
/// <summary>
/// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all
/// online users in a channel.
/// </summary>
MentionEveryone = 0x00_02_00_00,
MentionEveryone = 0x00_02_00_00,
/// <summary>
/// Allows the usage of custom emojis from other servers.
/// </summary>
UseExternalEmojis = 0x00_04_00_00,
UseExternalEmojis = 0x00_04_00_00,
// Voice
/// <summary>
/// Allows for joining of a voice channel.
/// </summary>
Connect = 0x00_10_00_00,
Connect = 0x00_10_00_00,
/// <summary>
/// Allows for speaking in a voice channel.
/// </summary>
Speak = 0x00_20_00_00,
Speak = 0x00_20_00_00,
/// <summary>
/// Allows for muting members in a voice channel.
/// </summary>
MuteMembers = 0x00_40_00_00,
MuteMembers = 0x00_40_00_00,
/// <summary>
/// Allows for deafening of members in a voice channel.
/// </summary>
DeafenMembers = 0x00_80_00_00,
DeafenMembers = 0x00_80_00_00,
/// <summary>
/// Allows for moving of members between voice channels.
/// </summary>
MoveMembers = 0x01_00_00_00,
MoveMembers = 0x01_00_00_00,
/// <summary>
/// Allows for using voice-activity-detection in a voice channel.
/// </summary>
UseVAD = 0x02_00_00_00,
UseVAD = 0x02_00_00_00,
/// <summary>
/// Allows for using priority speaker in a voice channel.
/// </summary>
@@ -140,17 +140,17 @@ namespace Discord
/// <summary>
/// Allows video streaming in a voice channel.
/// </summary>
Stream = 0x00_00_02_00,
Stream = 0x00_00_02_00,
// General 2
/// <summary>
/// Allows for modification of own nickname.
/// </summary>
ChangeNickname = 0x04_00_00_00,
ChangeNickname = 0x04_00_00_00,
/// <summary>
/// Allows for modification of other users nicknames.
/// </summary>
ManageNicknames = 0x08_00_00_00,
ManageNicknames = 0x08_00_00_00,
/// <summary>
/// Allows management and editing of roles.
/// </summary>
@@ -158,7 +158,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageRoles = 0x10_00_00_00,
ManageRoles = 0x10_00_00_00,
/// <summary>
/// Allows management and editing of webhooks.
/// </summary>
@@ -166,7 +166,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageWebhooks = 0x20_00_00_00,
ManageWebhooks = 0x20_00_00_00,
/// <summary>
/// Allows management and editing of emojis and stickers.
/// </summary>
@@ -182,7 +182,7 @@ namespace Discord
/// <summary>
/// Allows for requesting to speak in stage channels.
/// </summary>
RequestToSpeak = 0x01_00_00_00_00,
RequestToSpeak = 0x01_00_00_00_00,
/// <summary>
/// Allows for creating, editing, and deleting guild scheduled events.
/// </summary>
@@ -194,7 +194,7 @@ namespace Discord
/// This permission requires the owner account to use two-factor
/// authentication when used on a guild that has server-wide 2FA enabled.
/// </remarks>
ManageThreads = 0x04_00_00_00_00,
ManageThreads = 0x04_00_00_00_00,
/// <summary>
/// Allows for creating public threads.
/// </summary>
@@ -206,7 +206,7 @@ namespace Discord
/// <summary>
/// Allows the usage of custom stickers from other servers.
/// </summary>
UseExternalStickers = 0x20_00_00_00_00,
UseExternalStickers = 0x20_00_00_00_00,
/// <summary>
/// Allows for sending messages in threads.
/// </summary>

View File

@@ -281,7 +281,7 @@ namespace Discord
manageThreads: manageThreads,
createPublicThreads: createPublicThreads,
createPrivateThreads: createPrivateThreads,
useExternalStickers: useExternalStickers,
useExternalStickers: useExternalStickers,
sendMessagesInThreads: sendMessagesInThreads,
startEmbeddedActivities: startEmbeddedActivities,
moderateMembers: moderateMembers)

View File

@@ -225,7 +225,8 @@ namespace Discord
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
moveMembers, useVoiceActivation, manageRoles, manageWebhooks, prioritySpeaker, stream, useSlashCommands, useApplicationCommands,
requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, usePublicThreads, usePrivateThreads, useExternalStickers,
sendMessagesInThreads, startEmbeddedActivities) { }
sendMessagesInThreads, startEmbeddedActivities)
{ }
/// <summary>
/// Initializes a new <see cref="OverwritePermissions" /> from the current one, changing the provided

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
namespace Discord

View File

@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Discord
{

View File

@@ -34,7 +34,7 @@ namespace Discord.Logging
try
{
if (severity <= Level)
await _messageEvent.InvokeAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false);
await _messageEvent.InvokeAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false);
}
catch
{

View File

@@ -99,7 +99,7 @@ namespace Discord.Net
=> Equals(obj as BucketId);
public override int GetHashCode()
=> IsHashBucket ? (BucketHash, string.Join("/", MajorParameters.Select(x => x.Value))).GetHashCode() : (HttpMethod, Endpoint).GetHashCode();
=> IsHashBucket ? (BucketHash, string.Join("/", MajorParameters.Select(x => x.Value))).GetHashCode() : (HttpMethod, Endpoint).GetHashCode();
public override string ToString()
=> GetBucketHash() ?? GetUniqueEndpoint();

View File

@@ -1,4 +1,4 @@
namespace Discord.Net.Rest
namespace Discord.Net.Rest
{
public delegate IRestClient RestClientProvider(string baseUrl);
}

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Net;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -1,4 +1,4 @@
namespace Discord.Net.Udp
namespace Discord.Net.Udp
{
public delegate IUdpSocket UdpSocketProvider();
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -1,4 +1,4 @@
namespace Discord.Net.WebSockets
namespace Discord.Net.WebSockets
{
public delegate IWebSocketClient WebSocketProvider();
}

View File

@@ -48,17 +48,17 @@ namespace Discord
/// to all actions.
/// </remarks>
public string AuditLogReason { get; set; }
/// <summary>
/// Gets or sets whether or not this request should use the system
/// clock for rate-limiting. Defaults to <c>true</c>.
/// </summary>
/// <remarks>
/// This property can also be set in <see cref="DiscordConfig"/>.
/// On a per-request basis, the system clock should only be disabled
/// when millisecond precision is especially important, and the
/// hosting system is known to have a desynced clock.
/// </remarks>
public bool? UseSystemClock { get; set; }
/// <summary>
/// Gets or sets whether or not this request should use the system
/// clock for rate-limiting. Defaults to <c>true</c>.
/// </summary>
/// <remarks>
/// This property can also be set in <see cref="DiscordConfig"/>.
/// On a per-request basis, the system clock should only be disabled
/// when millisecond precision is especially important, and the
/// hosting system is known to have a desynced clock.
/// </remarks>
public bool? UseSystemClock { get; set; }
/// <summary>
/// Gets or sets the callback to execute regarding ratelimits for this request.

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;

View File

@@ -30,7 +30,7 @@ namespace Discord
public TEntity Value { get; }
private Func<Task<TEntity>> DownloadFunc { get; }
internal Cacheable(TEntity value, TId id, bool hasValue , Func<Task<TEntity>> downloadFunc)
internal Cacheable(TEntity value, TId id, bool hasValue, Func<Task<TEntity>> downloadFunc)
{
Value = value;
Id = id;

View File

@@ -38,9 +38,9 @@ namespace Discord
return (x, y) switch
{
(null, null) => true,
(null, _) => false,
(_, null) => false,
_ => x.Id.Equals(y.Id)
(null, _) => false,
(_, null) => false,
_ => x.Id.Equals(y.Id)
};
}

View File

@@ -161,7 +161,8 @@ namespace Discord
public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
: this(comparer)
{
if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
if (collection == null)
throw new ArgumentNullException(paramName: nameof(collection));
InitializeFromCollection(collection);
}
/// <exception cref="ArgumentNullException">
@@ -170,17 +171,22 @@ namespace Discord
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
: this(concurrencyLevel, DefaultCapacity, false, comparer)
{
if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
if (collection == null)
throw new ArgumentNullException(paramName: nameof(collection));
if (comparer == null)
throw new ArgumentNullException(paramName: nameof(comparer));
InitializeFromCollection(collection);
}
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
: this(concurrencyLevel, capacity, false, comparer) { }
internal ConcurrentHashSet(int concurrencyLevel, int capacity, bool growLockArray, IEqualityComparer<T> comparer)
{
if (concurrencyLevel < 1) throw new ArgumentOutOfRangeException(paramName: nameof(concurrencyLevel));
if (capacity < 0) throw new ArgumentOutOfRangeException(paramName: nameof(capacity));
if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
if (concurrencyLevel < 1)
throw new ArgumentOutOfRangeException(paramName: nameof(concurrencyLevel));
if (capacity < 0)
throw new ArgumentOutOfRangeException(paramName: nameof(capacity));
if (comparer == null)
throw new ArgumentNullException(paramName: nameof(comparer));
if (capacity < concurrencyLevel)
capacity = concurrencyLevel;
@@ -201,7 +207,8 @@ namespace Discord
{
foreach (var value in collection)
{
if (value == null) throw new ArgumentNullException(paramName: "key");
if (value == null)
throw new ArgumentNullException(paramName: "key");
if (!TryAddInternal(value, _comparer.GetHashCode(value), false))
throw new ArgumentException();
@@ -213,7 +220,8 @@ namespace Discord
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
public bool ContainsKey(T value)
{
if (value == null) throw new ArgumentNullException(paramName: "key");
if (value == null)
throw new ArgumentNullException(paramName: "key");
return ContainsKeyInternal(value, _comparer.GetHashCode(value));
}
private bool ContainsKeyInternal(T value, int hashcode)
@@ -237,7 +245,8 @@ namespace Discord
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
public bool TryAdd(T value)
{
if (value == null) throw new ArgumentNullException(paramName: "key");
if (value == null)
throw new ArgumentNullException(paramName: "key");
return TryAddInternal(value, _comparer.GetHashCode(value), true);
}
private bool TryAddInternal(T value, int hashcode, bool acquireLock)
@@ -266,7 +275,8 @@ namespace Discord
}
Volatile.Write(ref tables._buckets[bucketNo], new Node(value, hashcode, tables._buckets[bucketNo]));
checked { tables._countPerLock[lockNo]++; }
checked
{ tables._countPerLock[lockNo]++; }
if (tables._countPerLock[lockNo] > _budget)
resizeDesired = true;
@@ -287,7 +297,8 @@ namespace Discord
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
public bool TryRemove(T value)
{
if (value == null) throw new ArgumentNullException(paramName: "key");
if (value == null)
throw new ArgumentNullException(paramName: "key");
return TryRemoveInternal(value);
}
private bool TryRemoveInternal(T value)
@@ -432,7 +443,8 @@ namespace Discord
newBuckets[newBucketNo] = new Node(current._value, current._hashcode, newBuckets[newBucketNo]);
checked { newCountPerLock[newLockNo]++; }
checked
{ newCountPerLock[newLockNo]++; }
current = next;
}

View File

@@ -136,27 +136,33 @@ namespace Discord
switch (tag.Type)
{
case TagType.UserMention:
if (userHandling == TagHandling.Ignore) continue;
if (userHandling == TagHandling.Ignore)
continue;
newText = ResolveUserMention(tag, userHandling);
break;
case TagType.ChannelMention:
if (channelHandling == TagHandling.Ignore) continue;
if (channelHandling == TagHandling.Ignore)
continue;
newText = ResolveChannelMention(tag, channelHandling);
break;
case TagType.RoleMention:
if (roleHandling == TagHandling.Ignore) continue;
if (roleHandling == TagHandling.Ignore)
continue;
newText = ResolveRoleMention(tag, roleHandling);
break;
case TagType.EveryoneMention:
if (everyoneHandling == TagHandling.Ignore) continue;
if (everyoneHandling == TagHandling.Ignore)
continue;
newText = ResolveEveryoneMention(tag, everyoneHandling);
break;
case TagType.HereMention:
if (everyoneHandling == TagHandling.Ignore) continue;
if (everyoneHandling == TagHandling.Ignore)
continue;
newText = ResolveHereMention(tag, everyoneHandling);
break;
case TagType.Emoji:
if (emojiHandling == TagHandling.Ignore) continue;
if (emojiHandling == TagHandling.Ignore)
continue;
newText = ResolveEmoji(tag, emojiHandling);
break;
}

View File

@@ -36,8 +36,10 @@ namespace Discord
public override bool Equals(object other)
{
if (!IsSpecified) return other == null;
if (other == null) return false;
if (!IsSpecified)
return other == null;
if (other == null)
return false;
return _value.Equals(other);
}
public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0;

View File

@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;

View File

@@ -1,4 +1,4 @@
namespace Discord
namespace Discord
{
internal class PageInfo
{

View File

@@ -147,7 +147,7 @@ namespace Discord
//Give/Take User permissions
perms = channel.GetPermissionOverwrite(user);
if (perms != null)
resolvedPermissions = (resolvedPermissions & ~perms.Value.DenyValue) | perms.Value.AllowValue;
resolvedPermissions = (resolvedPermissions & ~perms.Value.DenyValue) | perms.Value.AllowValue;
if (channel is ITextChannel)
{

View File

@@ -12,8 +12,10 @@ namespace Discord
private static ArgumentNullException CreateNotNullException(string name, string msg)
{
if (msg == null) return new ArgumentNullException(paramName: name);
else return new ArgumentNullException(paramName: name, message: msg);
if (msg == null)
return new ArgumentNullException(paramName: name);
else
return new ArgumentNullException(paramName: name, message: msg);
}
#endregion
@@ -26,8 +28,10 @@ namespace Discord
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
public static void NotNullOrEmpty(string obj, string name, string msg = null)
{
if (obj == null) throw CreateNotNullException(name, msg);
if (obj.Length == 0) throw CreateNotEmptyException(name, msg);
if (obj == null)
throw CreateNotNullException(name, msg);
if (obj.Length == 0)
throw CreateNotEmptyException(name, msg);
}
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
@@ -35,16 +39,20 @@ namespace Discord
{
if (obj.IsSpecified)
{
if (obj.Value == null) throw CreateNotNullException(name, msg);
if (obj.Value.Length == 0) throw CreateNotEmptyException(name, msg);
if (obj.Value == null)
throw CreateNotNullException(name, msg);
if (obj.Value.Length == 0)
throw CreateNotEmptyException(name, msg);
}
}
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
public static void NotNullOrWhitespace(string obj, string name, string msg = null)
{
if (obj == null) throw CreateNotNullException(name, msg);
if (obj.Trim().Length == 0) throw CreateNotEmptyException(name, msg);
if (obj == null)
throw CreateNotNullException(name, msg);
if (obj.Trim().Length == 0)
throw CreateNotEmptyException(name, msg);
}
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
@@ -52,8 +60,10 @@ namespace Discord
{
if (obj.IsSpecified)
{
if (obj.Value == null) throw CreateNotNullException(name, msg);
if (obj.Value.Trim().Length == 0) throw CreateNotEmptyException(name, msg);
if (obj.Value == null)
throw CreateNotNullException(name, msg);
if (obj.Value.Trim().Length == 0)
throw CreateNotEmptyException(name, msg);
}
}
@@ -282,7 +292,8 @@ namespace Discord
var minimum = SnowflakeUtils.ToSnowflake(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(14)));
for (var i = 0; i < collection.Length; i++)
{
if (collection[i] == 0) continue;
if (collection[i] == 0)
continue;
if (collection[i] <= minimum)
throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old.");
}

View File

@@ -19,7 +19,7 @@ namespace Discord.Interactions
/// Specify the target channel types for a <see cref="ApplicationCommandOptionType.Channel"/> option.
/// </summary>
/// <param name="channelTypes">The allowed channel types for this option.</param>
public ChannelTypesAttribute (params ChannelType[] channelTypes)
public ChannelTypesAttribute(params ChannelType[] channelTypes)
{
if (channelTypes is null)
throw new ArgumentNullException(nameof(channelTypes));

View File

@@ -23,7 +23,7 @@ namespace Discord.Interactions
/// </summary>
public object Value { get; }
private ChoiceAttribute (string name)
private ChoiceAttribute(string name)
{
Name = name;
}
@@ -33,7 +33,7 @@ namespace Discord.Interactions
/// </summary>
/// <param name="name">Name of the choice.</param>
/// <param name="value">Predefined value of the choice.</param>
public ChoiceAttribute (string name, string value) : this(name)
public ChoiceAttribute(string name, string value) : this(name)
{
Type = SlashCommandChoiceType.String;
Value = value;
@@ -44,7 +44,7 @@ namespace Discord.Interactions
/// </summary>
/// <param name="name">Name of the choice.</param>
/// <param name="value">Predefined value of the choice.</param>
public ChoiceAttribute (string name, int value) : this(name)
public ChoiceAttribute(string name, int value) : this(name)
{
Type = SlashCommandChoiceType.Integer;
Value = value;
@@ -55,7 +55,7 @@ namespace Discord.Interactions
/// </summary>
/// <param name="name">Name of the choice.</param>
/// <param name="value">Predefined value of the choice.</param>
public ChoiceAttribute (string name, double value) : this(name)
public ChoiceAttribute(string name, double value) : this(name)
{
Type = SlashCommandChoiceType.Number;
Value = value;

View File

@@ -43,7 +43,7 @@ namespace Discord.Interactions
/// <param name="customId">String to compare the Message Component CustomIDs with.</param>
/// <param name="ignoreGroupNames">If <see langword="true"/> <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
/// <param name="runMode">Set the run mode of the command.</param>
public ComponentInteractionAttribute (string customId, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
public ComponentInteractionAttribute(string customId, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
{
CustomId = customId;
IgnoreGroupNames = ignoreGroupNames;

View File

@@ -24,13 +24,13 @@ namespace Discord.Interactions
/// </summary>
public RunMode RunMode { get; }
internal ContextCommandAttribute (string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default)
internal ContextCommandAttribute(string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default)
{
Name = name;
CommandType = commandType;
RunMode = runMode;
}
internal virtual void CheckMethodDefinition (MethodInfo methodInfo) { }
internal virtual void CheckMethodDefinition(MethodInfo methodInfo) { }
}
}

View File

@@ -16,9 +16,9 @@ namespace Discord.Interactions
/// Register a method as a Message Context Command.
/// </summary>
/// <param name="name">Name of the context command.</param>
public MessageCommandAttribute (string name) : base(name, ApplicationCommandType.Message) { }
public MessageCommandAttribute(string name) : base(name, ApplicationCommandType.Message) { }
internal override void CheckMethodDefinition (MethodInfo methodInfo)
internal override void CheckMethodDefinition(MethodInfo methodInfo)
{
var parameters = methodInfo.GetParameters();

View File

@@ -38,7 +38,7 @@ namespace Discord.Interactions
/// <param name="description">Description of the command.</param>
/// <param name="ignoreGroupNames"> If <see langword="true"/>, <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
/// <param name="runMode">Set the run mode of the command.</param>
public SlashCommandAttribute (string name, string description, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
public SlashCommandAttribute(string name, string description, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
{
Name = name;
Description = description;

View File

@@ -16,9 +16,9 @@ namespace Discord.Interactions
/// Register a command as a User Context Command.
/// </summary>
/// <param name="name">Name of this User Context Command.</param>
public UserCommandAttribute (string name) : base(name, ApplicationCommandType.User) { }
public UserCommandAttribute(string name) : base(name, ApplicationCommandType.User) { }
internal override void CheckMethodDefinition (MethodInfo methodInfo)
internal override void CheckMethodDefinition(MethodInfo methodInfo)
{
var parameters = methodInfo.GetParameters();

View File

@@ -18,7 +18,7 @@ namespace Discord.Interactions
/// Set the default permission of a Slash Command.
/// </summary>
/// <param name="isDefaultPermission"><see langword="true"/> if the users are allowed to use this command.</param>
public DefaultPermissionAttribute (bool isDefaultPermission)
public DefaultPermissionAttribute(bool isDefaultPermission)
{
IsDefaultPermission = isDefaultPermission;
}

View File

@@ -26,7 +26,7 @@ namespace Discord.Interactions
/// </summary>
/// <param name="name">Name of the group.</param>
/// <param name="description">Description of the group.</param>
public GroupAttribute (string name, string description)
public GroupAttribute(string name, string description)
{
Name = name;
Description = description;

View File

@@ -28,7 +28,7 @@ namespace Discord.Interactions
/// <param name="parameterInfo">The parameter of the command being checked against.</param>
/// <param name="value">The raw value of the parameter.</param>
/// <param name="services">The service collection used for dependency injection.</param>
public abstract Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, IParameterInfo parameterInfo, object value,
public abstract Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, IParameterInfo parameterInfo, object value,
IServiceProvider services);
}
}

View File

@@ -37,6 +37,6 @@ namespace Discord.Interactions
/// <param name="context">The context of the command.</param>
/// <param name="commandInfo">The command being executed.</param>
/// <param name="services">The service collection used for dependency injection.</param>
public abstract Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services);
public abstract Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services);
}
}

View File

@@ -23,7 +23,7 @@ namespace Discord.Interactions
/// </summary>
/// <param name="name">Name of the parameter.</param>
/// <param name="description">Description of the parameter.</param>
public SummaryAttribute (string name = null, string description = null)
public SummaryAttribute(string name = null, string description = null)
{
Name = name;
Description = description;

View File

@@ -53,7 +53,7 @@ namespace Discord.Interactions.Builders
/// <inheritdoc/>
IReadOnlyList<IParameterBuilder> ICommandBuilder.Parameters => Parameters;
internal CommandBuilder (ModuleBuilder module)
internal CommandBuilder(ModuleBuilder module)
{
_attributes = new List<Attribute>();
_preconditions = new List<PreconditionAttribute>();
@@ -62,7 +62,7 @@ namespace Discord.Interactions.Builders
Module = module;
}
protected CommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : this(module)
protected CommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : this(module)
{
Name = name;
Callback = callback;
@@ -75,7 +75,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithName (string name)
public TBuilder WithName(string name)
{
Name = name;
return Instance;
@@ -88,7 +88,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithMethodName (string name)
public TBuilder WithMethodName(string name)
{
MethodName = name;
return Instance;
@@ -101,7 +101,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithAttributes (params Attribute[] attributes)
public TBuilder WithAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
return Instance;
@@ -114,7 +114,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder SetRunMode (RunMode runMode)
public TBuilder SetRunMode(RunMode runMode)
{
RunMode = runMode;
return Instance;
@@ -127,7 +127,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithNameAsRegex (bool value)
public TBuilder WithNameAsRegex(bool value)
{
TreatNameAsRegex = value;
return Instance;
@@ -140,7 +140,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder AddParameters (params TParamBuilder[] parameters)
public TBuilder AddParameters(params TParamBuilder[] parameters)
{
_parameters.AddRange(parameters);
return Instance;
@@ -153,30 +153,30 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithPreconditions (params PreconditionAttribute[] preconditions)
public TBuilder WithPreconditions(params PreconditionAttribute[] preconditions)
{
_preconditions.AddRange(preconditions);
return Instance;
}
/// <inheritdoc/>
public abstract TBuilder AddParameter (Action<TParamBuilder> configure);
public abstract TBuilder AddParameter(Action<TParamBuilder> configure);
internal abstract TInfo Build (ModuleInfo module, InteractionService commandService);
internal abstract TInfo Build(ModuleInfo module, InteractionService commandService);
//ICommandBuilder
/// <inheritdoc/>
ICommandBuilder ICommandBuilder.WithName (string name) =>
ICommandBuilder ICommandBuilder.WithName(string name) =>
WithName(name);
/// <inheritdoc/>
ICommandBuilder ICommandBuilder.WithMethodName (string name) =>
ICommandBuilder ICommandBuilder.WithMethodName(string name) =>
WithMethodName(name);
ICommandBuilder ICommandBuilder.WithAttributes (params Attribute[] attributes) =>
ICommandBuilder ICommandBuilder.WithAttributes(params Attribute[] attributes) =>
WithAttributes(attributes);
/// <inheritdoc/>
ICommandBuilder ICommandBuilder.SetRunMode (RunMode runMode) =>
ICommandBuilder ICommandBuilder.SetRunMode(RunMode runMode) =>
SetRunMode(runMode);
/// <inheritdoc/>
@@ -184,11 +184,11 @@ namespace Discord.Interactions.Builders
WithNameAsRegex(value);
/// <inheritdoc/>
ICommandBuilder ICommandBuilder.AddParameters (params IParameterBuilder[] parameters) =>
ICommandBuilder ICommandBuilder.AddParameters(params IParameterBuilder[] parameters) =>
AddParameters(parameters as TParamBuilder);
/// <inheritdoc/>
ICommandBuilder ICommandBuilder.WithPreconditions (params PreconditionAttribute[] preconditions) =>
ICommandBuilder ICommandBuilder.WithPreconditions(params PreconditionAttribute[] preconditions) =>
WithPreconditions(preconditions);
}
}

View File

@@ -9,7 +9,7 @@ namespace Discord.Interactions.Builders
{
protected override ComponentCommandBuilder Instance => this;
internal ComponentCommandBuilder (ModuleBuilder module) : base(module) { }
internal ComponentCommandBuilder(ModuleBuilder module) : base(module) { }
/// <summary>
/// Initializes a new <see cref="ComponentBuilder"/>.
@@ -17,7 +17,7 @@ namespace Discord.Interactions.Builders
/// <param name="module">Parent module of this command.</param>
/// <param name="name">Name of this command.</param>
/// <param name="callback">Execution callback of this command.</param>
public ComponentCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
public ComponentCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
/// <summary>
/// Adds a command parameter to the parameters collection.
@@ -26,7 +26,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public override ComponentCommandBuilder AddParameter (Action<ComponentCommandParameterBuilder> configure)
public override ComponentCommandBuilder AddParameter(Action<ComponentCommandParameterBuilder> configure)
{
var parameter = new ComponentCommandParameterBuilder(this);
configure(parameter);
@@ -34,7 +34,7 @@ namespace Discord.Interactions.Builders
return this;
}
internal override ComponentCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
internal override ComponentCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
new ComponentCommandInfo(this, module, commandService);
}
}

View File

@@ -35,7 +35,7 @@ namespace Discord.Interactions.Builders
/// </summary>
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
internal ContextCommandBuilder (ModuleBuilder module) : base(module) { }
internal ContextCommandBuilder(ModuleBuilder module) : base(module) { }
/// <summary>
/// Initializes a new <see cref="ContextCommandBuilder"/>.
@@ -43,7 +43,7 @@ namespace Discord.Interactions.Builders
/// <param name="module">Parent module of this command.</param>
/// <param name="name">Name of this command.</param>
/// <param name="callback">Execution callback of this command.</param>
public ContextCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
public ContextCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
/// <summary>
/// Sets <see cref="CommandType"/>.
@@ -52,7 +52,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ContextCommandBuilder SetType (ApplicationCommandType commandType)
public ContextCommandBuilder SetType(ApplicationCommandType commandType)
{
CommandType = commandType;
return this;
@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
/// The builder instance.
/// </returns>
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
public ContextCommandBuilder SetDefaultPermission (bool defaultPermision)
public ContextCommandBuilder SetDefaultPermission(bool defaultPermision)
{
DefaultPermission = defaultPermision;
return this;
@@ -79,7 +79,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public override ContextCommandBuilder AddParameter (Action<CommandParameterBuilder> configure)
public override ContextCommandBuilder AddParameter(Action<CommandParameterBuilder> configure)
{
var parameter = new CommandParameterBuilder(this);
configure(parameter);
@@ -126,7 +126,7 @@ namespace Discord.Interactions.Builders
return this;
}
internal override ContextCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
internal override ContextCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
ContextCommandInfo.Create(this, module, commandService);
}
}

View File

@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder WithName (string name);
ICommandBuilder WithName(string name);
/// <summary>
/// Sets <see cref="MethodName"/>.
@@ -75,7 +75,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder WithMethodName (string name);
ICommandBuilder WithMethodName(string name);
/// <summary>
/// Adds attributes to <see cref="Attributes"/>.
@@ -84,7 +84,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder WithAttributes (params Attribute[] attributes);
ICommandBuilder WithAttributes(params Attribute[] attributes);
/// <summary>
/// Sets <see cref="RunMode"/>.
@@ -93,7 +93,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder SetRunMode (RunMode runMode);
ICommandBuilder SetRunMode(RunMode runMode);
/// <summary>
/// Sets <see cref="TreatNameAsRegex"/>.
@@ -111,7 +111,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder AddParameters (params IParameterBuilder[] parameters);
ICommandBuilder AddParameters(params IParameterBuilder[] parameters);
/// <summary>
/// Adds preconditions to <see cref="Preconditions"/>.
@@ -120,6 +120,6 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
ICommandBuilder WithPreconditions (params PreconditionAttribute[] preconditions);
ICommandBuilder WithPreconditions(params PreconditionAttribute[] preconditions);
}
}

View File

@@ -35,7 +35,7 @@ namespace Discord.Interactions.Builders
/// </summary>
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
internal SlashCommandBuilder (ModuleBuilder module) : base(module) { }
internal SlashCommandBuilder(ModuleBuilder module) : base(module) { }
/// <summary>
/// Initializes a new <see cref="SlashCommandBuilder"/>.
@@ -43,7 +43,7 @@ namespace Discord.Interactions.Builders
/// <param name="module">Parent module of this command.</param>
/// <param name="name">Name of this command.</param>
/// <param name="callback">Execution callback of this command.</param>
public SlashCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
public SlashCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
/// <summary>
/// Sets <see cref="Description"/>.
@@ -52,7 +52,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public SlashCommandBuilder WithDescription (string description)
public SlashCommandBuilder WithDescription(string description)
{
Description = description;
return this;
@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
/// The builder instance.
/// </returns>
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
public SlashCommandBuilder WithDefaultPermission (bool permission)
public SlashCommandBuilder WithDefaultPermission(bool permission)
{
DefaultPermission = permission;
return Instance;
@@ -79,7 +79,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public override SlashCommandBuilder AddParameter (Action<SlashCommandParameterBuilder> configure)
public override SlashCommandBuilder AddParameter(Action<SlashCommandParameterBuilder> configure)
{
var parameter = new SlashCommandParameterBuilder(this);
configure(parameter);
@@ -126,7 +126,7 @@ namespace Discord.Interactions.Builders
return this;
}
internal override SlashCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
internal override SlashCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
new SlashCommandInfo(this, module, commandService);
}
}

View File

@@ -116,7 +116,7 @@ namespace Discord.Interactions.Builders
internal TypeInfo TypeInfo { get; set; }
internal ModuleBuilder (InteractionService interactionService, ModuleBuilder parent = null)
internal ModuleBuilder(InteractionService interactionService, ModuleBuilder parent = null)
{
InteractionService = interactionService;
Parent = parent;
@@ -127,7 +127,7 @@ namespace Discord.Interactions.Builders
_contextCommands = new List<ContextCommandBuilder>();
_componentCommands = new List<ComponentCommandBuilder>();
_autocompleteCommands = new List<AutocompleteCommandBuilder>();
_modalCommands = new List<ModalCommandBuilder> ();
_modalCommands = new List<ModalCommandBuilder>();
_preconditions = new List<PreconditionAttribute>();
}
@@ -137,7 +137,7 @@ namespace Discord.Interactions.Builders
/// <param name="interactionService">The underlying Interaction Service.</param>
/// <param name="name">Name of this module.</param>
/// <param name="parent">Parent module of this sub-module.</param>
public ModuleBuilder (InteractionService interactionService, string name, ModuleBuilder parent = null) : this(interactionService, parent)
public ModuleBuilder(InteractionService interactionService, string name, ModuleBuilder parent = null) : this(interactionService, parent)
{
Name = name;
}
@@ -149,7 +149,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder WithGroupName (string name)
public ModuleBuilder WithGroupName(string name)
{
SlashGroupName = name;
return this;
@@ -162,7 +162,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder WithDescription (string description)
public ModuleBuilder WithDescription(string description)
{
Description = description;
return this;
@@ -176,7 +176,7 @@ namespace Discord.Interactions.Builders
/// The builder instance.
/// </returns>
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
public ModuleBuilder WithDefaultPermission (bool permission)
public ModuleBuilder WithDefaultPermission(bool permission)
{
DefaultPermission = permission;
return this;
@@ -228,7 +228,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddAttributes (params Attribute[] attributes)
public ModuleBuilder AddAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
return this;
@@ -241,7 +241,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddPreconditions (params PreconditionAttribute[] preconditions)
public ModuleBuilder AddPreconditions(params PreconditionAttribute[] preconditions)
{
_preconditions.AddRange(preconditions);
return this;
@@ -254,7 +254,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddSlashCommand (Action<SlashCommandBuilder> configure)
public ModuleBuilder AddSlashCommand(Action<SlashCommandBuilder> configure)
{
var command = new SlashCommandBuilder(this);
configure(command);
@@ -286,7 +286,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddContextCommand (Action<ContextCommandBuilder> configure)
public ModuleBuilder AddContextCommand(Action<ContextCommandBuilder> configure)
{
var command = new ContextCommandBuilder(this);
configure(command);
@@ -318,7 +318,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddComponentCommand (Action<ComponentCommandBuilder> configure)
public ModuleBuilder AddComponentCommand(Action<ComponentCommandBuilder> configure)
{
var command = new ComponentCommandBuilder(this);
configure(command);
@@ -398,7 +398,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder AddModule (Action<ModuleBuilder> configure)
public ModuleBuilder AddModule(Action<ModuleBuilder> configure)
{
var subModule = new ModuleBuilder(InteractionService, this);
configure(subModule);
@@ -406,7 +406,7 @@ namespace Discord.Interactions.Builders
return this;
}
internal ModuleInfo Build (InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
internal ModuleInfo Build(InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
{
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
{

View File

@@ -13,9 +13,9 @@ namespace Discord.Interactions.Builders
public const int MaxCommandDepth = 3;
public static async Task<IEnumerable<TypeInfo>> SearchAsync (Assembly assembly, InteractionService commandService)
public static async Task<IEnumerable<TypeInfo>> SearchAsync(Assembly assembly, InteractionService commandService)
{
static bool IsLoadableModule (TypeInfo info)
static bool IsLoadableModule(TypeInfo info)
{
return info.DeclaredMethods.Any(x => x.GetCustomAttribute<SlashCommandAttribute>() != null);
}
@@ -24,7 +24,7 @@ namespace Discord.Interactions.Builders
foreach (var type in assembly.DefinedTypes)
{
if (( type.IsPublic || type.IsNestedPublic ) && IsValidModuleDefinition(type))
if ((type.IsPublic || type.IsNestedPublic) && IsValidModuleDefinition(type))
{
result.Add(type);
}
@@ -36,7 +36,7 @@ namespace Discord.Interactions.Builders
return result;
}
public static async Task<Dictionary<Type, ModuleInfo>> BuildAsync (IEnumerable<TypeInfo> validTypes, InteractionService commandService,
public static async Task<Dictionary<Type, ModuleInfo>> BuildAsync(IEnumerable<TypeInfo> validTypes, InteractionService commandService,
IServiceProvider services)
{
var topLevelGroups = validTypes.Where(x => x.DeclaringType == null || !IsValidModuleDefinition(x.DeclaringType.GetTypeInfo()));
@@ -62,7 +62,7 @@ namespace Discord.Interactions.Builders
return result;
}
private static void BuildModule (ModuleBuilder builder, TypeInfo typeInfo, InteractionService commandService,
private static void BuildModule(ModuleBuilder builder, TypeInfo typeInfo, InteractionService commandService,
IServiceProvider services)
{
var attributes = typeInfo.GetCustomAttributes();
@@ -130,14 +130,14 @@ namespace Discord.Interactions.Builders
foreach (var method in validInteractions)
builder.AddComponentCommand(x => BuildComponentCommand(x, createInstance, method, commandService, services));
foreach(var method in validAutocompleteCommands)
foreach (var method in validAutocompleteCommands)
builder.AddAutocompleteCommand(x => BuildAutocompleteCommand(x, createInstance, method, commandService, services));
foreach(var method in validModalCommands)
foreach (var method in validModalCommands)
builder.AddModalCommand(x => BuildModalCommand(x, createInstance, method, commandService, services));
}
private static void BuildSubModules (ModuleBuilder parent, IEnumerable<TypeInfo> subModules, IList<TypeInfo> builtTypes, InteractionService commandService,
private static void BuildSubModules(ModuleBuilder parent, IEnumerable<TypeInfo> subModules, IList<TypeInfo> builtTypes, InteractionService commandService,
IServiceProvider services, int slashGroupDepth = 0)
{
foreach (var submodule in subModules.Where(IsValidModuleDefinition))
@@ -158,7 +158,7 @@ namespace Discord.Interactions.Builders
}
}
private static void BuildSlashCommand (SlashCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
private static void BuildSlashCommand(SlashCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
InteractionService commandService, IServiceProvider services)
{
var attributes = methodInfo.GetCustomAttributes();
@@ -212,7 +212,7 @@ namespace Discord.Interactions.Builders
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
}
private static void BuildContextCommand (ContextCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
private static void BuildContextCommand(ContextCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
InteractionService commandService, IServiceProvider services)
{
var attributes = methodInfo.GetCustomAttributes();
@@ -267,7 +267,7 @@ namespace Discord.Interactions.Builders
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
}
private static void BuildComponentCommand (ComponentCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
private static void BuildComponentCommand(ComponentCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
InteractionService commandService, IServiceProvider services)
{
var attributes = methodInfo.GetCustomAttributes();
@@ -312,7 +312,7 @@ namespace Discord.Interactions.Builders
builder.MethodName = methodInfo.Name;
foreach(var attribute in attributes)
foreach (var attribute in attributes)
{
switch (attribute)
{
@@ -383,13 +383,13 @@ namespace Discord.Interactions.Builders
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
}
private static ExecuteCallback CreateCallback (Func<IServiceProvider, IInteractionModuleBase> createInstance,
private static ExecuteCallback CreateCallback(Func<IServiceProvider, IInteractionModuleBase> createInstance,
MethodInfo methodInfo, InteractionService commandService)
{
Func<IInteractionModuleBase, object[], Task> commandInvoker = commandService._useCompiledLambda ?
ReflectionUtils<IInteractionModuleBase>.CreateMethodInvoker(methodInfo) : (module, args) => methodInfo.Invoke(module, args) as Task;
async Task<IResult> ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo)
async Task<IResult> ExecuteCallback(IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo)
{
var instance = createInstance(serviceProvider);
instance.SetContext(context);
@@ -420,7 +420,7 @@ namespace Discord.Interactions.Builders
{
await instance.AfterExecuteAsync(commandInfo).ConfigureAwait(false);
instance.AfterExecute(commandInfo);
( instance as IDisposable )?.Dispose();
(instance as IDisposable)?.Dispose();
}
}
@@ -428,7 +428,7 @@ namespace Discord.Interactions.Builders
}
#region Parameters
private static void BuildSlashParameter (SlashCommandParameterBuilder builder, ParameterInfo paramInfo, IServiceProvider services)
private static void BuildSlashParameter(SlashCommandParameterBuilder builder, ParameterInfo paramInfo, IServiceProvider services)
{
var attributes = paramInfo.GetCustomAttributes();
var paramType = paramInfo.ParameterType;
@@ -465,7 +465,7 @@ namespace Discord.Interactions.Builders
break;
case AutocompleteAttribute autocomplete:
builder.Autocomplete = true;
if(autocomplete.AutocompleteHandlerType is not null)
if (autocomplete.AutocompleteHandlerType is not null)
builder.WithAutocompleteHandler(autocomplete.AutocompleteHandlerType, services);
break;
case MaxValueAttribute maxValue:
@@ -516,7 +516,7 @@ namespace Discord.Interactions.Builders
BuildParameter(builder, paramInfo);
}
private static void BuildParameter<TInfo, TBuilder> (ParameterBuilder<TInfo, TBuilder> builder, ParameterInfo paramInfo)
private static void BuildParameter<TInfo, TBuilder>(ParameterBuilder<TInfo, TBuilder> builder, ParameterInfo paramInfo)
where TInfo : class, IParameterInfo
where TBuilder : ParameterBuilder<TInfo, TBuilder>
{
@@ -598,7 +598,7 @@ namespace Discord.Interactions.Builders
builder.WithType(propertyInfo.PropertyType);
builder.PropertyInfo = propertyInfo;
foreach(var attribute in attributes)
foreach (var attribute in attributes)
{
switch (attribute)
{
@@ -625,30 +625,30 @@ namespace Discord.Interactions.Builders
}
#endregion
internal static bool IsValidModuleDefinition (TypeInfo typeInfo)
internal static bool IsValidModuleDefinition(TypeInfo typeInfo)
{
return ModuleTypeInfo.IsAssignableFrom(typeInfo) &&
!typeInfo.IsAbstract &&
!typeInfo.ContainsGenericParameters;
}
private static bool IsValidSlashCommandDefinition (MethodInfo methodInfo)
private static bool IsValidSlashCommandDefinition(MethodInfo methodInfo)
{
return methodInfo.IsDefined(typeof(SlashCommandAttribute)) &&
( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>) ) &&
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
!methodInfo.IsStatic &&
!methodInfo.IsGenericMethod;
}
private static bool IsValidContextCommandDefinition (MethodInfo methodInfo)
private static bool IsValidContextCommandDefinition(MethodInfo methodInfo)
{
return methodInfo.IsDefined(typeof(ContextCommandAttribute)) &&
( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>) ) &&
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
!methodInfo.IsStatic &&
!methodInfo.IsGenericMethod;
}
private static bool IsValidComponentCommandDefinition (MethodInfo methodInfo)
private static bool IsValidComponentCommandDefinition(MethodInfo methodInfo)
{
return methodInfo.IsDefined(typeof(ComponentInteractionAttribute)) &&
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
@@ -656,7 +656,7 @@ namespace Discord.Interactions.Builders
!methodInfo.IsGenericMethod;
}
private static bool IsValidAutocompleteCommandDefinition (MethodInfo methodInfo)
private static bool IsValidAutocompleteCommandDefinition(MethodInfo methodInfo)
{
return methodInfo.IsDefined(typeof(AutocompleteCommandAttribute)) &&
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&

View File

@@ -9,7 +9,7 @@ namespace Discord.Interactions.Builders
{
protected override CommandParameterBuilder Instance => this;
internal CommandParameterBuilder (ICommandBuilder command) : base(command) { }
internal CommandParameterBuilder(ICommandBuilder command) : base(command) { }
/// <summary>
/// Initializes a new <see cref="CommandParameterInfo"/>.
@@ -17,9 +17,9 @@ namespace Discord.Interactions.Builders
/// <param name="command">Parent command of this parameter.</param>
/// <param name="name">Name of this command.</param>
/// <param name="type">Type of this parameter.</param>
public CommandParameterBuilder (ICommandBuilder command, string name, Type type) : base(command, name, type) { }
public CommandParameterBuilder(ICommandBuilder command, string name, Type type) : base(command, name, type) { }
internal override CommandParameterInfo Build (ICommandInfo command) =>
internal override CommandParameterInfo Build(ICommandInfo command) =>
new CommandParameterInfo(this, command);
}
}

View File

@@ -55,7 +55,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder WithName (string name);
IParameterBuilder WithName(string name);
/// <summary>
/// Sets <see cref="ParameterType"/>.
@@ -64,7 +64,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder SetParameterType (Type type);
IParameterBuilder SetParameterType(Type type);
/// <summary>
/// Sets <see cref="IsRequired"/>.
@@ -73,7 +73,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder SetRequired (bool isRequired);
IParameterBuilder SetRequired(bool isRequired);
/// <summary>
/// Sets <see cref="DefaultValue"/>.
@@ -82,7 +82,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder SetDefaultValue (object defaultValue);
IParameterBuilder SetDefaultValue(object defaultValue);
/// <summary>
/// Adds attributes to <see cref="Attributes"/>.
@@ -91,7 +91,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder AddAttributes (params Attribute[] attributes);
IParameterBuilder AddAttributes(params Attribute[] attributes);
/// <summary>
/// Adds preconditions to <see cref="Preconditions"/>.
@@ -100,6 +100,6 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
IParameterBuilder AddPreconditions (params ParameterPreconditionAttribute[] preconditions);
IParameterBuilder AddPreconditions(params ParameterPreconditionAttribute[] preconditions);
}
}

View File

@@ -40,7 +40,7 @@ namespace Discord.Interactions.Builders
public IReadOnlyCollection<ParameterPreconditionAttribute> Preconditions => _preconditions;
protected abstract TBuilder Instance { get; }
internal ParameterBuilder (ICommandBuilder command)
internal ParameterBuilder(ICommandBuilder command)
{
_attributes = new List<Attribute>();
_preconditions = new List<ParameterPreconditionAttribute>();
@@ -48,7 +48,7 @@ namespace Discord.Interactions.Builders
Command = command;
}
protected ParameterBuilder (ICommandBuilder command, string name, Type type) : this(command)
protected ParameterBuilder(ICommandBuilder command, string name, Type type) : this(command)
{
Name = name;
SetParameterType(type);
@@ -61,7 +61,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder WithName (string name)
public virtual TBuilder WithName(string name)
{
Name = name;
return Instance;
@@ -74,7 +74,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder SetParameterType (Type type)
public virtual TBuilder SetParameterType(Type type)
{
ParameterType = type;
return Instance;
@@ -87,7 +87,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder SetRequired (bool isRequired)
public virtual TBuilder SetRequired(bool isRequired)
{
IsRequired = isRequired;
return Instance;
@@ -100,7 +100,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder SetDefaultValue (object defaultValue)
public virtual TBuilder SetDefaultValue(object defaultValue)
{
DefaultValue = defaultValue;
return Instance;
@@ -113,7 +113,7 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder AddAttributes (params Attribute[] attributes)
public virtual TBuilder AddAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
return Instance;
@@ -126,37 +126,37 @@ namespace Discord.Interactions.Builders
/// <returns>
/// The builder instance.
/// </returns>
public virtual TBuilder AddPreconditions (params ParameterPreconditionAttribute[] attributes)
public virtual TBuilder AddPreconditions(params ParameterPreconditionAttribute[] attributes)
{
_preconditions.AddRange(attributes);
return Instance;
}
internal abstract TInfo Build (ICommandInfo command);
internal abstract TInfo Build(ICommandInfo command);
//IParameterBuilder
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.WithName (string name) =>
IParameterBuilder IParameterBuilder.WithName(string name) =>
WithName(name);
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.SetParameterType (Type type) =>
IParameterBuilder IParameterBuilder.SetParameterType(Type type) =>
SetParameterType(type);
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.SetRequired (bool isRequired) =>
IParameterBuilder IParameterBuilder.SetRequired(bool isRequired) =>
SetRequired(isRequired);
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.SetDefaultValue (object defaultValue) =>
IParameterBuilder IParameterBuilder.SetDefaultValue(object defaultValue) =>
SetDefaultValue(defaultValue);
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.AddAttributes (params Attribute[] attributes) =>
IParameterBuilder IParameterBuilder.AddAttributes(params Attribute[] attributes) =>
AddAttributes(attributes);
/// <inheritdoc/>
IParameterBuilder IParameterBuilder.AddPreconditions (params ParameterPreconditionAttribute[] preconditions) =>
IParameterBuilder IParameterBuilder.AddPreconditions(params ParameterPreconditionAttribute[] preconditions) =>
AddPreconditions(preconditions);
}
}

View File

@@ -229,7 +229,7 @@ namespace Discord.Interactions.Builders
{
base.SetParameterType(type);
if(!IsComplexParameter)
if (!IsComplexParameter)
TypeConverter = Command.Module.InteractionService.GetTypeConverter(ParameterType, services);
return this;
@@ -248,7 +248,7 @@ namespace Discord.Interactions.Builders
SlashCommandParameterBuilder builder = new(Command);
configure(builder);
if(builder.IsComplexParameter)
if (builder.IsComplexParameter)
throw new InvalidOperationException("You cannot create nested complex parameters.");
_complexParameterFields.Add(builder);
@@ -265,7 +265,7 @@ namespace Discord.Interactions.Builders
/// <exception cref="InvalidOperationException">Thrown if the added field has a <see cref="ComplexParameterAttribute"/>.</exception>
public SlashCommandParameterBuilder AddComplexParameterFields(params SlashCommandParameterBuilder[] fields)
{
if(fields.Any(x => x.IsComplexParameter))
if (fields.Any(x => x.IsComplexParameter))
throw new InvalidOperationException("You cannot create nested complex parameters.");
_complexParameterFields.AddRange(fields);

View File

@@ -15,7 +15,7 @@ namespace Discord.Interactions
/// </summary>
public object Value { get; }
internal ParameterChoice (string name, object value)
internal ParameterChoice(string name, object value)
{
Name = name;
Value = value;

View File

@@ -11,7 +11,7 @@ namespace Discord.Interactions
/// Sets the context of this module.
/// </summary>
/// <param name="context"></param>
void SetContext (IInteractionContext context);
void SetContext(IInteractionContext context);
/// <summary>
/// Method body to be executed asynchronously before executing an application command.
@@ -35,14 +35,14 @@ namespace Discord.Interactions
/// Method body to be executed after an application command execution.
/// </summary>
/// <param name="command">Command information related to the Discord Application Command.</param>
void AfterExecute (ICommandInfo command);
void AfterExecute(ICommandInfo command);
/// <summary>
/// Method body to be executed when <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.
/// </summary>
/// <param name="commandService">Command Service instance that built this module.</param>
/// <param name="module">Info class of this module.</param>
void OnModuleBuilding (InteractionService commandService, ModuleInfo module);
void OnModuleBuilding(InteractionService commandService, ModuleInfo module);
/// <summary>
/// Method body to be executed after the automated module creation is completed and before <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.

View File

@@ -64,7 +64,7 @@ namespace Discord.Interactions
{
var keywords = new List<string>() { ParameterName, CommandName };
if(!IgnoreGroupNames)
if (!IgnoreGroupNames)
{
var currentParent = Module;

View File

@@ -20,7 +20,7 @@ namespace Discord.Interactions
/// <returns>
/// A task representing the execution operation.
/// </returns>
public delegate Task ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo);
public delegate Task ExecuteCallback(IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo);
/// <summary>
/// The base information class for <see cref="InteractionService"/> commands.
@@ -129,7 +129,7 @@ namespace Discord.Interactions
if (!argsResult.IsSuccess)
return await InvokeEventAndReturn(context, argsResult).ConfigureAwait(false);
if(argsResult is not ParseResult parseResult)
if (argsResult is not ParseResult parseResult)
return ExecuteResult.FromError(InteractionCommandError.BadArgs, "Complex command parsing failed for an unknown reason.");
var args = parseResult.Args;

View File

@@ -42,7 +42,7 @@ namespace Discord.Interactions
var data = (context.Interaction as IComponentInteraction).Data;
var args = new object[Parameters.Count];
for(var i = 0; i < Parameters.Count; i++)
for (var i = 0; i < Parameters.Count; i++)
{
var parameter = Parameters[i];
var isCapture = i < captureCount;

View File

@@ -35,7 +35,7 @@ namespace Discord.Interactions
/// <inheritdoc/>
public override bool IgnoreGroupNames => true;
internal ContextCommandInfo (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
internal ContextCommandInfo(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
: base(builder, module, commandService)
{
CommandType = builder.CommandType;
@@ -46,7 +46,7 @@ namespace Discord.Interactions
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
}
internal static ContextCommandInfo Create (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
internal static ContextCommandInfo Create(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
{
return builder.CommandType switch
{
@@ -57,7 +57,7 @@ namespace Discord.Interactions
}
/// <inheritdoc/>
protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
=> CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result);
}
}

View File

@@ -86,7 +86,7 @@ namespace Discord.Interactions
var options = GetOptions();
var args = new object[Parameters.Count];
for(var i = 0; i < Parameters.Count; i++)
for (var i = 0; i < Parameters.Count; i++)
{
var parameter = Parameters[i];
var result = await ParseArgumentAsync(parameter, context, options, services).ConfigureAwait(false);
@@ -136,10 +136,10 @@ namespace Discord.Interactions
return readResult;
}
protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
=> CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result);
protected override string GetLogString (IInteractionContext context)
protected override string GetLogString(IInteractionContext context)
{
if (context.Guild != null)
return $"Slash Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}";
@@ -153,7 +153,7 @@ namespace Discord.Interactions
if (!parameter.IsComplexParameter)
yield return parameter;
else
foreach(var complexParameterField in parameter.ComplexParameterFields)
foreach (var complexParameterField in parameter.ComplexParameterFields)
yield return complexParameterField;
}
}

View File

@@ -75,11 +75,11 @@ namespace Discord.Interactions
/// <returns>
/// A task representing the execution process. The task result contains the execution result.
/// </returns>
Task<IResult> ExecuteAsync (IInteractionContext context, IServiceProvider services);
Task<IResult> ExecuteAsync(IInteractionContext context, IServiceProvider services);
/// <summary>
/// Check if an execution context meets the command precondition requirements.
/// </summary>
Task<PreconditionResult> CheckPreconditionsAsync (IInteractionContext context, IServiceProvider services);
Task<PreconditionResult> CheckPreconditionsAsync(IInteractionContext context, IServiceProvider services);
}
}

View File

@@ -52,6 +52,6 @@ namespace Discord.Interactions
/// <summary>
/// Check if an execution context meets the parameter precondition requirements.
/// </summary>
Task<PreconditionResult> CheckPreconditionsAsync (IInteractionContext context, object value, IServiceProvider services);
Task<PreconditionResult> CheckPreconditionsAsync(IInteractionContext context, object value, IServiceProvider services);
}
}

Some files were not shown because too many files have changed in this diff Show More