Slash commands are cool
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

120 wiersze
4.0KB

  1. use crate::discord;
  2. use crate::discord::{Interaction, InteractionResponse, InteractionApplicationCommandCallbackData};
  3. // fn foo() -> (definition, private?)
  4. // hello-world data for telling Discord about it
  5. pub fn def_hello_world() -> (discord::ApplicationCommand, Option<String>) {
  6. (discord::ApplicationCommand {
  7. id: None,
  8. application_id: None,
  9. name: "hello-world".to_string(),
  10. description: "Hello World".to_string(),
  11. options: None,
  12. }, Some("616329232389505055".to_string()))
  13. }
  14. // hello-world action when someone uses the command on Discord
  15. pub fn hello_world(interaction: &Interaction) -> InteractionResponse {
  16. let cmd = interaction.cmd().unwrap();
  17. InteractionResponse::ChannelMessageWithSource {
  18. data: Some(InteractionApplicationCommandCallbackData {
  19. tts: false,
  20. content: format!("Hello {}!", cmd.member.nick.unwrap_or(cmd.member.user.unwrap().username)),
  21. allowed_mentions: None,
  22. embeds: None,
  23. flags: None,
  24. }),
  25. }
  26. }
  27. // gitea-release command definition
  28. pub fn def_gitea_release() -> (discord::ApplicationCommand, Option<String>) {
  29. (discord::ApplicationCommand {
  30. id: None,
  31. application_id: None,
  32. name: "gitea-release".to_string(),
  33. description: "Display a software release".to_string(),
  34. options: Some(vec![
  35. discord::ApplicationCommandOption::String {
  36. name: "username".to_string(),
  37. description: "Gitea username".to_string(),
  38. required: true,
  39. choices: None
  40. },
  41. discord::ApplicationCommandOption::String {
  42. name: "repo".to_string(),
  43. description: "Gitea repository".to_string(),
  44. required: true,
  45. choices: None
  46. },
  47. ]),
  48. }, Some("616329232389505055".to_string()))
  49. }
  50. // gitea-issue
  51. pub fn def_gitea_issue() -> (discord::ApplicationCommand, Option<String>) {
  52. (discord::ApplicationCommand {
  53. id: None,
  54. application_id: None,
  55. name: "gitea-issue".to_string(),
  56. description: "Display an issue".to_string(),
  57. options: Some(vec![
  58. discord::ApplicationCommandOption::String {
  59. name: "username".to_string(),
  60. description: "Gitea username".to_string(),
  61. required: true,
  62. choices: None
  63. },
  64. discord::ApplicationCommandOption::String {
  65. name: "repo".to_string(),
  66. description: "Gitea repository".to_string(),
  67. required: true,
  68. choices: None
  69. },
  70. discord::ApplicationCommandOption::Integer {
  71. name: "issue".to_string(),
  72. description: "Gitea issue number".to_string(),
  73. required: true,
  74. choices: None
  75. },
  76. ]),
  77. }, Some("616329232389505055".to_string()))
  78. }
  79. // macros
  80. // cardlife macro
  81. pub fn def_cardlife() -> (discord::ApplicationCommand, Option<String>) {
  82. (discord::ApplicationCommand {
  83. id: None,
  84. application_id: None,
  85. name: "cardlife".to_string(),
  86. description: "Cardlife mod information".to_string(),
  87. options: None,
  88. }, Some("616329232389505055".to_string()))
  89. }
  90. // robocraft macro
  91. pub fn def_robocraft() -> (discord::ApplicationCommand, Option<String>) {
  92. (discord::ApplicationCommand {
  93. id: None,
  94. application_id: None,
  95. name: "robocraft".to_string(),
  96. description: "Robocraft mod information".to_string(),
  97. options: None,
  98. }, Some("616329232389505055".to_string()))
  99. }
  100. // techblox macro
  101. pub fn def_techblox() -> (discord::ApplicationCommand, Option<String>) {
  102. (discord::ApplicationCommand {
  103. id: None,
  104. application_id: None,
  105. name: "techblox".to_string(),
  106. description: "Techblox mod information".to_string(),
  107. options: None,
  108. }, Some("616329232389505055".to_string()))
  109. }