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.

RestApplicationCommandOption.cs 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Immutable;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Model = Discord.API.ApplicationCommandOption;
  8. namespace Discord.Rest
  9. {
  10. /// <summary>
  11. /// Represents a Rest-based implementation of <see cref="IApplicationCommandOption"/>.
  12. /// </summary>
  13. public class RestApplicationCommandOption : IApplicationCommandOption
  14. {
  15. #region RestApplicationCommandOption
  16. /// <inheritdoc/>
  17. public ApplicationCommandOptionType Type { get; private set; }
  18. /// <inheritdoc/>
  19. public string Name { get; private set; }
  20. /// <inheritdoc/>
  21. public string Description { get; private set; }
  22. /// <inheritdoc/>
  23. public bool? Default { get; private set; }
  24. /// <inheritdoc/>
  25. public bool? Required { get; private set; }
  26. /// <summary>
  27. /// A collection of <see cref="RestApplicationCommandChoice"/>'s for this command.
  28. /// </summary>
  29. public IReadOnlyCollection<RestApplicationCommandChoice> Choices { get; private set; }
  30. /// <summary>
  31. /// A collection of <see cref="RestApplicationCommandOption"/>'s for this command.
  32. /// </summary>
  33. public IReadOnlyCollection<RestApplicationCommandOption> Options { get; private set; }
  34. internal RestApplicationCommandOption() { }
  35. internal static RestApplicationCommandOption Create(Model model)
  36. {
  37. var options = new RestApplicationCommandOption();
  38. options.Update(model);
  39. return options;
  40. }
  41. internal void Update(Model model)
  42. {
  43. Type = model.Type;
  44. Name = model.Name;
  45. Description = model.Description;
  46. if (model.Default.IsSpecified)
  47. Default = model.Default.Value;
  48. if (model.Required.IsSpecified)
  49. Required = model.Required.Value;
  50. Options = model.Options.IsSpecified
  51. ? model.Options.Value.Select(x => Create(x)).ToImmutableArray()
  52. : null;
  53. Choices = model.Choices.IsSpecified
  54. ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray()
  55. : null;
  56. }
  57. #endregion
  58. #region IApplicationCommandOption
  59. IReadOnlyCollection<IApplicationCommandOption> IApplicationCommandOption.Options
  60. => Options;
  61. IReadOnlyCollection<IApplicationCommandOptionChoice> IApplicationCommandOption.Choices
  62. => Choices;
  63. #endregion
  64. }
  65. }