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.

RequestOptions.cs 2.8 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Threading;
  2. namespace Discord
  3. {
  4. /// <summary>
  5. /// Represents options that should be used when sending a request.
  6. /// </summary>
  7. public class RequestOptions
  8. {
  9. /// <summary>
  10. /// Creates a new <see cref="RequestOptions" /> class with its default settings.
  11. /// </summary>
  12. public static RequestOptions Default => new RequestOptions();
  13. /// <summary>
  14. /// Gets or sets the maximum time to wait for for this request to complete.
  15. /// </summary>
  16. /// <remarks>
  17. /// Gets or set the max time, in milliseconds, to wait for for this request to complete. If
  18. /// <c>null</c>, a request will not time out. If a rate limit has been triggered for this request's bucket
  19. /// and will not be unpaused in time, this request will fail immediately.
  20. /// </remarks>
  21. /// <returns>
  22. /// A <see cref="int"/> in milliseconds for when the request times out.
  23. /// </returns>
  24. public int? Timeout { get; set; }
  25. /// <summary>
  26. /// Gets or sets the cancellation token for this request.
  27. /// </summary>
  28. /// <returns>
  29. /// A <see cref="CancellationToken"/> for this request.
  30. /// </returns>
  31. public CancellationToken CancelToken { get; set; } = CancellationToken.None;
  32. /// <summary>
  33. /// Gets or sets the retry behavior when the request fails.
  34. /// </summary>
  35. public RetryMode? RetryMode { get; set; }
  36. public bool HeaderOnly { get; internal set; }
  37. /// <summary>
  38. /// Gets or sets the reason for this action in the guild's audit log.
  39. /// </summary>
  40. /// <remarks>
  41. /// Gets or sets the reason that will be written to the guild's audit log if applicable. This may not apply
  42. /// to all actions.
  43. /// </remarks>
  44. public string AuditLogReason { get; set; }
  45. internal bool IgnoreState { get; set; }
  46. internal string BucketId { get; set; }
  47. internal bool IsClientBucket { get; set; }
  48. internal static RequestOptions CreateOrClone(RequestOptions options)
  49. {
  50. if (options == null)
  51. return new RequestOptions();
  52. else
  53. return options.Clone();
  54. }
  55. /// <summary>
  56. /// Initializes a new <see cref="RequestOptions" /> class with the default request timeout set in
  57. /// <see cref="DiscordConfig"/>.
  58. /// </summary>
  59. public RequestOptions()
  60. {
  61. Timeout = DiscordConfig.DefaultRequestTimeout;
  62. }
  63. public RequestOptions Clone() => MemberwiseClone() as RequestOptions;
  64. }
  65. }