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 crate::bot::lang::PLAYER_DOES_NOT_HAVE_MATCHING_LOC; use geoffrey_models::models::parameters::delete_params::DeleteParams; use geoffrey_models::models::response::api_error::GeoffreyAPIError; use serenity::builder::CreateApplicationCommand; pub struct DeleteCommand; #[async_trait] impl BotCommand for DeleteCommand { type ApiParams = DeleteParams; type ApiResp = Location; fn command_name() -> String { "delete".to_string() } fn request_type() -> Method { Method::POST } fn custom_err_resp(err: &CommandError) -> Option { match err { CommandError::GeoffreyApi(GeoffreyAPIError::EntryNotFound) => { Some(PLAYER_DOES_NOT_HAVE_MATCHING_LOC.to_string()) } _ => None, } } fn create_app_command(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { command .name(Self::command_name()) .description("Delete a location from Geoffrey") .create_option(|option| { option .name("loc_name") .description("Name of the location") .kind(ApplicationCommandOptionType::String) .required(true) }) } async fn process_arguments( command_interaction: ApplicationCommandInteraction, ) -> Result { let options = command_interaction.data.options; let loc_name = option_to_string(options.get(0), "loc_name")?; Ok(Self::ApiParams::new(loc_name)) } fn build_response(resp: Self::ApiResp, _: Self::ApiParams) -> String { format!( "**{}** has been been removed from Geoffrey, good riddance!", resp.name ) } }