| @@ -0,0 +1,17 @@ | |||||
| using System; | |||||
| namespace Discord.Commands | |||||
| { | |||||
| /// <summary> Set whether or not to ignore extra arguments for an individual command method or module, | |||||
| /// overriding the setting in <see cref="CommandServiceConfig"/> if necessary. </summary> | |||||
| [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | |||||
| public sealed class IgnoreExtraArgsAttribute : Attribute | |||||
| { | |||||
| public bool IgnoreValue { get; } | |||||
| public IgnoreExtraArgsAttribute(bool ignoreValue) | |||||
| { | |||||
| IgnoreValue = ignoreValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,8 +1,7 @@ | |||||
| using System; | |||||
| using System; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| namespace Discord.Commands.Builders | namespace Discord.Commands.Builders | ||||
| { | { | ||||
| @@ -22,6 +21,7 @@ namespace Discord.Commands.Builders | |||||
| public string PrimaryAlias { get; set; } | public string PrimaryAlias { get; set; } | ||||
| public RunMode RunMode { get; set; } | public RunMode RunMode { get; set; } | ||||
| public int Priority { get; set; } | public int Priority { get; set; } | ||||
| public bool IgnoreExtraArgs { get; set; } | |||||
| public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions; | public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions; | ||||
| public IReadOnlyList<ParameterBuilder> Parameters => _parameters; | public IReadOnlyList<ParameterBuilder> Parameters => _parameters; | ||||
| @@ -32,6 +32,7 @@ namespace Discord.Commands.Builders | |||||
| internal CommandBuilder(ModuleBuilder module) | internal CommandBuilder(ModuleBuilder module) | ||||
| { | { | ||||
| Module = module; | Module = module; | ||||
| IgnoreExtraArgs = module.IgnoreExtraArgs; | |||||
| _preconditions = new List<PreconditionAttribute>(); | _preconditions = new List<PreconditionAttribute>(); | ||||
| _parameters = new List<ParameterBuilder>(); | _parameters = new List<ParameterBuilder>(); | ||||
| @@ -140,4 +141,4 @@ namespace Discord.Commands.Builders | |||||
| return new CommandInfo(this, info, service); | return new CommandInfo(this, info, service); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -2,7 +2,6 @@ using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Reflection; | using System.Reflection; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| namespace Discord.Commands.Builders | namespace Discord.Commands.Builders | ||||
| { | { | ||||
| @@ -20,6 +19,7 @@ namespace Discord.Commands.Builders | |||||
| public string Summary { get; set; } | public string Summary { get; set; } | ||||
| public string Remarks { get; set; } | public string Remarks { get; set; } | ||||
| public string Group { get; set; } | public string Group { get; set; } | ||||
| public bool IgnoreExtraArgs { get; set; } | |||||
| public IReadOnlyList<CommandBuilder> Commands => _commands; | public IReadOnlyList<CommandBuilder> Commands => _commands; | ||||
| public IReadOnlyList<ModuleBuilder> Modules => _submodules; | public IReadOnlyList<ModuleBuilder> Modules => _submodules; | ||||
| @@ -34,6 +34,7 @@ namespace Discord.Commands.Builders | |||||
| { | { | ||||
| Service = service; | Service = service; | ||||
| Parent = parent; | Parent = parent; | ||||
| IgnoreExtraArgs = service._ignoreExtraArgs; | |||||
| _commands = new List<CommandBuilder>(); | _commands = new List<CommandBuilder>(); | ||||
| _submodules = new List<ModuleBuilder>(); | _submodules = new List<ModuleBuilder>(); | ||||
| @@ -123,6 +123,9 @@ namespace Discord.Commands | |||||
| case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
| builder.AddPrecondition(precondition); | builder.AddPrecondition(precondition); | ||||
| break; | break; | ||||
| case IgnoreExtraArgsAttribute ignoreExtra: | |||||
| builder.IgnoreExtraArgs = ignoreExtra.IgnoreValue; | |||||
| break; | |||||
| default: | default: | ||||
| builder.AddAttributes(attribute); | builder.AddAttributes(attribute); | ||||
| break; | break; | ||||
| @@ -177,6 +180,9 @@ namespace Discord.Commands | |||||
| case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
| builder.AddPrecondition(precondition); | builder.AddPrecondition(precondition); | ||||
| break; | break; | ||||
| case IgnoreExtraArgsAttribute ignoreExtra: | |||||
| builder.IgnoreExtraArgs = ignoreExtra.IgnoreValue; | |||||
| break; | |||||
| default: | default: | ||||
| builder.AddAttributes(attribute); | builder.AddAttributes(attribute); | ||||
| break; | break; | ||||
| @@ -6,7 +6,6 @@ using System.Linq; | |||||
| using System.Reflection; | using System.Reflection; | ||||
| using System.Threading; | using System.Threading; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| using Discord.Commands.Builders; | using Discord.Commands.Builders; | ||||
| using Discord.Logging; | using Discord.Logging; | ||||
| @@ -20,11 +20,5 @@ namespace Discord.Commands | |||||
| /// <summary> Determines whether extra parameters should be ignored. </summary> | /// <summary> Determines whether extra parameters should be ignored. </summary> | ||||
| public bool IgnoreExtraArgs { get; set; } = false; | public bool IgnoreExtraArgs { get; set; } = false; | ||||
| ///// <summary> Gets or sets the <see cref="IServiceProvider"/> to use. </summary> | |||||
| //public IServiceProvider ServiceProvider { get; set; } = null; | |||||
| ///// <summary> Gets or sets a factory function for the <see cref="IServiceProvider"/> to use. </summary> | |||||
| //public Func<CommandService, IServiceProvider> ServiceProviderFactory { get; set; } = null; | |||||
| } | } | ||||
| } | } | ||||
| @@ -27,6 +27,7 @@ namespace Discord.Commands | |||||
| public string Remarks { get; } | public string Remarks { get; } | ||||
| public int Priority { get; } | public int Priority { get; } | ||||
| public bool HasVarArgs { get; } | public bool HasVarArgs { get; } | ||||
| public bool IgnoreExtraArgs { get; } | |||||
| public RunMode RunMode { get; } | public RunMode RunMode { get; } | ||||
| public IReadOnlyList<string> Aliases { get; } | public IReadOnlyList<string> Aliases { get; } | ||||
| @@ -63,6 +64,7 @@ namespace Discord.Commands | |||||
| Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | ||||
| HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].IsMultiple : false; | HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].IsMultiple : false; | ||||
| IgnoreExtraArgs = builder.IgnoreExtraArgs; | |||||
| _action = builder.Callback; | _action = builder.Callback; | ||||
| _commandService = service; | _commandService = service; | ||||
| @@ -119,7 +121,7 @@ namespace Discord.Commands | |||||
| return ParseResult.FromError(preconditionResult); | return ParseResult.FromError(preconditionResult); | ||||
| string input = searchResult.Text.Substring(startIndex); | string input = searchResult.Text.Substring(startIndex); | ||||
| return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0).ConfigureAwait(false); | |||||
| return await CommandParser.ParseArgsAsync(this, context, IgnoreExtraArgs, services, input, 0).ConfigureAwait(false); | |||||
| } | } | ||||
| public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) | public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) | ||||
| @@ -2,7 +2,6 @@ using System; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| using System.Reflection; | |||||
| using Discord.Commands.Builders; | using Discord.Commands.Builders; | ||||
| namespace Discord.Commands | namespace Discord.Commands | ||||
| @@ -14,6 +13,7 @@ namespace Discord.Commands | |||||
| public string Summary { get; } | public string Summary { get; } | ||||
| public string Remarks { get; } | public string Remarks { get; } | ||||
| public string Group { get; } | public string Group { get; } | ||||
| public bool IgnoreExtraArgs { get; } | |||||
| public IReadOnlyList<string> Aliases { get; } | public IReadOnlyList<string> Aliases { get; } | ||||
| public IReadOnlyList<CommandInfo> Commands { get; } | public IReadOnlyList<CommandInfo> Commands { get; } | ||||
| @@ -23,8 +23,6 @@ namespace Discord.Commands | |||||
| public ModuleInfo Parent { get; } | public ModuleInfo Parent { get; } | ||||
| public bool IsSubmodule => Parent != null; | public bool IsSubmodule => Parent != null; | ||||
| //public TypeInfo TypeInfo { get; } | |||||
| internal ModuleInfo(ModuleBuilder builder, CommandService service, IServiceProvider services, ModuleInfo parent = null) | internal ModuleInfo(ModuleBuilder builder, CommandService service, IServiceProvider services, ModuleInfo parent = null) | ||||
| { | { | ||||
| Service = service; | Service = service; | ||||
| @@ -33,10 +31,9 @@ namespace Discord.Commands | |||||
| Summary = builder.Summary; | Summary = builder.Summary; | ||||
| Remarks = builder.Remarks; | Remarks = builder.Remarks; | ||||
| Group = builder.Group; | Group = builder.Group; | ||||
| IgnoreExtraArgs = builder.IgnoreExtraArgs; | |||||
| Parent = parent; | Parent = parent; | ||||
| //TypeInfo = builder.TypeInfo; | |||||
| Aliases = BuildAliases(builder, service).ToImmutableArray(); | Aliases = BuildAliases(builder, service).ToImmutableArray(); | ||||
| Commands = builder.Commands.Select(x => x.Build(this, service)).ToImmutableArray(); | Commands = builder.Commands.Select(x => x.Build(this, service)).ToImmutableArray(); | ||||
| Preconditions = BuildPreconditions(builder).ToImmutableArray(); | Preconditions = BuildPreconditions(builder).ToImmutableArray(); | ||||