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.

ApplicationCommandOption.cs 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Discord.API
  8. {
  9. internal class ApplicationCommandOption
  10. {
  11. [JsonProperty("type")]
  12. public ApplicationCommandOptionType Type { get; set; }
  13. [JsonProperty("name")]
  14. public string Name { get; set; }
  15. [JsonProperty("description")]
  16. public string Description { get; set; }
  17. [JsonProperty("default")]
  18. public Optional<bool> Default { get; set; }
  19. [JsonProperty("required")]
  20. public Optional<bool> Required { get; set; }
  21. [JsonProperty("choices")]
  22. public Optional<ApplicationCommandOptionChoice[]> Choices { get; set; }
  23. [JsonProperty("options")]
  24. public Optional<ApplicationCommandOption[]> Options { get; set; }
  25. [JsonProperty("autocomplete")]
  26. public Optional<bool> Autocomplete { get; set; }
  27. [JsonProperty("channel_types")]
  28. public Optional<ChannelType[]> ChannelTypes { get; set; }
  29. public ApplicationCommandOption() { }
  30. public ApplicationCommandOption(IApplicationCommandOption cmd)
  31. {
  32. Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice()
  33. {
  34. Name = x.Name,
  35. Value = x.Value
  36. }).ToArray();
  37. Options = cmd.Options.Select(x => new ApplicationCommandOption(x)).ToArray();
  38. ChannelTypes = cmd.ChannelTypes.ToArray();
  39. Required = cmd.IsRequired.HasValue
  40. ? cmd.IsRequired.Value
  41. : Optional<bool>.Unspecified;
  42. Default = cmd.IsDefault.HasValue
  43. ? cmd.IsDefault.Value
  44. : Optional<bool>.Unspecified;
  45. Name = cmd.Name;
  46. Type = cmd.Type;
  47. Description = cmd.Description;
  48. }
  49. public ApplicationCommandOption(Discord.ApplicationCommandOptionProperties option)
  50. {
  51. Choices = option.Choices != null
  52. ? option.Choices.Select(x => new ApplicationCommandOptionChoice()
  53. {
  54. Name = x.Name,
  55. Value = x.Value
  56. }).ToArray()
  57. : Optional<ApplicationCommandOptionChoice[]>.Unspecified;
  58. Options = option.Options != null
  59. ? option.Options.Select(x => new ApplicationCommandOption(x)).ToArray()
  60. : Optional<ApplicationCommandOption[]>.Unspecified;
  61. Required = option.Required.HasValue
  62. ? option.Required.Value
  63. : Optional<bool>.Unspecified;
  64. Default = option.Default.HasValue
  65. ? option.Default.Value
  66. : Optional<bool>.Unspecified;
  67. ChannelTypes = option.ChannelTypes != null
  68. ? option.ChannelTypes.ToArray()
  69. : Optional<ChannelType[]>.Unspecified;
  70. Name = option.Name;
  71. Type = option.Type;
  72. Description = option.Description;
  73. Autocomplete = option.Autocomplete;
  74. }
  75. }
  76. }