66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
use async_trait::async_trait;
|
|
use geoffrey_models::models::locations::Location;
|
|
use reqwest::Method;
|
|
use serenity::model::interactions::application_command::{
|
|
ApplicationCommandInteraction, ApplicationCommandOptionType,
|
|
};
|
|
|
|
use crate::bot::arg_parse::option_to_string;
|
|
use crate::bot::commands::{BotCommand, CommandError};
|
|
use geoffrey_models::models::parameters::edit_params::EditParams;
|
|
use serenity::builder::CreateApplicationCommand;
|
|
|
|
//TODO: Combine edit commands into one class once I figure out why subcommand are not working
|
|
pub struct EditNameCommand;
|
|
|
|
#[async_trait]
|
|
impl BotCommand for EditNameCommand {
|
|
type ApiParams = EditParams;
|
|
type ApiResp = Location;
|
|
|
|
fn command_name() -> String {
|
|
"edit_name".to_string()
|
|
}
|
|
|
|
fn endpoint_name() -> String {
|
|
"edit".to_string()
|
|
}
|
|
|
|
fn request_type() -> Method {
|
|
Method::POST
|
|
}
|
|
|
|
fn create_app_command(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
|
command
|
|
.name(Self::command_name())
|
|
.description("Edit a location's name")
|
|
.create_option(|option| {
|
|
option
|
|
.name("loc_name")
|
|
.description("Location to edit")
|
|
.kind(ApplicationCommandOptionType::String)
|
|
.required(true)
|
|
})
|
|
.create_option(|option| {
|
|
option
|
|
.name("new_name")
|
|
.description("New location name")
|
|
.kind(ApplicationCommandOptionType::String)
|
|
.required(true)
|
|
})
|
|
}
|
|
|
|
async fn process_arguments(
|
|
command_interaction: ApplicationCommandInteraction,
|
|
) -> Result<Self::ApiParams, CommandError> {
|
|
let options = command_interaction.data.options;
|
|
let name = option_to_string(options.get(0), "loc_name")?;
|
|
let new_name = option_to_string(options.get(1), "new_name")?;
|
|
Ok(Self::ApiParams::new(name, None, Some(new_name)))
|
|
}
|
|
|
|
fn build_response(resp: Self::ApiResp, args: Self::ApiParams) -> String {
|
|
format!("**{}** has been renamed to {}", args.loc_name, resp.name,)
|
|
}
|
|
}
|