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
mod resolved;
pub use self::resolved::{CommandInteractionDataResolved, InteractionChannel, InteractionMember};
use crate::id::CommandId;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Default)]
pub struct CommandData {
pub id: CommandId,
pub name: String,
#[serde(default)]
pub options: Vec<CommandDataOption>,
pub resolved: Option<CommandInteractionDataResolved>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(untagged)]
pub enum CommandDataOption {
String {
name: String,
value: String,
},
Integer {
name: String,
value: i64,
},
Boolean {
name: String,
value: bool,
},
SubCommand {
name: String,
#[serde(default)]
options: Vec<CommandDataOption>,
},
}
impl CommandDataOption {
pub const fn kind(&self) -> &'static str {
match self {
CommandDataOption::String { .. } => "String",
CommandDataOption::Integer { .. } => "Integer",
CommandDataOption::Boolean { .. } => "Boolean",
CommandDataOption::SubCommand { .. } => "SubCommand",
}
}
pub fn name(&self) -> &str {
match self {
Self::String { name, .. }
| Self::Integer { name, .. }
| Self::Boolean { name, .. }
| Self::SubCommand { name, .. } => name,
}
}
}