1use crate::CommandOptionBuilder;
4use crate::types::{ApplicationCommand, CommandEntry, CommandKind, SubCommand as WitSub};
5
6#[derive(Debug, Clone)]
8pub struct SlashCommand(ApplicationCommand);
9
10impl SlashCommand {
11 fn of(kind: CommandKind, name: String, description: String) -> Self {
12 Self(ApplicationCommand {
13 kind,
14 name,
15 name_localizations: Vec::new(),
16 description,
17 description_localizations: Vec::new(),
18 options: Vec::new(),
19 default_member_permissions: None,
20 })
21 }
22
23 #[must_use]
26 pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
27 Self::of(CommandKind::ChatInput, name.into(), description.into())
28 }
29
30 #[must_use]
32 pub fn user(name: impl Into<String>) -> Self {
33 Self::of(CommandKind::User, name.into(), String::new())
34 }
35
36 #[must_use]
38 pub fn message(name: impl Into<String>) -> Self {
39 Self::of(CommandKind::Message, name.into(), String::new())
40 }
41
42 #[must_use]
44 pub fn option(mut self, option: CommandOptionBuilder) -> Self {
45 self.0
46 .options
47 .push(CommandEntry::ValueOption(option.build()));
48 self
49 }
50
51 #[must_use]
53 pub fn sub_command(mut self, sub: SubCommand) -> Self {
54 self.0.options.push(CommandEntry::SubCommand(sub.0));
55 self
56 }
57
58 #[must_use]
60 pub fn group(mut self, group: SubCommandGroup) -> Self {
61 self.0.options.push(CommandEntry::Group(group.0));
62 self
63 }
64
65 #[must_use]
67 pub fn default_member_permissions(mut self, bits: u64) -> Self {
68 self.0.default_member_permissions = Some(bits);
69 self
70 }
71
72 #[must_use]
74 pub fn localized_name(mut self, locale: &str, name: &str) -> Self {
75 let l = crate::types::Localized {
76 locale: locale.to_owned(),
77 text: name.to_owned(),
78 };
79 self.0.name_localizations.push(l);
80 self
81 }
82
83 #[must_use]
85 pub fn build(self) -> ApplicationCommand {
86 self.0
87 }
88}
89
90#[derive(Debug, Clone)]
92pub struct SubCommand(WitSub);
93
94impl SubCommand {
95 #[must_use]
97 pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
98 Self(WitSub {
99 name: name.into(),
100 name_localizations: Vec::new(),
101 description: description.into(),
102 description_localizations: Vec::new(),
103 options: Vec::new(),
104 })
105 }
106
107 #[must_use]
109 pub fn option(mut self, option: CommandOptionBuilder) -> Self {
110 self.0.options.push(option.build());
111 self
112 }
113}
114
115#[derive(Debug, Clone)]
117pub struct SubCommandGroup(crate::types::SubCommandGroup);
118
119impl SubCommandGroup {
120 #[must_use]
122 pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
123 Self(crate::types::SubCommandGroup {
124 name: name.into(),
125 name_localizations: Vec::new(),
126 description: description.into(),
127 description_localizations: Vec::new(),
128 sub_commands: Vec::new(),
129 })
130 }
131
132 #[must_use]
134 pub fn sub_command(mut self, sub: SubCommand) -> Self {
135 self.0.sub_commands.push(sub.0);
136 self
137 }
138}