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
use crate::{
client::Client,
error::Error,
request::{Request, RequestBuilder},
response::ResponseFuture,
routing::Route,
};
use serde::Serialize;
use twilight_model::{
application::command::{Command, CommandOption},
id::{ApplicationId, CommandId, GuildId},
};
#[derive(Serialize)]
struct UpdateGuildCommandFields<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
options: Option<&'a [CommandOption]>,
}
pub struct UpdateGuildCommand<'a> {
fields: UpdateGuildCommandFields<'a>,
application_id: ApplicationId,
command_id: CommandId,
guild_id: GuildId,
http: &'a Client,
}
impl<'a> UpdateGuildCommand<'a> {
pub(crate) const fn new(
http: &'a Client,
application_id: ApplicationId,
guild_id: GuildId,
command_id: CommandId,
) -> Self {
Self {
application_id,
command_id,
fields: UpdateGuildCommandFields {
description: None,
name: None,
options: None,
},
guild_id,
http,
}
}
pub const fn name(mut self, name: &'a str) -> Self {
self.fields.name = Some(name);
self
}
pub const fn description(mut self, description: &'a str) -> Self {
self.fields.description = Some(description);
self
}
pub const fn command_options(mut self, options: &'a [CommandOption]) -> Self {
self.fields.options = Some(options);
self
}
fn request(&self) -> Result<Request, Error> {
Request::builder(&Route::UpdateGuildCommand {
application_id: self.application_id.0,
command_id: self.command_id.0,
guild_id: self.guild_id.0,
})
.json(&self.fields)
.map(RequestBuilder::build)
}
pub fn exec(self) -> ResponseFuture<Command> {
match self.request() {
Ok(request) => self.http.request(request),
Err(source) => ResponseFuture::error(source),
}
}
}