Removed ParamList null checks
This commit is contained in:
@@ -95,17 +95,13 @@ namespace Discord.Commands
|
||||
return Task.FromResult(ExecuteResult.FromError(parseResult.ArgValues[i]));
|
||||
argList[i] = parseResult.ArgValues[i].Values.First().Value;
|
||||
}
|
||||
|
||||
object[] paramList = null;
|
||||
if (parseResult.ParamValues != null)
|
||||
|
||||
var paramList = new object[parseResult.ParamValues.Count];
|
||||
for (int i = 0; i < parseResult.ParamValues.Count; i++)
|
||||
{
|
||||
paramList = new object[parseResult.ParamValues.Count];
|
||||
for (int i = 0; i < parseResult.ParamValues.Count; i++)
|
||||
{
|
||||
if (!parseResult.ParamValues[i].IsSuccess)
|
||||
return Task.FromResult(ExecuteResult.FromError(parseResult.ParamValues[i]));
|
||||
paramList[i] = parseResult.ParamValues[i].Values.First().Value;
|
||||
}
|
||||
if (!parseResult.ParamValues[i].IsSuccess)
|
||||
return Task.FromResult(ExecuteResult.FromError(parseResult.ParamValues[i]));
|
||||
paramList[i] = parseResult.ParamValues[i].Values.First().Value;
|
||||
}
|
||||
|
||||
return Execute(msg, argList, paramList);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -22,9 +21,8 @@ namespace Discord.Commands
|
||||
var curPart = ParserPart.None;
|
||||
int lastArgEndPos = int.MinValue;
|
||||
var argList = ImmutableArray.CreateBuilder<TypeReaderResult>();
|
||||
ImmutableArray<TypeReaderResult>.Builder paramList = ImmutableArray.CreateBuilder<TypeReaderResult>();
|
||||
var paramList = ImmutableArray.CreateBuilder<TypeReaderResult>();
|
||||
bool isEscaping = false;
|
||||
bool hasMultipleMatches = false;
|
||||
char c;
|
||||
|
||||
for (int curPos = startPos; curPos <= endPos; curPos++)
|
||||
@@ -111,13 +109,8 @@ namespace Discord.Commands
|
||||
return ParseResult.FromError(CommandError.BadArgCount, "The input text has too many parameters.");
|
||||
|
||||
var typeReaderResult = await curParam.Parse(context, argString).ConfigureAwait(false);
|
||||
if (!typeReaderResult.IsSuccess)
|
||||
{
|
||||
if (typeReaderResult.Error == CommandError.MultipleMatches)
|
||||
hasMultipleMatches = true;
|
||||
else
|
||||
return ParseResult.FromError(typeReaderResult);
|
||||
}
|
||||
if (!typeReaderResult.IsSuccess && typeReaderResult.Error != CommandError.MultipleMatches)
|
||||
return ParseResult.FromError(typeReaderResult);
|
||||
|
||||
if (curParam.IsMultiple)
|
||||
{
|
||||
@@ -162,7 +155,7 @@ namespace Discord.Commands
|
||||
argList.Add(TypeReaderResult.FromSuccess(param.DefaultValue));
|
||||
}
|
||||
|
||||
return ParseResult.FromSuccess(argList.ToImmutable(), paramList?.ToImmutable());
|
||||
return ParseResult.FromSuccess(argList.ToImmutable(), paramList.ToImmutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace Discord.Commands
|
||||
{
|
||||
case MultiMatchHandling.Best:
|
||||
argList = parseResult.ArgValues.Select(x => x.Values.OrderByDescending(y => y.Score).First()).ToArray();
|
||||
paramList = parseResult.ParamValues?.Select(x => x.Values.OrderByDescending(y => y.Score).First()).ToArray();
|
||||
paramList = parseResult.ParamValues.Select(x => x.Values.OrderByDescending(y => y.Score).First()).ToArray();
|
||||
parseResult = ParseResult.FromSuccess(argList, paramList);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,6 @@ namespace Discord.Commands
|
||||
=> new ParseResult(null, null, result.Error, result.ErrorReason);
|
||||
|
||||
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
||||
private string DebuggerDisplay => IsSuccess ? $"Success ({ArgValues.Count}{(ParamValues != null ? $" +{ParamValues.Count} Values" : "")})" : $"{Error}: {ErrorReason}";
|
||||
private string DebuggerDisplay => IsSuccess ? $"Success ({ArgValues.Count}{(ParamValues.Count > 0 ? $" +{ParamValues.Count} Values" : "")})" : $"{Error}: {ErrorReason}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user