1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use TokenStream;
use TokenStream as TokenStream2;
/// Converts an `async` function into a normal function returning a
/// `Pin<Box<dyn Future<Output = _> + '_>>`
/// Converts an `async-compatible` function into a builder and modifies function's body
/// to parse all required arguments, for further information about the behaviour of this macro, see
/// the implementation.
///
/// By an `async-compatible` function it's meant a function with a minimum of one argument,
/// which must be an `&SlashContext<T>`, which is always given and also used to parse all arguments.
///
/// # Usage:
///
/// This macro can be used two ways:
///
/// - Without arguments, as #[command], which takes the caller function name as the name of the command.
/// - Providing the name, as #[command("command name")] which takes the provided name as the command name.
///
/// When marking a function with this attribute macro, you **must** provide a description of the
/// command that will be seen on discord when using the command, this is made by adding a
/// `description` attribute, which can be added two ways:
///
/// - List way: #[description("Some description")]
///
/// - Named value way: #[description = "Some description"]
///
/// ## Arguments:
///
/// You **must** provide another `description` attribute for every argument describing what they
/// are, this description will be seen on discord when filling up the argument. This needs to be
/// done with all the arguments except the context, which must be the first one, the accepted
/// syntax is the same as the previous `description` one.
///
/// ### Renaming:
/// Adding a `rename` attribute is optional, but can be used to modify the name of the argument seen
/// in discord, it is allowed to have only one `rename` attribute per argument and the attribute can
/// be used the same ways a the `description` one.
///
/// ### Autocompletion:
/// Adding an `autocomplete` attribute is also optional, but it allows the developer to complete
/// the user's input for an argument. This attribute is used the same way as the description one,
/// but it *must* point to a function marked with the `#[autocomplete]` attribute macro.
///
/// ## Specifying required permissions
///
/// It is possible to specify the permissions needed to execute the command by using the
/// `#[required_permissions]` attribute. It accepts as input a list of comma separated
/// [twilight permissions](https://docs.rs/twilight-model/latest/twilight_model/guild/struct.Permissions.html).
/// For example, to specify that a user needs to have administrator permissions to execute a command,
/// the attribute would be used like this `#[required_permissions(ADMINISTRATOR)]`.
/// Prepares the function to allow it to be set as an after hook, see
/// the implementation for more information about this macro's behaviour.
/// Prepares the function to allow it to be set as a before hook, see
/// the implementation for more information about this macro's behaviour.
/// Prepares the function to be used to autocomplete command arguments.
/// Implements `Parse` for an enum, allowing it to be used as a command argument.
/// The enum will be seen by the user as a list of options to choose from, and one of the variants
/// will have to be selected.
///
/// # Examples:
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Parse)]
/// enum Choices {
/// First,
/// Second,
/// Third,
/// // ...
/// }
/// ```
///
/// Enums variants can be renamed to modify the value seen by the user using the
/// `#[parse(rename = "<RENAME>")]` attribute.
///
/// # Example:
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Parse)]
/// enum Choices {
/// First,
/// Second,
/// #[parse(rename = "Forth")]
/// Third, // <- This item will be shown to the user as "Forth", despite its variant name being Third
/// // ...
/// }
/// ```
///
/// Implements the `Modal` trait for the derived struct, allowing it to create modals and collect
/// the inputs provided by the user.
///
/// # Examples
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Modal)]
/// struct MyModal {
/// something: String,
/// optional_item: Option<String>
/// }
/// ```
///
/// # Attributes
///
/// The derive macro accepts several attributes:
///
/// - `#[modal(title = "<TITLE>")]`: This attribute allows specifying the title of the modal, by default the
/// title will be the name of the structure.
///
/// ## Example
///
/// ```rust
/// #[derive(Modal)]
/// struct MyModal { // <- This modal will have "MyModal" as title.
/// //...
/// }
///
/// #[derive(Modal)]
/// #[modal(title = "Some incredible modal")]
/// struct OtherModal { // <- This one will have "Some incredible modal" as the title.
/// // ...
/// }
/// ```
///
/// - `#[modal(label = "<LABEL>")]`: This attribute allows setting the label of the field, by default it will
/// be the name of the struct field.
///
/// ## Example
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Modal)]
/// struct MyModal {
/// #[modal(label = "My field")]
/// something: String, // <- This field will be shown as "My field"
/// optional_item: Option<String> // <- This one will use the struct name "optional_item"
/// }
/// ```
///
/// - `#[modal(max_length = x)]` and `#[modal(min_length = y)]`: These attributes allow to set a
/// maximum/minimum amount of characters a field can have.
///
/// ## Example
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Modal)]
/// struct MyModal {
/// #[modal(max_length = 150, min_length = 15)]
/// something: String, // <- This field will have both maximum and minimum size constraints.
/// #[modal(max_length) = 25]
/// short_field: String, // <- This field will only have a maximum size constraint.
/// optional_item: Option<String> // <- This one won't have any
/// }
/// ```
///
/// - #[modal(placeholder = "<PLACEHOLDER>")]: This attribute allows specifying a placeholder that will be seen
/// before entering anything on the input.
///
/// ## Example
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Modal)]
/// struct MyModal {
/// #[modal(placeholder = "This is a placeholder")]
/// something: String, // <- This field will have as placeholder "This is a placeholder".
/// }
/// ```
///
/// - `#[modal(paragraph)]`: This attribute will mark the field as a paragraph. By default, all fields are
/// marked as single line fields, so the user will only be able to input up to one line unless we
/// mark it as a paragraph.
///
/// ## Example
///
/// ```rust
/// use zephyrus::prelude::*;
///
/// #[derive(Modal)]
/// struct MyModal {
/// #[modal(paragraph)]
/// something: String, // <- This field will be shown as a multi-line field.
/// optional_item: Option<String> // <- This one will be shown as a single line one.
/// }
/// ```
/// Extracts the given result, throwing a compile error if an error is given.