Format the project with 'dotnet format' (#2551)
* Sync and Re-Format * Fix Title string. * Fix indentation.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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>)) &&
|
||||
@@ -680,7 +680,7 @@ namespace Discord.Interactions.Builders
|
||||
propertyInfo.SetMethod?.IsStatic == false &&
|
||||
propertyInfo.IsDefined(typeof(ModalInputAttribute));
|
||||
}
|
||||
|
||||
|
||||
private static ConstructorInfo GetComplexParameterConstructor(TypeInfo typeInfo, ComplexParameterAttribute complexParameter)
|
||||
{
|
||||
var ctors = typeInfo.GetConstructors();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user