use async_trait::async_trait; use reqwest::Method; use serenity::builder::CreateApplicationCommand; use serenity::model::interactions::application_command::{ ApplicationCommandInteraction, ApplicationCommandOptionType, }; use geoffrey_models::models::locations::Location; use geoffrey_models::models::parameters::edit_params::EditParams; use geoffrey_models::models::{Dimension, Position}; use crate::bot::arg_parse::{ add_dimension_argument, add_x_position_argument, add_y_position_argument, add_z_position_argument, option_to_dim, option_to_i64, option_to_string, }; use crate::bot::commands::BotCommand; use crate::context::GeoffreyContext; use crate::error::BotError; //TODO: Combine edit commands into one class once I figure out why subcommand are not working pub struct EditPosCommand; #[async_trait] impl BotCommand for EditPosCommand { type ApiParams = EditParams; type ApiResp = Location; fn command_name() -> String { "edit_pos".to_string() } fn endpoint() -> 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 position") .create_option(|option| { option .name("loc_name") .description("Location to edit") .kind(ApplicationCommandOptionType::String) .required(true) }) .create_option(add_x_position_argument) .create_option(add_y_position_argument) .create_option(add_z_position_argument) .create_option(add_dimension_argument) } async fn process_arguments( command_interaction: ApplicationCommandInteraction, ) -> Result { let options = command_interaction.data.options; let name = option_to_string(options.get(0), "loc_name")?; let x = option_to_i64(options.get(1), "x")?; let y = option_to_i64(options.get(2), "y")?; let z = option_to_i64(options.get(3), "z")?; let dim = option_to_dim(options.get(4), "dimension").unwrap_or(Dimension::Overworld); let position = Position::new(x as i32, y as i32, z as i32, dim); Ok(Self::ApiParams::new(name, Some(position), None)) } fn build_response(_: &GeoffreyContext, resp: Self::ApiResp, _: Self::ApiParams) -> String { format!("**{}** has been moved to {}", resp.name, resp.position) } }