twilight_http/request/application/command/
update_guild_command.rsuse crate::{
client::Client,
error::Error,
request::{Request, TryIntoRequest},
response::{Response, ResponseFuture},
routing::Route,
};
use serde::Serialize;
use std::future::IntoFuture;
use twilight_model::{
application::command::{Command, CommandOption},
id::{
marker::{ApplicationMarker, CommandMarker, GuildMarker},
Id,
},
};
#[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")]
nsfw: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
options: Option<&'a [CommandOption]>,
}
#[must_use = "requests must be configured and executed"]
pub struct UpdateGuildCommand<'a> {
fields: UpdateGuildCommandFields<'a>,
application_id: Id<ApplicationMarker>,
command_id: Id<CommandMarker>,
guild_id: Id<GuildMarker>,
http: &'a Client,
}
impl<'a> UpdateGuildCommand<'a> {
pub(crate) const fn new(
http: &'a Client,
application_id: Id<ApplicationMarker>,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
) -> Self {
Self {
application_id,
command_id,
fields: UpdateGuildCommandFields {
description: None,
name: None,
nsfw: 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
}
pub const fn nsfw(mut self, nsfw: bool) -> Self {
self.fields.nsfw = Some(nsfw);
self
}
}
impl IntoFuture for UpdateGuildCommand<'_> {
type Output = Result<Response<Command>, Error>;
type IntoFuture = ResponseFuture<Command>;
fn into_future(self) -> Self::IntoFuture {
let http = self.http;
match self.try_into_request() {
Ok(request) => http.request(request),
Err(source) => ResponseFuture::error(source),
}
}
}
impl TryIntoRequest for UpdateGuildCommand<'_> {
fn try_into_request(self) -> Result<Request, Error> {
Request::builder(&Route::UpdateGuildCommand {
application_id: self.application_id.get(),
command_id: self.command_id.get(),
guild_id: self.guild_id.get(),
})
.json(&self.fields)
.build()
}
}