twilight_http/request/application/command/
mod.rs1pub mod create_global_command;
2pub mod create_guild_command;
3
4mod delete_global_command;
5mod delete_guild_command;
6mod get_command_permissions;
7mod get_global_command;
8mod get_global_commands;
9mod get_guild_command;
10mod get_guild_command_permissions;
11mod get_guild_commands;
12mod set_global_commands;
13mod set_guild_commands;
14mod update_command_permissions;
15mod update_global_command;
16mod update_guild_command;
17
18pub use self::{
19 create_global_command::CreateGlobalCommand, create_guild_command::CreateGuildCommand,
20 delete_global_command::DeleteGlobalCommand, delete_guild_command::DeleteGuildCommand,
21 get_command_permissions::GetCommandPermissions, get_global_command::GetGlobalCommand,
22 get_global_commands::GetGlobalCommands, get_guild_command::GetGuildCommand,
23 get_guild_command_permissions::GetGuildCommandPermissions,
24 get_guild_commands::GetGuildCommands, set_global_commands::SetGlobalCommands,
25 set_guild_commands::SetGuildCommands, update_command_permissions::UpdateCommandPermissions,
26 update_global_command::UpdateGlobalCommand, update_guild_command::UpdateGuildCommand,
27};
28
29use serde::Serialize;
30use std::collections::HashMap;
31use twilight_model::{
32 application::command::{CommandOption, CommandType},
33 guild::Permissions,
34 id::{marker::ApplicationMarker, Id},
35};
36
37#[derive(Serialize)]
41struct CommandBorrowed<'a> {
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub application_id: Option<Id<ApplicationMarker>>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub default_member_permissions: Option<Permissions>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub dm_permission: Option<bool>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub description: Option<&'a str>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub description_localizations: Option<&'a HashMap<String, String>>,
52 #[serde(rename = "type")]
53 pub kind: CommandType,
54 pub name: &'a str,
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub name_localizations: Option<&'a HashMap<String, String>>,
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub nsfw: Option<bool>,
59 #[serde(default)]
60 pub options: Option<&'a [CommandOption]>,
61}
62
63#[cfg(test)]
64mod tests {
65 use super::CommandBorrowed;
66 use std::collections::HashMap;
67 use twilight_model::{
68 application::command::{Command, CommandType},
69 guild::Permissions,
70 id::Id,
71 };
72
73 #[test]
79 #[allow(deprecated)]
80 fn command_borrowed_from_command() {
81 let command = Command {
82 application_id: Some(Id::new(1)),
83 contexts: None,
84 default_member_permissions: Some(Permissions::ADMINISTRATOR),
85 dm_permission: Some(true),
86 description: "command description".to_owned(),
87 description_localizations: Some(HashMap::from([(
88 "en-US".to_owned(),
89 "command description".to_owned(),
90 )])),
91 guild_id: Some(Id::new(2)),
92 id: Some(Id::new(3)),
93 integration_types: None,
94 kind: CommandType::ChatInput,
95 name: "command name".to_owned(),
96 name_localizations: Some(HashMap::from([(
97 "en-US".to_owned(),
98 "command name".to_owned(),
99 )])),
100 nsfw: Some(true),
101 options: Vec::new(),
102 version: Id::new(1),
103 };
104 _ = CommandBorrowed {
105 application_id: command.application_id,
106 default_member_permissions: command.default_member_permissions,
107 dm_permission: command.dm_permission,
108 description: Some(&command.description),
109 description_localizations: command.description_localizations.as_ref(),
110 kind: CommandType::ChatInput,
111 name: &command.name,
112 name_localizations: command.name_localizations.as_ref(),
113 nsfw: command.nsfw,
114 options: Some(&command.options),
115 };
116 }
117}