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

129 lines
3.0KB

  1. use serde::{Deserialize, Serialize};
  2. #[derive(Serialize, Deserialize, Clone)]
  3. #[serde(tag = "type")]
  4. pub enum Interaction {
  5. #[serde(rename = "1")]
  6. Ping {},
  7. #[serde(rename = "2")]
  8. Command {
  9. token: String,
  10. // member: Member,
  11. id: String,
  12. guild_id: String,
  13. // data: Command,
  14. channel_id: String,
  15. //version: usize,
  16. },
  17. }
  18. impl Interaction {
  19. pub fn is_ping(&self) -> bool {
  20. match self {
  21. Self::Ping {..} => true,
  22. Self::Command {..} => false,
  23. }
  24. }
  25. }
  26. #[derive(Serialize, Deserialize, Clone)]
  27. #[serde(tag = "type")]
  28. pub enum InteractionResponse {
  29. #[serde(rename = "1")]
  30. Pong {},
  31. #[serde(rename = "2")]
  32. Acknowledge {},
  33. #[serde(rename = "3")]
  34. ChannelMessage {
  35. data: Option<InteractionApplicationCommandCallbackData>,
  36. },
  37. #[serde(rename = "4")]
  38. ChannelMessageWithSource {
  39. data: Option<InteractionApplicationCommandCallbackData>,
  40. },
  41. #[serde(rename = "5")]
  42. AcknowledgeWithSource {},
  43. }
  44. #[derive(Serialize, Deserialize, Clone)]
  45. pub struct InteractionApplicationCommandCallbackData {
  46. pub tts: bool,
  47. pub content: String,
  48. //pub embeds: Option<Vec<Embed>>,
  49. pub allowed_mentions: Option<String>,
  50. }
  51. // slash command management structures
  52. #[derive(Serialize, Deserialize, Clone)]
  53. pub struct ApplicationCommand {
  54. pub id: Option<String>,
  55. pub application_id: Option<String>,
  56. pub name: String,
  57. pub description: String,
  58. pub options: Option<Vec<ApplicationCommandOption>>,
  59. }
  60. #[derive(Serialize, Deserialize, Clone)]
  61. #[serde(tag = "type")]
  62. pub enum ApplicationCommandOption {
  63. #[serde(rename = "1")]
  64. SubCommand {
  65. name: String,
  66. description: String,
  67. required: bool,
  68. options: Option<Vec<ApplicationCommandOption>>,
  69. },
  70. #[serde(rename = "2")]
  71. SubCommandGroup {
  72. name: String,
  73. description: String,
  74. required: bool,
  75. options: Option<Vec<ApplicationCommandOption>>,
  76. },
  77. #[serde(rename = "3")]
  78. String {
  79. name: String,
  80. description: String,
  81. required: bool,
  82. choices: Option<Vec<ApplicationCommandOptionChoice>>,
  83. },
  84. #[serde(rename = "4")]
  85. Integer {
  86. name: String,
  87. description: String,
  88. required: bool,
  89. choices: Option<Vec<ApplicationCommandOptionChoice>>,
  90. },
  91. #[serde(rename = "5")]
  92. Boolean {
  93. name: String,
  94. description: String,
  95. required: bool,
  96. },
  97. #[serde(rename = "6")]
  98. User {
  99. name: String,
  100. description: String,
  101. required: bool,
  102. },
  103. #[serde(rename = "7")]
  104. Channel {
  105. name: String,
  106. description: String,
  107. required: bool,
  108. },
  109. #[serde(rename = "8")]
  110. Role {
  111. name: String,
  112. description: String,
  113. required: bool,
  114. },
  115. }
  116. #[derive(Serialize, Deserialize, Clone)]
  117. pub struct ApplicationCommandOptionChoice {
  118. pub name: String,
  119. pub value: String,
  120. }