You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MatchResult.cs 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace Discord.Commands
  3. {
  4. public class MatchResult : IResult
  5. {
  6. /// <summary>
  7. /// Gets the command that may have matched during the command execution.
  8. /// </summary>
  9. public CommandMatch? Match { get; }
  10. /// <summary>
  11. /// Gets on which pipeline stage the command may have matched or failed.
  12. /// </summary>
  13. public IResult Pipeline { get; }
  14. /// <inheritdoc />
  15. public CommandError? Error { get; }
  16. /// <inheritdoc />
  17. public string ErrorReason { get; }
  18. /// <inheritdoc />
  19. public bool IsSuccess => !Error.HasValue;
  20. private MatchResult(CommandMatch? match, IResult pipeline, CommandError? error, string errorReason)
  21. {
  22. Match = match;
  23. Error = error;
  24. Pipeline = pipeline;
  25. ErrorReason = errorReason;
  26. }
  27. public static MatchResult FromSuccess(CommandMatch match, IResult pipeline)
  28. => new MatchResult(match,pipeline,null, null);
  29. public static MatchResult FromError(CommandError error, string reason)
  30. => new MatchResult(null,null,error, reason);
  31. public static MatchResult FromError(Exception ex)
  32. => FromError(CommandError.Exception, ex.Message);
  33. public static MatchResult FromError(IResult result)
  34. => new MatchResult(null, null,result.Error, result.ErrorReason);
  35. public static MatchResult FromError(IResult pipeline, CommandError error, string reason)
  36. => new MatchResult(null, pipeline, error, reason);
  37. public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
  38. private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
  39. }
  40. }