Add configuration option for case insensitive commands
Currently, commands are case-sensitive. This PR allows for commands to be case insensitive (which is now the default option).
This commit is contained in:
@@ -19,6 +19,7 @@ namespace Discord.Commands
|
|||||||
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
||||||
private readonly CommandMap _map;
|
private readonly CommandMap _map;
|
||||||
|
|
||||||
|
internal readonly bool _caseSensitive;
|
||||||
internal readonly RunMode _defaultRunMode;
|
internal readonly RunMode _defaultRunMode;
|
||||||
|
|
||||||
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x);
|
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x);
|
||||||
@@ -67,6 +68,7 @@ namespace Discord.Commands
|
|||||||
[typeof(IGroupUser)] = new UserTypeReader<IGroupUser>(),
|
[typeof(IGroupUser)] = new UserTypeReader<IGroupUser>(),
|
||||||
[typeof(IGuildUser)] = new UserTypeReader<IGuildUser>(),
|
[typeof(IGuildUser)] = new UserTypeReader<IGuildUser>(),
|
||||||
};
|
};
|
||||||
|
_caseSensitive = config.CaseSensitiveCommands;
|
||||||
_defaultRunMode = config.DefaultRunMode;
|
_defaultRunMode = config.DefaultRunMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +214,7 @@ namespace Discord.Commands
|
|||||||
public SearchResult Search(CommandContext context, int argPos) => Search(context, context.Message.Content.Substring(argPos));
|
public SearchResult Search(CommandContext context, int argPos) => Search(context, context.Message.Content.Substring(argPos));
|
||||||
public SearchResult Search(CommandContext context, string input)
|
public SearchResult Search(CommandContext context, string input)
|
||||||
{
|
{
|
||||||
string lowerInput = input.ToLowerInvariant();
|
input = _caseSensitive ? input : input.ToLowerInvariant();
|
||||||
var matches = _map.GetCommands(input).OrderByDescending(x => x.Priority).ToImmutableArray();
|
var matches = _map.GetCommands(input).OrderByDescending(x => x.Priority).ToImmutableArray();
|
||||||
|
|
||||||
if (matches.Length > 0)
|
if (matches.Length > 0)
|
||||||
|
|||||||
@@ -4,5 +4,7 @@
|
|||||||
{
|
{
|
||||||
/// <summary> The default RunMode commands should have, if one is not specified on the Command attribute or builder. </summary>
|
/// <summary> The default RunMode commands should have, if one is not specified on the Command attribute or builder. </summary>
|
||||||
public RunMode DefaultRunMode { get; set; } = RunMode.Mixed;
|
public RunMode DefaultRunMode { get; set; } = RunMode.Mixed;
|
||||||
|
/// <summary> Should commands be case-sensitive? </summary>
|
||||||
|
public bool CaseSensitiveCommands { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ using System.Threading.Tasks;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using Discord.Commands.Builders;
|
using Discord.Commands.Builders;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
|
[DebuggerDisplay("{Name,nq}")]
|
||||||
public class CommandInfo
|
public class CommandInfo
|
||||||
{
|
{
|
||||||
private static readonly System.Reflection.MethodInfo _convertParamsMethod = typeof(CommandInfo).GetTypeInfo().GetDeclaredMethod(nameof(ConvertParamsList));
|
private static readonly System.Reflection.MethodInfo _convertParamsMethod = typeof(CommandInfo).GetTypeInfo().GetDeclaredMethod(nameof(ConvertParamsList));
|
||||||
|
|||||||
Reference in New Issue
Block a user