Browse Source

Removed ParamList null checks

tags/1.0-rc
RogueException 8 years ago
parent
commit
f6d8659a2e
4 changed files with 13 additions and 24 deletions
  1. +6
    -10
      src/Discord.Net.Commands/Command.cs
  2. +5
    -12
      src/Discord.Net.Commands/CommandParser.cs
  3. +1
    -1
      src/Discord.Net.Commands/CommandService.cs
  4. +1
    -1
      src/Discord.Net.Commands/Results/ParseResult.cs

+ 6
- 10
src/Discord.Net.Commands/Command.cs View File

@@ -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);


+ 5
- 12
src/Discord.Net.Commands/CommandParser.cs View File

@@ -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());
}
}
}

+ 1
- 1
src/Discord.Net.Commands/CommandService.cs View File

@@ -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;
}


+ 1
- 1
src/Discord.Net.Commands/Results/ParseResult.cs View File

@@ -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}";
}
}

Loading…
Cancel
Save